QdrantMemoryStore¶
Qdrant-backed episodic memory store.
QdrantMemoryStore
¶
Bases: BaseMemoryStore
Episodic memory store backed by a Qdrant collection.
Episodes are embedded at write time using FastEmbed and stored as vector points. Similarity search uses cosine distance over the embedded episode text.
By default, Qdrant runs in-process with no server required. Pass a
pre-configured QdrantClient to persist to a remote or on-disk
instance instead.
Note: This is a minimal integration. Advanced Qdrant features such
as payload filters, score thresholds, and named vectors are not
exposed. Use the _client attribute directly for full API access.
Attributes:
| Name | Type | Description |
|---|---|---|
_client |
QdrantClient
|
The Qdrant client instance. |
_collection |
str
|
Name of the Qdrant collection. |
Source code in src/llm_agents_from_scratch/memory/qdrant_store.py
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 | |
__init__
¶
Initialize a QdrantMemoryStore.
Creates a Qdrant collection configured for cosine similarity over FastEmbed vectors. Embedding runs locally via ONNX Runtime; no external embedding service is required. The model is downloaded on first use and cached locally.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
collection_name
|
str
|
Name of the Qdrant collection.
Defaults to |
'episodes'
|
embedding_model
|
str
|
FastEmbed model name used to embed
episode text at write time and queries at search time.
Defaults to |
'BAAI/bge-small-en-v1.5'
|
client
|
QdrantClient | None
|
Pre-configured Qdrant client.
Defaults to an in-memory client when |
None
|
Source code in src/llm_agents_from_scratch/memory/qdrant_store.py
write
async
¶
Embed and persist an episode to the Qdrant collection.
The full serialised episode and its completion timestamp are
stored in the point payload for later retrieval. The embedded
text defaults to a concat-format serialisation of
DEFAULT_EPISODE_INCLUDE attributes when embedded_text
is not provided.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
episode
|
Episode
|
The completed episode to store. |
required |
embedded_text
|
str | None
|
Pre-formatted text to embed.
When provided by the calling memory strategy, this text
is used directly for the vector. Defaults to |
None
|
Source code in src/llm_agents_from_scratch/memory/qdrant_store.py
read_recent
async
¶
Return the N most recently recorded episodes.
Fetches all points from the collection and sorts by the stored
completed_at timestamp.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
n
|
int
|
Maximum number of episodes to return. |
required |
Returns:
| Type | Description |
|---|---|
list[Episode]
|
list[Episode]: Episodes ordered from most recent to oldest. |
Source code in src/llm_agents_from_scratch/memory/qdrant_store.py
count
async
¶
Return the total number of episodes in the store.
Returns:
| Name | Type | Description |
|---|---|---|
int |
int
|
Episode count. |
summary
async
¶
Return a human-readable summary of the store contents.
Includes the collection name, total episode count, and the instruction and timestamp of the newest and oldest episodes.
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
Multi-line summary of the store. |
Source code in src/llm_agents_from_scratch/memory/qdrant_store.py
search
async
¶
Return the K episodes most semantically similar to a query.
Embeds the query using the same FastEmbed model used at write time and retrieves the top-K points by cosine similarity.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
query
|
str
|
The search query (e.g. the task instruction). |
required |
k
|
int
|
Maximum number of episodes to return. |
required |
**kwargs
|
Any
|
Additional keyword arguments forwarded to
|
{}
|
Returns:
| Type | Description |
|---|---|
list[Episode]
|
list[Episode]: Episodes ordered by cosine similarity to the query. |