fabricatio_memory.rust
Attributes
Classes
Represents a memory object with content, importance, tags, and access statistics. |
|
Service class for managing memory stores and indexes. |
|
Memory statistics structure containing aggregated metrics about stored memories. |
|
MemoryStore is a struct that provides an interface for storing, retrieving, and searching memories in a Tantivy search index. |
Package Contents
- class fabricatio_memory.rust.Memory
Represents a memory object with content, importance, tags, and access statistics.
- class fabricatio_memory.rust.MemoryService
Service class for managing memory stores and indexes.
- get_store(store_name: str) MemoryStore
Gets a MemoryStore instance for the given store name.
This method retrieves or creates an index for the given store name, then returns a MemoryStore instance that can be used to perform operations on that index.
- class fabricatio_memory.rust.MemoryStats
Memory statistics structure containing aggregated metrics about stored memories.
- class fabricatio_memory.rust.MemoryStore
MemoryStore is a struct that provides an interface for storing, retrieving, and searching memories in a Tantivy search index.
It supports operations such as adding, updating, deleting, and searching memories based on various criteria like content, tags, importance, recency, and access frequency.
The store handles memory access tracking by updating access counts and timestamps automatically during retrieval and search operations. It also supports batch updates and optional immediate disk writes for consistency.
The implementation uses a Tantivy index with fields for content, tags, importance, timestamps, and access counts. It includes PyO3 bindings to allow Python usage.
- add_memory(content: str, importance: int, tags: Sequence[str], write: bool = False) str
Adds a new memory to the system and returns its unique ID.
- Parameters:
- Returns:
The UUID of the newly added memory.
- Return type:
- Raises:
Exception – If there is an error adding the memory or writing to the index.
- write() None
Writes all pending changes to disk.
- Returns:
None
- Raises:
Exception – If there is an error committing the changes.
- get_memory(uuid: str, write: bool = False) Memory | None
Retrieves a memory by its ID and updates its access count.
- update_memory(uuid: str, content: str | None = None, importance: int | None = None, tags: Sequence[str] | None = None, write: bool = False) bool
Updates an existing memory’s content, importance, or tags.
- Parameters:
uuid (str) – The unique identifier of the memory to update.
content (str | None, optional) – The new content. Defaults to None.
importance (int | None, optional) – The new importance score. Defaults to None.
tags (list[str] | None, optional) – The new list of tags. Defaults to None.
write (bool, optional) – If True, commits the changes to disk immediately. Defaults to False.
- Returns:
True if the memory was found and updated, False otherwise.
- Return type:
- Raises:
Exception – If there is an error updating the memory or writing to the index.
- delete_memory(uuid: str, write: bool = False) bool
Deletes a memory by its ID.
- Parameters:
- Returns:
True if the deletion operation was processed (returns True even if memory didn’t exist).
- Return type:
- Raises:
Exception – If there is an error deleting the memory or writing to the index.
- search_memories(query_str: str, top_k: int = 20, boost_recent: bool = False, write: bool = False) list[Memory]
Searches memories by query string with optional recency boosting.
- Parameters:
query_str (str) – The search query string.
top_k (int, optional) – The maximum number of results to return. Defaults to 20.
boost_recent (bool, optional) – If True, boosts the score of more recent memories. Defaults to False.
write (bool, optional) – If True, commits access updates to disk immediately. Defaults to False.
- Returns:
A list of matching Memory objects, sorted by relevance.
- Return type:
- Raises:
Exception – If there is an error parsing the query or searching the index.
- search_by_tags(tags: Sequence[str], top_k: int = 20, write: bool = False) list[Memory]
Searches memories by specific tags.
- Parameters:
- Returns:
A list of matching Memory objects.
- Return type:
- Raises:
Exception – If there is an error searching the index.
- get_memories_by_importance(min_importance: int, top_k: int = 20, write: bool = False) list[Memory]
Gets memories filtered by a minimum importance level.
- Parameters:
- Returns:
A list of Memory objects with importance >= min_importance.
- Return type:
- Raises:
Exception – If there is an error searching the index.
- get_recent_memories(days: int, top_k: int = 20, write: bool = False) list[Memory]
Gets memories from the last N days.
- Parameters:
- Returns:
A list of Memory objects created within the last N days.
- Return type:
- Raises:
Exception – If there is an error searching the index.
- get_frequently_accessed(top_k: int = 20, write: bool = False) list[Memory]
Gets memories sorted by access frequency (most accessed first).
- Parameters:
- Returns:
A list of Memory objects sorted by access count in descending order.
- Return type:
- Raises:
Exception – If there is an error searching the index.
- count_memories() int
Counts the total number of memories in the system.
- Returns:
The total number of documents in the index.
- Return type:
- stats() MemoryStats
Gets aggregated statistics about all memories.
- Returns:
- An object containing total memories, average importance,
average access count, and average age in days.
- Return type:
- Raises:
Exception – If there is an error calculating aggregations.