@mastra/memory 1.6.2-alpha.0 → 1.6.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +26 -0
- package/dist/docs/SKILL.md +24 -24
- package/dist/docs/assets/SOURCE_MAP.json +1 -1
- package/dist/docs/references/docs-agents-agent-approval.md +3 -3
- package/dist/docs/references/docs-agents-agent-memory.md +1 -1
- package/dist/docs/references/docs-agents-network-approval.md +1 -1
- package/dist/docs/references/docs-agents-networks.md +1 -1
- package/dist/docs/references/docs-agents-supervisor-agents.md +3 -3
- package/dist/docs/references/docs-memory-memory-processors.md +8 -8
- package/dist/docs/references/docs-memory-message-history.md +2 -2
- package/dist/docs/references/docs-memory-observational-memory.md +5 -5
- package/dist/docs/references/docs-memory-semantic-recall.md +7 -7
- package/dist/docs/references/docs-memory-working-memory.md +14 -14
- package/dist/docs/references/reference-core-getMemory.md +1 -1
- package/dist/docs/references/reference-core-listMemory.md +1 -1
- package/dist/docs/references/reference-memory-clone-utilities.md +7 -7
- package/dist/docs/references/reference-memory-cloneThread.md +4 -4
- package/dist/docs/references/reference-memory-createThread.md +1 -1
- package/dist/docs/references/reference-memory-getThreadById.md +1 -1
- package/dist/docs/references/reference-memory-listThreads.md +3 -3
- package/dist/docs/references/reference-memory-memory-class.md +1 -1
- package/dist/docs/references/reference-memory-observational-memory.md +1 -1
- package/dist/docs/references/reference-storage-dynamodb.md +5 -5
- package/dist/docs/references/reference-storage-libsql.md +1 -1
- package/dist/docs/references/reference-storage-mongodb.md +5 -5
- package/dist/docs/references/reference-storage-postgresql.md +5 -5
- package/dist/docs/references/reference-storage-upstash.md +3 -3
- package/dist/docs/references/reference-vectors-libsql.md +15 -15
- package/dist/docs/references/reference-vectors-mongodb.md +18 -18
- package/dist/docs/references/reference-vectors-pg.md +21 -21
- package/dist/docs/references/reference-vectors-upstash.md +15 -15
- package/package.json +8 -8
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
The `listThreads()` method retrieves threads with pagination support and optional filtering by `resourceId`, `metadata`, or both.
|
|
4
4
|
|
|
5
|
-
## Usage
|
|
5
|
+
## Usage examples
|
|
6
6
|
|
|
7
7
|
### List all threads with pagination
|
|
8
8
|
|
|
@@ -26,7 +26,7 @@ const result = await memory.listThreads({
|
|
|
26
26
|
})
|
|
27
27
|
```
|
|
28
28
|
|
|
29
|
-
### Filter by resourceId
|
|
29
|
+
### Filter by `resourceId`
|
|
30
30
|
|
|
31
31
|
```typescript
|
|
32
32
|
const result = await memory.listThreads({
|
|
@@ -119,7 +119,7 @@ while (hasMorePages) {
|
|
|
119
119
|
}
|
|
120
120
|
```
|
|
121
121
|
|
|
122
|
-
## Metadata
|
|
122
|
+
## Metadata filtering
|
|
123
123
|
|
|
124
124
|
The metadata filter uses AND logic - all specified key-value pairs must match for a thread to be included in the results:
|
|
125
125
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
# Memory
|
|
1
|
+
# Memory class
|
|
2
2
|
|
|
3
3
|
The `Memory` class provides a robust system for managing conversation history and thread-based message storage in Mastra. It enables persistent storage of conversations, semantic search capabilities, and efficient message retrieval. You must configure a storage provider for conversation history, and if you enable semantic recall you will also need to provide a vector store and embedder.
|
|
4
4
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
# DynamoDB
|
|
1
|
+
# DynamoDB storage
|
|
2
2
|
|
|
3
3
|
The DynamoDB storage implementation provides a scalable and performant NoSQL database solution for Mastra, leveraging a single-table design pattern with [ElectroDB](https://electrodb.dev/).
|
|
4
4
|
|
|
@@ -120,7 +120,7 @@ For local development, you can use [DynamoDB Local](https://docs.aws.amazon.com/
|
|
|
120
120
|
|
|
121
121
|
**config.ttl** (`object`): TTL (Time To Live) configuration for automatic data expiration. Configure per entity type: thread, message, trace, eval, workflow\_snapshot, resource, score. Each entity config includes: enabled (boolean), attributeName (string, default: 'ttl'), defaultTtlSeconds (number).
|
|
122
122
|
|
|
123
|
-
## TTL (
|
|
123
|
+
## TTL (time to live) configuration
|
|
124
124
|
|
|
125
125
|
DynamoDB TTL allows you to automatically delete items after a specified time period. This is useful for:
|
|
126
126
|
|
|
@@ -216,7 +216,7 @@ aws dynamodb update-time-to-live \
|
|
|
216
216
|
|
|
217
217
|
> **Note:** DynamoDB deletes expired items within 48 hours after expiration. Items remain queryable until actually deleted.
|
|
218
218
|
|
|
219
|
-
## AWS IAM
|
|
219
|
+
## AWS IAM permissions
|
|
220
220
|
|
|
221
221
|
The IAM role or user executing the code needs appropriate permissions to interact with the specified DynamoDB table and its indexes. Below is a sample policy. Replace `${YOUR_TABLE_NAME}` with your actual table name and `${YOUR_AWS_REGION}` and `${YOUR_AWS_ACCOUNT_ID}` with appropriate values.
|
|
222
222
|
|
|
@@ -246,7 +246,7 @@ The IAM role or user executing the code needs appropriate permissions to interac
|
|
|
246
246
|
}
|
|
247
247
|
```
|
|
248
248
|
|
|
249
|
-
## Key
|
|
249
|
+
## Key considerations
|
|
250
250
|
|
|
251
251
|
Before diving into the architectural details, keep these key points in mind when working with the DynamoDB storage adapter:
|
|
252
252
|
|
|
@@ -255,7 +255,7 @@ Before diving into the architectural details, keep these key points in mind when
|
|
|
255
255
|
- **Understanding GSIs:** Familiarity with how the GSIs are structured (as per `TABLE_SETUP.md`) is important for understanding data retrieval and potential query patterns.
|
|
256
256
|
- **ElectroDB:** The adapter uses ElectroDB to manage interactions with DynamoDB, providing a layer of abstraction and type safety over raw DynamoDB operations.
|
|
257
257
|
|
|
258
|
-
## Architectural
|
|
258
|
+
## Architectural approach
|
|
259
259
|
|
|
260
260
|
This storage adapter utilizes a **single-table design pattern** leveraging [ElectroDB](https://electrodb.dev/), a common and recommended approach for DynamoDB. This differs architecturally from relational database adapters (like `@mastra/pg` or `@mastra/libsql`) that typically use multiple tables, each dedicated to a specific entity (threads, messages, etc.).
|
|
261
261
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
# MongoDB
|
|
1
|
+
# MongoDB storage
|
|
2
2
|
|
|
3
3
|
The MongoDB storage implementation provides a scalable storage solution using MongoDB databases with support for both document storage and vector operations.
|
|
4
4
|
|
|
@@ -56,7 +56,7 @@ const storage = new MongoDBStore({
|
|
|
56
56
|
|
|
57
57
|
> **Deprecation Notice:** The `url` parameter is deprecated but still supported for backward compatibility. Please use `uri` instead in all new code.
|
|
58
58
|
|
|
59
|
-
## Constructor
|
|
59
|
+
## Constructor examples
|
|
60
60
|
|
|
61
61
|
You can instantiate `MongoDBStore` in the following ways:
|
|
62
62
|
|
|
@@ -84,7 +84,7 @@ const store2 = new MongoDBStore({
|
|
|
84
84
|
})
|
|
85
85
|
```
|
|
86
86
|
|
|
87
|
-
## Additional
|
|
87
|
+
## Additional notes
|
|
88
88
|
|
|
89
89
|
### Collection Management
|
|
90
90
|
|
|
@@ -138,7 +138,7 @@ const thread = await memoryStore?.getThreadById({ threadId: '...' })
|
|
|
138
138
|
|
|
139
139
|
> **Warning:** If `init()` isn't called, collections won't be created and storage operations will fail silently or throw errors.
|
|
140
140
|
|
|
141
|
-
## Vector
|
|
141
|
+
## Vector search capabilities
|
|
142
142
|
|
|
143
143
|
MongoDB storage includes built-in vector search capabilities for AI applications:
|
|
144
144
|
|
|
@@ -190,7 +190,7 @@ const results = await vectorStore.query({
|
|
|
190
190
|
});
|
|
191
191
|
```
|
|
192
192
|
|
|
193
|
-
## Usage
|
|
193
|
+
## Usage example
|
|
194
194
|
|
|
195
195
|
### Adding memory to an agent
|
|
196
196
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
# PostgreSQL
|
|
1
|
+
# PostgreSQL storage
|
|
2
2
|
|
|
3
3
|
The PostgreSQL storage implementation provides a production-ready storage solution using PostgreSQL databases.
|
|
4
4
|
|
|
@@ -71,7 +71,7 @@ const storage = new PostgresStore({
|
|
|
71
71
|
|
|
72
72
|
**indexes** (`CreateIndexOptions[]`): Custom indexes to create during initialization.
|
|
73
73
|
|
|
74
|
-
## Constructor
|
|
74
|
+
## Constructor examples
|
|
75
75
|
|
|
76
76
|
You can instantiate `PostgresStore` in the following ways:
|
|
77
77
|
|
|
@@ -119,7 +119,7 @@ const store4 = new PostgresStore({
|
|
|
119
119
|
})
|
|
120
120
|
```
|
|
121
121
|
|
|
122
|
-
## Additional
|
|
122
|
+
## Additional notes
|
|
123
123
|
|
|
124
124
|
### Schema Management
|
|
125
125
|
|
|
@@ -316,7 +316,7 @@ This pattern ensures only one `PostgresStore` instance is created regardless of
|
|
|
316
316
|
|
|
317
317
|
> **Tip:** This singleton pattern is only necessary during local development with HMR. In production builds, modules are only loaded once.
|
|
318
318
|
|
|
319
|
-
## Usage
|
|
319
|
+
## Usage example
|
|
320
320
|
|
|
321
321
|
### Adding memory to an agent
|
|
322
322
|
|
|
@@ -387,7 +387,7 @@ for await (const chunk of stream.textStream) {
|
|
|
387
387
|
}
|
|
388
388
|
```
|
|
389
389
|
|
|
390
|
-
## Index
|
|
390
|
+
## Index management
|
|
391
391
|
|
|
392
392
|
PostgreSQL storage provides index management to optimize query performance.
|
|
393
393
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
# Upstash
|
|
1
|
+
# Upstash storage
|
|
2
2
|
|
|
3
3
|
The Upstash storage implementation provides a serverless-friendly storage solution using Upstash's Redis-compatible key-value store.
|
|
4
4
|
|
|
@@ -52,7 +52,7 @@ const storage = new UpstashStore({
|
|
|
52
52
|
|
|
53
53
|
**prefix** (`string`): Key prefix for all stored items (Default: `mastra:`)
|
|
54
54
|
|
|
55
|
-
## Additional
|
|
55
|
+
## Additional notes
|
|
56
56
|
|
|
57
57
|
### Key Structure
|
|
58
58
|
|
|
@@ -87,7 +87,7 @@ For optimal performance:
|
|
|
87
87
|
- Monitor Redis memory usage
|
|
88
88
|
- Consider data expiration policies if needed
|
|
89
89
|
|
|
90
|
-
## Usage
|
|
90
|
+
## Usage example
|
|
91
91
|
|
|
92
92
|
### Adding memory to an agent
|
|
93
93
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
# libSQL
|
|
1
|
+
# libSQL vector store
|
|
2
2
|
|
|
3
3
|
The libSQL storage implementation provides a SQLite-compatible vector search [libSQL](https://github.com/tursodatabase/libsql), a fork of SQLite with vector extensions, and [Turso](https://turso.tech/) with vector extensions, offering a lightweight and efficient vector database solution. It's part of the `@mastra/libsql` package and offers efficient vector similarity search with metadata filtering.
|
|
4
4
|
|
|
@@ -69,7 +69,7 @@ const results = await store.query({
|
|
|
69
69
|
});
|
|
70
70
|
```
|
|
71
71
|
|
|
72
|
-
## Constructor
|
|
72
|
+
## Constructor options
|
|
73
73
|
|
|
74
74
|
**url** (`string`): libSQL database URL. Use ':memory:' for in-memory database, 'file:dbname.db' for local file, or a libSQL-compatible connection string like 'libsql://your-database.turso.io'.
|
|
75
75
|
|
|
@@ -81,7 +81,7 @@ const results = await store.query({
|
|
|
81
81
|
|
|
82
82
|
## Methods
|
|
83
83
|
|
|
84
|
-
### createIndex()
|
|
84
|
+
### `createIndex()`
|
|
85
85
|
|
|
86
86
|
Creates a new vector collection. The index name must start with a letter or underscore and can only contain letters, numbers, and underscores. The dimension must be a positive integer.
|
|
87
87
|
|
|
@@ -91,7 +91,7 @@ Creates a new vector collection. The index name must start with a letter or unde
|
|
|
91
91
|
|
|
92
92
|
**metric** (`'cosine' | 'euclidean' | 'dotproduct'`): Distance metric for similarity search. Note: Currently only cosine similarity is supported by libSQL. (Default: `cosine`)
|
|
93
93
|
|
|
94
|
-
### upsert()
|
|
94
|
+
### `upsert()`
|
|
95
95
|
|
|
96
96
|
Adds or updates vectors and their metadata in the index. Uses a transaction to ensure all vectors are inserted atomically - if any insert fails, the entire operation is rolled back.
|
|
97
97
|
|
|
@@ -103,7 +103,7 @@ Adds or updates vectors and their metadata in the index. Uses a transaction to e
|
|
|
103
103
|
|
|
104
104
|
**ids** (`string[]`): Optional vector IDs (auto-generated if not provided)
|
|
105
105
|
|
|
106
|
-
### query()
|
|
106
|
+
### `query()`
|
|
107
107
|
|
|
108
108
|
Searches for similar vectors with optional metadata filtering.
|
|
109
109
|
|
|
@@ -119,7 +119,7 @@ Searches for similar vectors with optional metadata filtering.
|
|
|
119
119
|
|
|
120
120
|
**minScore** (`number`): Minimum similarity score threshold (Default: `0`)
|
|
121
121
|
|
|
122
|
-
### describeIndex()
|
|
122
|
+
### `describeIndex()`
|
|
123
123
|
|
|
124
124
|
Gets information about an index.
|
|
125
125
|
|
|
@@ -135,25 +135,25 @@ interface IndexStats {
|
|
|
135
135
|
}
|
|
136
136
|
```
|
|
137
137
|
|
|
138
|
-
### deleteIndex()
|
|
138
|
+
### `deleteIndex()`
|
|
139
139
|
|
|
140
140
|
Deletes an index and all its data.
|
|
141
141
|
|
|
142
142
|
**indexName** (`string`): Name of the index to delete
|
|
143
143
|
|
|
144
|
-
### listIndexes()
|
|
144
|
+
### `listIndexes()`
|
|
145
145
|
|
|
146
146
|
Lists all vector indexes in the database.
|
|
147
147
|
|
|
148
148
|
Returns: `Promise<string[]>`
|
|
149
149
|
|
|
150
|
-
### truncateIndex()
|
|
150
|
+
### `truncateIndex()`
|
|
151
151
|
|
|
152
152
|
Removes all vectors from an index while keeping the index structure.
|
|
153
153
|
|
|
154
154
|
**indexName** (`string`): Name of the index to truncate
|
|
155
155
|
|
|
156
|
-
### updateVector()
|
|
156
|
+
### `updateVector()`
|
|
157
157
|
|
|
158
158
|
Update a single vector by ID or by metadata filter. Either `id` or `filter` must be provided, but not both.
|
|
159
159
|
|
|
@@ -169,7 +169,7 @@ Update a single vector by ID or by metadata filter. Either `id` or `filter` must
|
|
|
169
169
|
|
|
170
170
|
**update.metadata** (`Record<string, any>`): New metadata to update
|
|
171
171
|
|
|
172
|
-
### deleteVector()
|
|
172
|
+
### `deleteVector()`
|
|
173
173
|
|
|
174
174
|
Deletes a specific vector entry from an index by its ID.
|
|
175
175
|
|
|
@@ -177,7 +177,7 @@ Deletes a specific vector entry from an index by its ID.
|
|
|
177
177
|
|
|
178
178
|
**id** (`string`): ID of the vector entry to delete
|
|
179
179
|
|
|
180
|
-
### deleteVectors()
|
|
180
|
+
### `deleteVectors()`
|
|
181
181
|
|
|
182
182
|
Delete multiple vectors by IDs or by metadata filter. Either `ids` or `filter` must be provided, but not both.
|
|
183
183
|
|
|
@@ -187,7 +187,7 @@ Delete multiple vectors by IDs or by metadata filter. Either `ids` or `filter` m
|
|
|
187
187
|
|
|
188
188
|
**filter** (`Record<string, any>`): Metadata filter to identify vectors to delete (mutually exclusive with ids)
|
|
189
189
|
|
|
190
|
-
## Response
|
|
190
|
+
## Response types
|
|
191
191
|
|
|
192
192
|
Query results are returned in this format:
|
|
193
193
|
|
|
@@ -200,7 +200,7 @@ interface QueryResult {
|
|
|
200
200
|
}
|
|
201
201
|
```
|
|
202
202
|
|
|
203
|
-
## Error
|
|
203
|
+
## Error handling
|
|
204
204
|
|
|
205
205
|
The store throws specific errors for different failure cases:
|
|
206
206
|
|
|
@@ -232,7 +232,7 @@ Common error cases include:
|
|
|
232
232
|
- Database connection issues
|
|
233
233
|
- Transaction failures during upsert
|
|
234
234
|
|
|
235
|
-
## Usage
|
|
235
|
+
## Usage example
|
|
236
236
|
|
|
237
237
|
### Local embeddings with fastembed
|
|
238
238
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
# MongoDB
|
|
1
|
+
# MongoDB vector store
|
|
2
2
|
|
|
3
3
|
The `MongoDBVector` class provides vector search using [MongoDB Atlas Vector Search](https://www.mongodb.com/docs/atlas/atlas-vector-search/). It enables efficient similarity search and metadata filtering within your MongoDB collections.
|
|
4
4
|
|
|
@@ -28,7 +28,7 @@ yarn add @mastra/mongodb@latest
|
|
|
28
28
|
bun add @mastra/mongodb@latest
|
|
29
29
|
```
|
|
30
30
|
|
|
31
|
-
## Usage
|
|
31
|
+
## Usage example
|
|
32
32
|
|
|
33
33
|
```typescript
|
|
34
34
|
import { MongoDBVector } from '@mastra/mongodb'
|
|
@@ -55,7 +55,7 @@ const store = new MongoDBVector({
|
|
|
55
55
|
})
|
|
56
56
|
```
|
|
57
57
|
|
|
58
|
-
## Constructor
|
|
58
|
+
## Constructor options
|
|
59
59
|
|
|
60
60
|
**id** (`string`): Unique identifier for this vector store instance
|
|
61
61
|
|
|
@@ -69,7 +69,7 @@ const store = new MongoDBVector({
|
|
|
69
69
|
|
|
70
70
|
## Methods
|
|
71
71
|
|
|
72
|
-
### createIndex()
|
|
72
|
+
### `createIndex()`
|
|
73
73
|
|
|
74
74
|
Creates a new vector index (collection) in MongoDB.
|
|
75
75
|
|
|
@@ -79,7 +79,7 @@ Creates a new vector index (collection) in MongoDB.
|
|
|
79
79
|
|
|
80
80
|
**metric** (`'cosine' | 'euclidean' | 'dotproduct'`): Distance metric for similarity search (Default: `cosine`)
|
|
81
81
|
|
|
82
|
-
### upsert()
|
|
82
|
+
### `upsert()`
|
|
83
83
|
|
|
84
84
|
Adds or updates vectors and their metadata in the collection.
|
|
85
85
|
|
|
@@ -91,7 +91,7 @@ Adds or updates vectors and their metadata in the collection.
|
|
|
91
91
|
|
|
92
92
|
**ids** (`string[]`): Optional vector IDs (auto-generated if not provided)
|
|
93
93
|
|
|
94
|
-
### query()
|
|
94
|
+
### `query()`
|
|
95
95
|
|
|
96
96
|
Searches for similar vectors with optional metadata filtering.
|
|
97
97
|
|
|
@@ -109,7 +109,7 @@ Searches for similar vectors with optional metadata filtering.
|
|
|
109
109
|
|
|
110
110
|
**minScore** (`number`): Minimum similarity score threshold (Default: `0`)
|
|
111
111
|
|
|
112
|
-
### describeIndex()
|
|
112
|
+
### `describeIndex()`
|
|
113
113
|
|
|
114
114
|
Returns information about the index (collection).
|
|
115
115
|
|
|
@@ -125,19 +125,19 @@ interface IndexStats {
|
|
|
125
125
|
}
|
|
126
126
|
```
|
|
127
127
|
|
|
128
|
-
### deleteIndex()
|
|
128
|
+
### `deleteIndex()`
|
|
129
129
|
|
|
130
130
|
Deletes a collection and all its data.
|
|
131
131
|
|
|
132
132
|
**indexName** (`string`): Name of the collection to delete
|
|
133
133
|
|
|
134
|
-
### listIndexes()
|
|
134
|
+
### `listIndexes()`
|
|
135
135
|
|
|
136
136
|
Lists all vector collections in the MongoDB database.
|
|
137
137
|
|
|
138
138
|
Returns: `Promise<string[]>`
|
|
139
139
|
|
|
140
|
-
### updateVector()
|
|
140
|
+
### `updateVector()`
|
|
141
141
|
|
|
142
142
|
Update a single vector by ID or by metadata filter. Either `id` or `filter` must be provided, but not both.
|
|
143
143
|
|
|
@@ -153,7 +153,7 @@ Update a single vector by ID or by metadata filter. Either `id` or `filter` must
|
|
|
153
153
|
|
|
154
154
|
**update.metadata** (`Record<string, any>`): New metadata to update
|
|
155
155
|
|
|
156
|
-
### deleteVector()
|
|
156
|
+
### `deleteVector()`
|
|
157
157
|
|
|
158
158
|
Deletes a specific vector entry from an index by its ID.
|
|
159
159
|
|
|
@@ -161,7 +161,7 @@ Deletes a specific vector entry from an index by its ID.
|
|
|
161
161
|
|
|
162
162
|
**id** (`string`): ID of the vector entry to delete
|
|
163
163
|
|
|
164
|
-
### deleteVectors()
|
|
164
|
+
### `deleteVectors()`
|
|
165
165
|
|
|
166
166
|
Delete multiple vectors by IDs or by metadata filter. Either `ids` or `filter` must be provided, but not both.
|
|
167
167
|
|
|
@@ -171,11 +171,11 @@ Delete multiple vectors by IDs or by metadata filter. Either `ids` or `filter` m
|
|
|
171
171
|
|
|
172
172
|
**filter** (`Record<string, any>`): Metadata filter to identify vectors to delete (mutually exclusive with ids)
|
|
173
173
|
|
|
174
|
-
### disconnect()
|
|
174
|
+
### `disconnect()`
|
|
175
175
|
|
|
176
176
|
Closes the MongoDB client connection. Should be called when done using the store.
|
|
177
177
|
|
|
178
|
-
## Response
|
|
178
|
+
## Response types
|
|
179
179
|
|
|
180
180
|
Query results are returned in this format:
|
|
181
181
|
|
|
@@ -188,7 +188,7 @@ interface QueryResult {
|
|
|
188
188
|
}
|
|
189
189
|
```
|
|
190
190
|
|
|
191
|
-
## Error
|
|
191
|
+
## Error handling
|
|
192
192
|
|
|
193
193
|
The store throws typed errors that can be caught:
|
|
194
194
|
|
|
@@ -212,15 +212,15 @@ try {
|
|
|
212
212
|
}
|
|
213
213
|
```
|
|
214
214
|
|
|
215
|
-
## Best
|
|
215
|
+
## Best practices
|
|
216
216
|
|
|
217
217
|
- Index metadata fields used in filters for optimal query performance.
|
|
218
218
|
- Use consistent field naming in metadata to avoid unexpected query results.
|
|
219
219
|
- Regularly monitor index and collection statistics to ensure efficient search.
|
|
220
220
|
|
|
221
|
-
## Usage
|
|
221
|
+
## Usage example
|
|
222
222
|
|
|
223
|
-
### Vector embeddings with MongoDB
|
|
223
|
+
### Vector embeddings with `MongoDB`
|
|
224
224
|
|
|
225
225
|
Embeddings are numeric vectors used by memory's `semanticRecall` to retrieve related messages by meaning (not keywords).
|
|
226
226
|
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
# PG
|
|
1
|
+
# PG vector store
|
|
2
2
|
|
|
3
3
|
The PgVector class provides vector search using [PostgreSQL](https://www.postgresql.org/) with [pgvector](https://github.com/pgvector/pgvector) extension. It provides robust vector similarity search capabilities within your existing PostgreSQL database.
|
|
4
4
|
|
|
5
|
-
## Constructor
|
|
5
|
+
## Constructor options
|
|
6
6
|
|
|
7
7
|
**connectionString** (`string`): PostgreSQL connection URL
|
|
8
8
|
|
|
@@ -26,7 +26,7 @@ The PgVector class provides vector search using [PostgreSQL](https://www.postgre
|
|
|
26
26
|
|
|
27
27
|
**pgPoolOptions** (`PoolConfig`): Additional pg pool configuration options
|
|
28
28
|
|
|
29
|
-
## Constructor
|
|
29
|
+
## Constructor examples
|
|
30
30
|
|
|
31
31
|
### Connection String
|
|
32
32
|
|
|
@@ -70,7 +70,7 @@ const vectorStore = new PgVector({
|
|
|
70
70
|
|
|
71
71
|
## Methods
|
|
72
72
|
|
|
73
|
-
### createIndex()
|
|
73
|
+
### `createIndex()`
|
|
74
74
|
|
|
75
75
|
**indexName** (`string`): Name of the index to create
|
|
76
76
|
|
|
@@ -84,7 +84,7 @@ const vectorStore = new PgVector({
|
|
|
84
84
|
|
|
85
85
|
**metadataIndexes** (`string[]`): Array of metadata field names to create btree indexes on. Improves query performance when filtering by these metadata fields.
|
|
86
86
|
|
|
87
|
-
#### IndexConfig
|
|
87
|
+
#### `IndexConfig`
|
|
88
88
|
|
|
89
89
|
**type** (`'flat' | 'hnsw' | 'ivfflat'`): Index type (Default: `ivfflat`)
|
|
90
90
|
|
|
@@ -114,7 +114,7 @@ HNSW indexes require significant shared memory during construction. For 100K vec
|
|
|
114
114
|
|
|
115
115
|
Higher M values or efConstruction values will increase memory requirements significantly. Adjust your system's shared memory limits if needed.
|
|
116
116
|
|
|
117
|
-
### upsert()
|
|
117
|
+
### `upsert()`
|
|
118
118
|
|
|
119
119
|
**indexName** (`string`): Name of the index to upsert vectors into
|
|
120
120
|
|
|
@@ -124,7 +124,7 @@ Higher M values or efConstruction values will increase memory requirements signi
|
|
|
124
124
|
|
|
125
125
|
**ids** (`string[]`): Optional vector IDs (auto-generated if not provided)
|
|
126
126
|
|
|
127
|
-
### query()
|
|
127
|
+
### `query()`
|
|
128
128
|
|
|
129
129
|
**indexName** (`string`): Name of the index to query
|
|
130
130
|
|
|
@@ -144,11 +144,11 @@ Higher M values or efConstruction values will increase memory requirements signi
|
|
|
144
144
|
|
|
145
145
|
**options.probes** (`number`): IVF search parameter
|
|
146
146
|
|
|
147
|
-
### listIndexes()
|
|
147
|
+
### `listIndexes()`
|
|
148
148
|
|
|
149
149
|
Returns an array of index names as strings.
|
|
150
150
|
|
|
151
|
-
### describeIndex()
|
|
151
|
+
### `describeIndex()`
|
|
152
152
|
|
|
153
153
|
**indexName** (`string`): Name of the index to describe
|
|
154
154
|
|
|
@@ -169,11 +169,11 @@ interface PGIndexStats {
|
|
|
169
169
|
}
|
|
170
170
|
```
|
|
171
171
|
|
|
172
|
-
### deleteIndex()
|
|
172
|
+
### `deleteIndex()`
|
|
173
173
|
|
|
174
174
|
**indexName** (`string`): Name of the index to delete
|
|
175
175
|
|
|
176
|
-
### updateVector()
|
|
176
|
+
### `updateVector()`
|
|
177
177
|
|
|
178
178
|
Update a single vector by ID or by metadata filter. Either `id` or `filter` must be provided, but not both.
|
|
179
179
|
|
|
@@ -208,7 +208,7 @@ await pgVector.updateVector({
|
|
|
208
208
|
})
|
|
209
209
|
```
|
|
210
210
|
|
|
211
|
-
### deleteVector()
|
|
211
|
+
### `deleteVector()`
|
|
212
212
|
|
|
213
213
|
**indexName** (`string`): Name of the index containing the vector
|
|
214
214
|
|
|
@@ -220,7 +220,7 @@ Deletes a single vector by ID from the specified index.
|
|
|
220
220
|
await pgVector.deleteVector({ indexName: 'my_vectors', id: 'vector123' })
|
|
221
221
|
```
|
|
222
222
|
|
|
223
|
-
### deleteVectors()
|
|
223
|
+
### `deleteVectors()`
|
|
224
224
|
|
|
225
225
|
Delete multiple vectors by IDs or by metadata filter. Either `ids` or `filter` must be provided, but not both.
|
|
226
226
|
|
|
@@ -230,11 +230,11 @@ Delete multiple vectors by IDs or by metadata filter. Either `ids` or `filter` m
|
|
|
230
230
|
|
|
231
231
|
**filter** (`Record<string, any>`): Metadata filter to identify vectors to delete (mutually exclusive with ids)
|
|
232
232
|
|
|
233
|
-
### disconnect()
|
|
233
|
+
### `disconnect()`
|
|
234
234
|
|
|
235
235
|
Closes the database connection pool. Should be called when done using the store.
|
|
236
236
|
|
|
237
|
-
### buildIndex()
|
|
237
|
+
### `buildIndex()`
|
|
238
238
|
|
|
239
239
|
**indexName** (`string`): Name of the index to define
|
|
240
240
|
|
|
@@ -268,7 +268,7 @@ await pgVector.buildIndex('my_vectors', 'cosine', {
|
|
|
268
268
|
})
|
|
269
269
|
```
|
|
270
270
|
|
|
271
|
-
## Response
|
|
271
|
+
## Response types
|
|
272
272
|
|
|
273
273
|
Query results are returned in this format:
|
|
274
274
|
|
|
@@ -281,7 +281,7 @@ interface QueryResult {
|
|
|
281
281
|
}
|
|
282
282
|
```
|
|
283
283
|
|
|
284
|
-
## Error
|
|
284
|
+
## Error handling
|
|
285
285
|
|
|
286
286
|
The store throws typed errors that can be caught:
|
|
287
287
|
|
|
@@ -299,7 +299,7 @@ try {
|
|
|
299
299
|
}
|
|
300
300
|
```
|
|
301
301
|
|
|
302
|
-
## Index
|
|
302
|
+
## Index configuration guide
|
|
303
303
|
|
|
304
304
|
### Performance Optimization
|
|
305
305
|
|
|
@@ -331,14 +331,14 @@ The system automatically detects configuration changes and only rebuilds indexes
|
|
|
331
331
|
- Changed configuration: Index is dropped and rebuilt
|
|
332
332
|
- This prevents the performance issues from unnecessary index recreations
|
|
333
333
|
|
|
334
|
-
## Best
|
|
334
|
+
## Best practices
|
|
335
335
|
|
|
336
336
|
- Regularly evaluate your index configuration to ensure optimal performance.
|
|
337
337
|
- Adjust parameters like `lists` and `m` based on dataset size and query requirements.
|
|
338
338
|
- **Monitor index performance** using `describeIndex()` to track usage
|
|
339
339
|
- Rebuild indexes periodically to maintain efficiency, especially after significant data changes
|
|
340
340
|
|
|
341
|
-
## Direct
|
|
341
|
+
## Direct pool access
|
|
342
342
|
|
|
343
343
|
The `PgVector` class exposes its underlying PostgreSQL connection pool as a public field:
|
|
344
344
|
|
|
@@ -354,7 +354,7 @@ This enables advanced usage such as running direct SQL queries, managing transac
|
|
|
354
354
|
|
|
355
355
|
This design supports advanced use cases but requires careful resource management by the user.
|
|
356
356
|
|
|
357
|
-
## Usage
|
|
357
|
+
## Usage example
|
|
358
358
|
|
|
359
359
|
### Local embeddings with fastembed
|
|
360
360
|
|