core.memory.memory
High-level facade combining an Embeddings backend with a TurnVectorStore.
Provides synchronous and asynchronous methods for indexing completed turns
(Q+A pairs), semantic search, and re-embedding with a new model. The
L4 integration layer wires this into FFAI via HistoryRecorder.
High-level facade combining an Embeddings backend with a TurnVectorStore.
Provides synchronous and asynchronous methods for indexing completed turns
(Q+A pairs), semantic search, and re-embedding with a new model. The
L4 integration layer wires this into FFAI via HistoryRecorder.
- class Memory(embeddings, store=None)[source]
Bases:
objectSemantic recall over completed conversation turns.
Wraps an
EmbeddingBackendand aTurnVectorStore. Provides two indexing entry points:index_turn()/aindex_turn()— extract text from a structuredturndict viaturn["content"][0]["text"].index_turn_text()/aindex_turn_text()— embed an arbitrary caller-supplied string while still storing the structuredturndict alongside. Used byHistoryRecorder(L4) to embed the Q+A pair (f"{prompt}\n{response}") rather than just the response.
- Parameters:
embeddings (EmbeddingBackend) – Embedding backend (LiteLLM API model or local
local/...model). Any object implementingEmbeddingBackendis accepted.store (TurnVectorStore | None) – Optional
TurnVectorStore. Defaults to a fresh instance. Public and settable so callers can swap in a store loaded from Parquet (L3).
- index_turn_text(text, turn, metadata=None)[source]
Embed an arbitrary
textand store the structuredturn.Use this when the embedded text differs from
turn["content"][0]["text"]— e.g., when embedding the Q+A pair (f"{prompt}\n{response}") while still storing the response as the canonical turn content.
- async aindex_turn(turn, metadata=None)[source]
Async variant of
index_turn().
- async aindex_turn_text(text, turn, metadata=None)[source]
Async variant of
index_turn_text().
- reindex(new_embeddings)[source]
Re-embed all stored texts with a new embedding model.
Reads all entries via
TurnVectorStore.iter_entries(), clears the store, and re-adds each entry with the new embedding. The turn dicts and metadata are preserved verbatim. After reindexing,self._embeddingsis updated so subsequentsearch()calls embed queries with the new model.- Parameters:
new_embeddings (EmbeddingBackend) – The new embedding backend to use.
- Return type:
None
Classes
- class Memory(embeddings, store=None)[source]
Bases:
objectSemantic recall over completed conversation turns.
Wraps an
EmbeddingBackendand aTurnVectorStore. Provides two indexing entry points:index_turn()/aindex_turn()— extract text from a structuredturndict viaturn["content"][0]["text"].index_turn_text()/aindex_turn_text()— embed an arbitrary caller-supplied string while still storing the structuredturndict alongside. Used byHistoryRecorder(L4) to embed the Q+A pair (f"{prompt}\n{response}") rather than just the response.
- Parameters:
embeddings (EmbeddingBackend) – Embedding backend (LiteLLM API model or local
local/...model). Any object implementingEmbeddingBackendis accepted.store (TurnVectorStore | None) – Optional
TurnVectorStore. Defaults to a fresh instance. Public and settable so callers can swap in a store loaded from Parquet (L3).
- index_turn_text(text, turn, metadata=None)[source]
Embed an arbitrary
textand store the structuredturn.Use this when the embedded text differs from
turn["content"][0]["text"]— e.g., when embedding the Q+A pair (f"{prompt}\n{response}") while still storing the response as the canonical turn content.
- async aindex_turn(turn, metadata=None)[source]
Async variant of
index_turn().
- async aindex_turn_text(text, turn, metadata=None)[source]
Async variant of
index_turn_text().
- reindex(new_embeddings)[source]
Re-embed all stored texts with a new embedding model.
Reads all entries via
TurnVectorStore.iter_entries(), clears the store, and re-adds each entry with the new embedding. The turn dicts and metadata are preserved verbatim. After reindexing,self._embeddingsis updated so subsequentsearch()calls embed queries with the new model.- Parameters:
new_embeddings (EmbeddingBackend) – The new embedding backend to use.
- Return type:
None