SimilarityMemory¶
Similarity-based episodic memory.
SimilarityMemory
¶
Bases: BaseMemory
Similarity-based episodic memory.
Recalls the K most semantically similar past episodes using the store's vector search. At write time, episodes are passed to the store as-is; embedding is handled by the store.
Attributes:
| Name | Type | Description |
|---|---|---|
store |
BaseMemoryStore
|
The underlying vector memory store. |
k |
int
|
Number of most similar episodes to recall. |
search_kwargs |
dict[str, Any]
|
Extra keyword arguments forwarded
to |
Source code in src/llm_agents_from_scratch/memory/similarity.py
__init__
¶
Initialize a SimilarityMemory.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
store
|
BaseMemoryStore
|
A vector-backed memory store that
implements |
required |
k
|
int
|
Number of most similar episodes to include in recall. Defaults to 3. |
3
|
search_kwargs
|
dict[str, Any] | None
|
Optional keyword
arguments forwarded to |
None
|
Source code in src/llm_agents_from_scratch/memory/similarity.py
recall
async
¶
Retrieve the K most semantically similar past episodes.
Uses the task instruction as the search query.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
task
|
Task
|
The incoming task whose instruction is used as the similarity query. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
Newline-separated episode strings, or empty string if no similar episodes are found. |
Source code in src/llm_agents_from_scratch/memory/similarity.py
record
async
¶
Persist a completed episode to the store.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
episode
|
Episode
|
The completed episode to store. |
required |
summary
async
¶
Return a human-readable summary of the memory and its store.
Describes the retrieval strategy (top-K similarity), then delegates to the store for substrate-level facts (count, oldest, newest).
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
Multi-line summary of the memory and its store. |