Smritea

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.

Ask AI about this page

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.

FieldMeaningRules
actor_idThe person, agent or system the memory is about.Up to 64 characters. Send it with actor_type.
actor_typeThe kind of actor.user, agent or system. Send it with actor_id.
actor_nameA display name for the actor.Up to 255 characters. Only add uses it.
conversation_idThe conversation the memory came from.Up to 64 characters.
source_typeWhere the text came from.conversation, document or api. Defaults to api.
participant_idsThe 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 sendSearch returns
actor_id and actor_typeMemories about that actor.
conversation_idMemories from that conversation.
participant_ids with one IDMemories from every conversation that actor took part in.
participant_ids with two or more IDsMemories from conversations where those actors all took part.
NothingMemories 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_id and actor_type together. Sending one alone fails validation.
  • Do not send participant_ids with conversation_id. The server answers 400 with the code VALIDATION_FAILED.
  • add ignores participant_ids, and Smritea does not store it.
  • On add, a conversation_id needs an actor_type. Without it, the server answers 400 with VALIDATION_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.

Last updated on