Memory scope
A scope says who a memory is about and where it came from. Search uses the scope to find only the memories you want.
A scope is a set of fields that you attach to a memory when you add it and to a search when you query. The scope says who a memory is about and which conversation it came from. Search returns only memories that match every scope field you send.
The six fields
Every field is optional. An empty scope is valid on add, but every add call must include the scope object. The table lists the six fields, what each one means, and its rules.
| Field | Meaning | Rules |
|---|---|---|
actor_id | The person, agent or system the memory is about. | Up to 64 characters. Send it with actor_type. |
actor_type | The kind of actor. | user, agent or system. Send it with actor_id. |
actor_name | A display name for the actor. | Up to 255 characters. Only add uses it. |
conversation_id | The conversation the memory came from. | Up to 64 characters. |
source_type | Where the text came from. | conversation, document or api. Defaults to api. |
participant_ids | The actors who took part in a conversation. | Search only. Each ID is 1 to 64 characters. |
An actor is anyone who can own a memory. In an app for end users, each user is an actor with actor_type set to user.
How search uses scope
Search combines every non-empty scope field with AND. A memory must match every field.
| You send | Search returns |
|---|---|
actor_id and actor_type | Memories about that actor. |
conversation_id | Memories from that conversation. |
participant_ids with one ID | Memories from every conversation that actor took part in. |
participant_ids with two or more IDs | Memories from conversations where those actors all took part. |
| Nothing | Memories from the whole app. |
If no conversation matches participant_ids, search returns an empty list.
Build a scope
Pass the scope in the options of add. This example stores a memory for one user inside one conversation.
from smritea import MemoryScope
scope = MemoryScope(
actor_id="alice",
actor_type="user",
conversation_id="conv-1",
)
client.add("Alice prefers vegetarian food", scope=scope)To search across the conversations that two actors share, put both IDs in participant_ids on the scope. Do not add conversation_id to this scope.
from smritea import MemoryScope
scope = MemoryScope(participant_ids=["alice", "bob"])
results = client.search("What did they decide?", scope=scope)
print(len(results))Rules that cause errors
- Send
actor_idandactor_typetogether. Sending one alone fails validation. - Do not send
participant_idswithconversation_id. The server answers 400 with the codeVALIDATION_FAILED. addignoresparticipant_ids, and Smritea does not store it.- On
add, aconversation_idneeds anactor_type. Without it, the server answers 400 withVALIDATION_FAILED.
Who is asking
Search also takes speaker_actor_id. It names the actor who asks the question. It never filters results. Use it to say who is speaking when the query refers to the speaker, for example with a first-person pronoun.
Conversation IDs in results
Smritea returns conversation IDs in an internal form that starts with cnv_. Search accepts either the form you sent or the internal form.
Related pages
Last updated on



