aimu.memory¶
Semantic facts, path-based documents, and a shared abstract base.
aimu.memory.MemoryStore ¶
Bases: ABC
Abstract interface for memory store implementations.
All implementations must support storing, searching, deleting, and listing content. Concrete subclasses add implementation-specific methods on top of this baseline.
aimu.memory.SemanticMemoryStore ¶
Bases: MemoryStore
Persistent store for factual memories backed by ChromaDB.
Memories are natural-language strings in subject-predicate-object form, e.g. "Paul works at Google" or "Sarah is the sister of Emma". ChromaDB embeds each fact so that topic-based retrieval ("work", "family life") finds semantically relevant facts without exact-string matching.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
collection_name
|
str
|
ChromaDB collection name (default: "memories"). |
'memories'
|
persist_path
|
Optional[str]
|
Directory path for persistent storage. If None, uses an in-memory ephemeral client. |
None
|
Examples:
>>> store = SemanticMemoryStore()
>>> store.store("Paul works at Google")
>>> store.store("Paul is married to Sarah")
>>> store.store("Sarah is the sister of Emma")
>>> store.search("work") # ["Paul works at Google"]
>>> store.search("family life") # marriage / sibling facts
store ¶
Store a fact string in the memory store.
The fact should be a natural-language sentence in subject-predicate-object form, e.g. "Paul works at Google" or "Sarah is the sister of Emma".
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
content
|
str
|
The fact string to store. |
required |
search ¶
Retrieve facts semantically related to a query.
Uses ChromaDB's vector similarity search so broad topics like "work" or "family life" match relevant facts without exact-string matching.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
query
|
str
|
Natural-language query (e.g. "work", "family"). |
required |
n_results
|
int
|
Maximum number of facts to return. |
10
|
max_distance
|
float | None
|
Optional cosine-distance cutoff (0 = identical, 2 = maximally dissimilar). Facts with a distance above this threshold are excluded. Typical useful range: 0.3 (tight) – 0.6 (loose). Defaults to None (no cutoff). |
None
|
Returns:
| Type | Description |
|---|---|
list[str]
|
List of fact strings ordered by relevance. |
delete ¶
Remove all stored facts that exactly match the given string.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
identifier
|
str
|
The exact fact string to remove. |
required |
aimu.memory.DocumentStore ¶
Bases: MemoryStore
Path-addressed document store backed by the filesystem or an in-memory dict.
Implements the :class:MemoryStore abstract interface so it can be swapped
with :class:SemanticMemoryStore in any application, and adds the richer
path-based API that mirrors Anthropic's Managed Agents Memory tools.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
persist_path
|
Optional[str]
|
Root directory for persistent storage. If None the store is ephemeral (in-memory only). |
None
|
Examples:
>>> store = DocumentStore()
>>> store.write("/preferences.md", "Use concise responses.")
>>> store.read("/preferences.md")
'Use concise responses.'
>>> store.edit("/preferences.md", "concise", "detailed")
>>> store.search_full_text("detailed")
[{"path": "/preferences.md", "content": "Use detailed responses."}]
write ¶
Create or overwrite a document at path.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str
|
Memory path, e.g. |
required |
content
|
str
|
Text content to store (≤ 100 KB recommended). |
required |
read ¶
Return the content of the document at path.
Raises:
| Type | Description |
|---|---|
KeyError
|
If no document exists at path. |
edit ¶
Replace the first occurrence of old_str with new_str in the document at path.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str
|
Memory path of the document to edit. |
required |
old_str
|
str
|
Exact substring to find. |
required |
new_str
|
str
|
Replacement text. |
required |
Raises:
| Type | Description |
|---|---|
KeyError
|
If no document exists at path. |
ValueError
|
If old_str is not found in the document. |
list_paths ¶
Return all memory paths, optionally filtered by prefix.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
prefix
|
Optional[str]
|
Only return paths that start with this string. Pass None (default) to return all paths. |
None
|
Returns:
| Type | Description |
|---|---|
list[str]
|
Sorted list of path strings. |
search_full_text ¶
Case-insensitive substring search across all document contents.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
query
|
str
|
Search string. |
required |
n_results
|
int
|
Maximum number of results to return. |
10
|
Returns:
| Type | Description |
|---|---|
list[dict]
|
List of |
list[dict]
|
documents, ordered by path. |
store ¶
Store content at an auto-assigned path (/note-{uuid}.md).
Use :meth:write directly when you need control over the path.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
content
|
str
|
Text content to store. |
required |
search ¶
Full-text search; returns a list of matching content strings.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
query
|
str
|
Search string. |
required |
n_results
|
int
|
Maximum number of results. |
10
|
Returns:
| Type | Description |
|---|---|
list[str]
|
List of content strings from matching documents. |
delete ¶
Delete the document at identifier (treated as a memory path).
No-op if the path does not exist.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
identifier
|
str
|
Memory path of the document to remove. |
required |