Recall lessons in a later run
This guide is for developers who already store lessons and want a later run to use them. It searches by meaning, reads entries back by an exact field, and shows the check your app makes before it puts an entry in a prompt.
Search by meaning
POST /v2/core/search takes the new question as query and the run_id that holds your lessons. It returns the closest entries first. k sets how many to return, 10 by default.
import os
import requests
response = requests.post(
"https://api.mubit.ai/v2/core/search",
headers={"Authorization": f"Bearer {os.environ['MUBIT_API_KEY']}"},
json={
"query": "Why did my card get charged two times this month?",
"run_id": "support-triage-lessons",
"k": 5,
},
timeout=30,
)
for entry in response.json():
print(round(entry["score"], 2), entry["metadata"]["id"], entry["metadata"]["content"])Each entry has a score (higher is closer), the stored text in metadata.content and the entry's id in metadata.id. An empty list means nothing matched, or the entries are not stored yet: wait for the ingest job first.
Read entries back by a field
Search ranks by meaning, so it returns the closest entries whatever they say. When your app knows which entries it wants, use POST /v2/core/lookup. It returns the entries of a run in a fixed order, with no ranking. match is a list of objects of exact field values, and an entry is returned when it matches any of them. Fields that you stored in metadata_json are matched by name. limit sets the most entries to return: 256 by default, 4096 at most.
import os
import requests
response = requests.post(
"https://api.mubit.ai/v2/core/lookup",
headers={"Authorization": f"Bearer {os.environ['MUBIT_API_KEY']}"},
json={
"run_id": "support-triage-lessons",
"match": [{"contract": "v1"}],
"limit": 50,
},
timeout=30,
)
for entry in response.json():
print(entry["id"], entry["metadata"])Each entry has an id, the run_id, metadata, and created_at and updated_at as Unix times. Without match, the call returns every entry of the run, up to limit. A blank or missing run_id gets 400.
Keep only what applies
Neither route checks that an entry applies to the question or to the current setting. Your app does, before it uses an entry:
- Drop entries from another setting. Compare the scope recorded with the entry, such as the database or the contract version, with the current one. Scope lessons per database and version shows this.
- Drop entries that score low. Pick a score threshold from your own examples. A score is not a probability.
- Cap what you send. Put at most a few entries, and a token budget's worth of text, in the prompt.
- Remember which entries you used. When you report the outcome, the ids of the entries you used let you credit them.
Then send the model call as usual, for example as Connect with the OpenAI SDK shows.
Read lessons a person approved
POST /v2/loop/context returns lessons a person approved for a session, in a prompt-ready form. It answers with none until a person has approved a lesson. Read approved lessons shows the request.