Python Quickstart
MicroResolve ships a Python package (microresolve) with pre-built wheels. No build step, no native compiler needed.
Install
pip install microresolveRequires Python 3.8+. Pre-built wheels for Linux, macOS, and Windows (x86_64 and arm64).
Basic usage
from microresolve import MicroResolve
engine = MicroResolve()ns = engine.namespace("support")
ns.add_intent("cancel_order", [ "cancel my order", "I want to cancel", "stop my order",])ns.add_intent("track_order", [ "where is my package", "track my order", "shipping status",])
matches = ns.resolve("I need to cancel")for m in matches: print(f"{m['id']}: {m['score']:.2f}")# cancel_order: 0.91Persist to disk
from microresolve import MicroResolve
engine = MicroResolve(data_dir="~/.local/share/microresolve")ns = engine.namespace("support")# ... add intents and phrases ...engine.flush()On the next startup, namespaces are auto-loaded from data_dir.
Custom threshold per namespace
ns_security = engine.namespace_with("security", threshold=1.3)Override threshold per call
matches = ns.resolve("cancel my order and get a refund", threshold=0.3, gap=1.5)Add phrases at runtime
result = ns.add_phrase("cancel_order", "abort my order")print(result["added"]) # Trueprint(result["redundant"]) # False if new
# Specify language explicitlyns.add_phrase("cancel_order", "取消我的订单", lang="zh")Correct a wrong classification
# "stop shipment" classified as cancel_order, should be track_orderns.correct("stop shipment", wrong="cancel_order", correct="track_order")
# Teach from a miss (engine returned nothing)ns.correct("where did my parcel go", wrong=None, correct="track_order")List namespaces and intents
ns_ids = engine.namespaces()intent_ids = ns.intent_ids()print(ns.intent_count())LangChain / LLM fallback pattern
from microresolve import MicroResolve
engine = MicroResolve(data_dir="~/.local/share/microresolve")ns = engine.namespace("support")
def handle(query: str) -> str: matches = ns.resolve(query) if matches and matches[0]["score"] > 0.7: return handle_intent(matches[0]["id"], query) return llm_fallback(query)Next
- Python API Reference — complete method listing
- Connect to server — sync a local engine with the self-hosted server
- Threshold Tuning — choose the right threshold for your namespace