Stores¶
Memory Stores¶
InMemoryStore¶
Reference store for tests and small single-process agents. search_by_embedding
is a full-scan cosine over a lazily cached embedding matrix (rebuilt after
save/update/delete). Suitable up to roughly thousands of vectors; for larger
N or durability see Performance & Scaling.
emotional_memory.stores.in_memory.InMemoryStore()
¶
Simple in-memory MemoryStore. Not persistent across restarts.
search_by_embedding uses brute-force cosine similarity with a cached
embedding matrix rebuilt lazily after mutations — suitable for small
datasets and testing. For production at larger scale, use a vector
database (SQLiteStore, QdrantStore, ChromaStore).
Source code in src/emotional_memory/stores/in_memory.py
search_by_embedding(embedding: list[float], top_k: int) -> list[Memory]
¶
Return top_k memories by cosine similarity to the query embedding.
Memories without an embedding are skipped. Uses a cached embedding
matrix (rebuilt lazily after save/update/delete) so repeated searches
avoid re-stacking all vectors on every call. A non-positive top_k
returns an empty list.
Source code in src/emotional_memory/stores/in_memory.py
SQLiteStore¶
Note
Requires the sqlite extra: uv pip install "emotional-memory[sqlite]"
Databases written before v0.18
The sqlite-vec index is created with distance_metric=cosine so that ANN
candidate prefiltering matches the cosine similarity used by retrieval
scoring. Earlier versions used sqlite-vec's L2 default, which ranks
differently whenever embeddings are not L2-normalised. Opening such a
database emits a UserWarning; call store.rebuild_vector_index() once to
migrate it (the vector table is derived data — embeddings are also stored in
the memory rows, so nothing is lost).
emotional_memory.stores.sqlite.SQLiteStore(path: str | Path = ':memory:')
¶
Persistent MemoryStore backed by SQLite with sqlite-vec vector search.
Parameters¶
path:
File path for the SQLite database, or ":memory:" for an ephemeral
in-memory database (useful in tests without writing to disk).
Source code in src/emotional_memory/stores/sqlite.py
close() -> None
¶
rebuild_vector_index() -> int
¶
Recreate the vector index from the stored memories, using cosine ranking.
The vec table holds only derived data (every embedding is also inside the
memories JSON blob), so it can be dropped and rebuilt safely. Use this
to migrate a database created before the index switched from L2 to cosine
ordering.
Returns:
| Type | Description |
|---|---|
int
|
Number of embeddings re-indexed. |
Source code in src/emotional_memory/stores/sqlite.py
search_by_embedding(embedding: list[float], top_k: int) -> list[Memory]
¶
Return top_k memories by approximate cosine similarity (sqlite-vec).
Falls back to brute-force cosine scan when the vector table is not yet initialised (e.g. no memories with embeddings have been saved yet).
Zero-length vectors have no defined cosine distance and come back with a
NULL distance, which SQLite sorts first; they are moved to the end so a
degenerate embedding cannot outrank genuine matches — mirroring
_math.cosine_similarity, which scores a zero vector 0.0.
Source code in src/emotional_memory/stores/sqlite.py
QdrantStore¶
Note
Requires the qdrant extra: uv pip install "emotional-memory[qdrant]"
emotional_memory.stores.qdrant.QdrantStore(*, url: str | None = None, path: str | None = None, collection_name: str = 'emotional_memory', api_key: str | None = None)
¶
MemoryStore backed by a Qdrant vector database.
Parameters¶
url:
Qdrant server URL, e.g. "http://localhost:6333". Mutually
exclusive with path. None (default) selects the ephemeral
in-memory Qdrant instance, useful for tests and prototyping.
path:
Local filesystem path for a persistent on-disk Qdrant instance.
Mutually exclusive with url.
collection_name:
Name of the Qdrant collection. Created lazily on first save().
api_key:
Optional API key for Qdrant Cloud (ignored in local modes).
Source code in src/emotional_memory/stores/qdrant.py
ChromaStore¶
Note
Requires the HTTP-only chroma extra and a separately operated server:
uv pip install "emotional-memory[chroma]". Pass host=; embedded and
file-backed modes are intentionally unavailable.
emotional_memory.stores.chroma.ChromaStore(*, path: str | None = None, host: str | None = None, port: int = 8000, collection_name: str = 'emotional_memory')
¶
MemoryStore backed by a Chroma vector database.
Parameters¶
path:
Unsupported. Retained to provide a migration error for callers that used
the former embedded persistent mode.
host:
Remote Chroma server hostname, e.g. "localhost". Required.
port:
Remote Chroma server port (default 8000). Only used when host
is provided.
collection_name:
Name of the Chroma collection. Created lazily on first save().
Source code in src/emotional_memory/stores/chroma.py
Runtime mood/affect persistence is a separate protocol (AffectiveStateStore),
not a MemoryStore. See State Stores.