core.memory.turn_store
In-memory vector store for memory recall over PermanentHistory turns.
Stores (text, embedding, turn, metadata) tuples in parallel lists and
provides cosine-similarity search. Designed for Tier 1 scale (<100K turns);
Chroma/Qdrant backends are a future concern for larger workloads.
In-memory vector store for memory recall over PermanentHistory turns.
Stores (text, embedding, turn, metadata) tuples in parallel lists and
provides cosine-similarity search. Designed for Tier 1 scale (<100K turns);
Chroma/Qdrant backends are a future concern for larger workloads.
- cosine_similarity(a, b)[source]
Cosine similarity between two equal-length float vectors.
Thin wrapper around
Embeddings.cosine_similarity()so thatturn_storeconsumers don’t need to import theEmbeddingsclass just to compute similarity. Returns0.0when either vector has zero magnitude.
- class TurnVectorStore[source]
Bases:
objectAppend-only in-memory store of embedded turns with cosine search.
Entries are stored in four parallel lists keyed by an integer index.
add()returns the index of the appended entry; that index is preserved on the correspondingTurnHitreturned bysearch().Search is O(N) over all stored entries. Adequate for Tier 1 scale; a vector-index backend (Chroma/Qdrant) is a future concern.
- add(text, embedding, turn, metadata=None)[source]
Append an entry and return its integer index.
- Parameters:
- Returns:
The integer index of the newly appended entry.
- Return type:
- search(query_embedding, top_k=5, threshold=None)[source]
Return up to
top_kturns ranked by cosine similarity.- Parameters:
- Returns:
Hits sorted by
scoredescending. Empty list if the store is empty or all hits fall belowthreshold.- Return type:
Classes
- class TurnVectorStore[source]
Bases:
objectAppend-only in-memory store of embedded turns with cosine search.
Entries are stored in four parallel lists keyed by an integer index.
add()returns the index of the appended entry; that index is preserved on the correspondingTurnHitreturned bysearch().Search is O(N) over all stored entries. Adequate for Tier 1 scale; a vector-index backend (Chroma/Qdrant) is a future concern.
- add(text, embedding, turn, metadata=None)[source]
Append an entry and return its integer index.
- Parameters:
- Returns:
The integer index of the newly appended entry.
- Return type:
- search(query_embedding, top_k=5, threshold=None)[source]
Return up to
top_kturns ranked by cosine similarity.- Parameters:
- Returns:
Hits sorted by
scoredescending. Empty list if the store is empty or all hits fall belowthreshold.- Return type: