@mastra/lance 1.0.0 → 1.0.1
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 +18 -0
- package/dist/docs/SKILL.md +15 -22
- package/dist/docs/{SOURCE_MAP.json → assets/SOURCE_MAP.json} +1 -1
- package/dist/docs/{rag/01-vector-databases.md → references/docs-rag-vector-databases.md} +208 -203
- package/dist/docs/{storage/01-reference.md → references/reference-storage-lance.md} +31 -13
- package/dist/docs/references/reference-vectors-lance.md +220 -0
- package/dist/index.cjs +53 -29
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +53 -29
- package/dist/index.js.map +1 -1
- package/dist/vector/index.d.ts +8 -3
- package/dist/vector/index.d.ts.map +1 -1
- package/package.json +7 -8
- package/dist/docs/README.md +0 -33
- package/dist/docs/vectors/01-reference.md +0 -149
|
@@ -1,14 +1,12 @@
|
|
|
1
|
-
> Guide on vector storage options in Mastra, including embedded and dedicated vector databases for similarity search.
|
|
2
|
-
|
|
3
1
|
# Storing Embeddings in A Vector Database
|
|
4
2
|
|
|
5
3
|
After generating embeddings, you need to store them in a database that supports vector similarity search. Mastra provides a consistent interface for storing and querying embeddings across various vector databases.
|
|
6
4
|
|
|
7
5
|
## Supported Databases
|
|
8
6
|
|
|
9
|
-
|
|
7
|
+
**MongoDB**:
|
|
10
8
|
|
|
11
|
-
```ts
|
|
9
|
+
```ts
|
|
12
10
|
import { MongoDBVector } from "@mastra/mongodb";
|
|
13
11
|
|
|
14
12
|
const store = new MongoDBVector({
|
|
@@ -27,15 +25,13 @@ await store.upsert({
|
|
|
27
25
|
});
|
|
28
26
|
```
|
|
29
27
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
For detailed setup instructions and best practices, see the [official MongoDB Atlas Vector Search documentation](https://www.mongodb.com/docs/atlas/atlas-vector-search/vector-search-overview/?utm_campaign=devrel&utm_source=third-party-content&utm_medium=cta&utm_content=mastra-docs).
|
|
28
|
+
### Using MongoDB Atlas Vector search
|
|
33
29
|
|
|
34
|
-
|
|
30
|
+
For detailed setup instructions and best practices, see the [official MongoDB Atlas Vector Search documentation](https://www.mongodb.com/docs/atlas/atlas-vector-search/vector-search-overview/?utm_campaign=devrel\&utm_source=third-party-content\&utm_medium=cta\&utm_content=mastra-docs).
|
|
35
31
|
|
|
36
|
-
|
|
32
|
+
**PgVector**:
|
|
37
33
|
|
|
38
|
-
```ts
|
|
34
|
+
```ts
|
|
39
35
|
import { PgVector } from "@mastra/pg";
|
|
40
36
|
|
|
41
37
|
const store = new PgVector({
|
|
@@ -55,16 +51,13 @@ await store.upsert({
|
|
|
55
51
|
});
|
|
56
52
|
```
|
|
57
53
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
PostgreSQL with the pgvector extension is a good solution for teams already using PostgreSQL who want to minimize infrastructure complexity.
|
|
61
|
-
For detailed setup instructions and best practices, see the [official pgvector repository](https://github.com/pgvector/pgvector).
|
|
54
|
+
### Using PostgreSQL with pgvector
|
|
62
55
|
|
|
63
|
-
|
|
56
|
+
PostgreSQL with the pgvector extension is a good solution for teams already using PostgreSQL who want to minimize infrastructure complexity. For detailed setup instructions and best practices, see the [official pgvector repository](https://github.com/pgvector/pgvector).
|
|
64
57
|
|
|
65
|
-
|
|
58
|
+
**Pinecone**:
|
|
66
59
|
|
|
67
|
-
```ts
|
|
60
|
+
```ts
|
|
68
61
|
import { PineconeVector } from "@mastra/pinecone";
|
|
69
62
|
|
|
70
63
|
const store = new PineconeVector({
|
|
@@ -82,11 +75,9 @@ await store.upsert({
|
|
|
82
75
|
});
|
|
83
76
|
```
|
|
84
77
|
|
|
85
|
-
|
|
78
|
+
**Qdrant**:
|
|
86
79
|
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
```ts title="vector-store.ts"
|
|
80
|
+
```ts
|
|
90
81
|
import { QdrantVector } from "@mastra/qdrant";
|
|
91
82
|
|
|
92
83
|
const store = new QdrantVector({
|
|
@@ -107,11 +98,9 @@ await store.upsert({
|
|
|
107
98
|
});
|
|
108
99
|
```
|
|
109
100
|
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
**chroma:**
|
|
101
|
+
**Chroma**:
|
|
113
102
|
|
|
114
|
-
```ts
|
|
103
|
+
```ts
|
|
115
104
|
import { ChromaVector } from "@mastra/chroma";
|
|
116
105
|
|
|
117
106
|
// Running Chroma locally
|
|
@@ -137,11 +126,9 @@ await store.upsert({
|
|
|
137
126
|
});
|
|
138
127
|
```
|
|
139
128
|
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
**astra:**
|
|
129
|
+
**Astra**:
|
|
143
130
|
|
|
144
|
-
```ts
|
|
131
|
+
```ts
|
|
145
132
|
import { AstraVector } from "@mastra/astra";
|
|
146
133
|
|
|
147
134
|
const store = new AstraVector({
|
|
@@ -163,11 +150,9 @@ await store.upsert({
|
|
|
163
150
|
});
|
|
164
151
|
```
|
|
165
152
|
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
**libsql:**
|
|
153
|
+
**libSQL**:
|
|
169
154
|
|
|
170
|
-
```ts
|
|
155
|
+
```ts
|
|
171
156
|
import { LibSQLVector } from "@mastra/core/vector/libsql";
|
|
172
157
|
|
|
173
158
|
const store = new LibSQLVector({
|
|
@@ -188,11 +173,9 @@ await store.upsert({
|
|
|
188
173
|
});
|
|
189
174
|
```
|
|
190
175
|
|
|
191
|
-
|
|
176
|
+
**Upstash**:
|
|
192
177
|
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
```ts title="vector-store.ts"
|
|
178
|
+
```ts
|
|
196
179
|
import { UpstashVector } from "@mastra/upstash";
|
|
197
180
|
|
|
198
181
|
// In upstash they refer to the store as an index
|
|
@@ -211,11 +194,9 @@ await store.upsert({
|
|
|
211
194
|
});
|
|
212
195
|
```
|
|
213
196
|
|
|
214
|
-
|
|
197
|
+
**Cloudflare**:
|
|
215
198
|
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
```ts title="vector-store.ts"
|
|
199
|
+
```ts
|
|
219
200
|
import { CloudflareVector } from "@mastra/vectorize";
|
|
220
201
|
|
|
221
202
|
const store = new CloudflareVector({
|
|
@@ -234,11 +215,9 @@ await store.upsert({
|
|
|
234
215
|
});
|
|
235
216
|
```
|
|
236
217
|
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
**opensearch:**
|
|
218
|
+
**OpenSearch**:
|
|
240
219
|
|
|
241
|
-
```ts
|
|
220
|
+
```ts
|
|
242
221
|
import { OpenSearchVector } from "@mastra/opensearch";
|
|
243
222
|
|
|
244
223
|
const store = new OpenSearchVector({ id: "opensearch", node: process.env.OPENSEARCH_URL });
|
|
@@ -255,14 +234,18 @@ await store.upsert({
|
|
|
255
234
|
});
|
|
256
235
|
```
|
|
257
236
|
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
**elasticsearch:**
|
|
237
|
+
**ElasticSearch**:
|
|
261
238
|
|
|
262
|
-
```ts
|
|
239
|
+
```ts
|
|
263
240
|
import { ElasticSearchVector } from "@mastra/elasticsearch";
|
|
264
241
|
|
|
265
|
-
const store = new ElasticSearchVector({
|
|
242
|
+
const store = new ElasticSearchVector({
|
|
243
|
+
id: 'elasticsearch-vector',
|
|
244
|
+
url: process.env.ELASTICSEARCH_URL,
|
|
245
|
+
auth: {
|
|
246
|
+
apiKey : process.env.ELASTICSEARCH_API_KEY
|
|
247
|
+
}
|
|
248
|
+
});
|
|
266
249
|
|
|
267
250
|
await store.createIndex({
|
|
268
251
|
indexName: "my-collection",
|
|
@@ -276,10 +259,13 @@ await store.upsert({
|
|
|
276
259
|
});
|
|
277
260
|
```
|
|
278
261
|
|
|
279
|
-
|
|
280
|
-
|
|
262
|
+
### Using Elasticsearch
|
|
263
|
+
|
|
264
|
+
For detailed setup instructions and best practices, see the [official Elasticsearch documentation](https://www.elastic.co/docs/solutions/search/get-started).
|
|
281
265
|
|
|
282
|
-
|
|
266
|
+
**Couchbase**:
|
|
267
|
+
|
|
268
|
+
```ts
|
|
283
269
|
import { CouchbaseVector } from "@mastra/couchbase";
|
|
284
270
|
|
|
285
271
|
const store = new CouchbaseVector({
|
|
@@ -302,10 +288,9 @@ await store.upsert({
|
|
|
302
288
|
});
|
|
303
289
|
```
|
|
304
290
|
|
|
305
|
-
|
|
306
|
-
**lancedb:**
|
|
291
|
+
**Lance**:
|
|
307
292
|
|
|
308
|
-
```ts
|
|
293
|
+
```ts
|
|
309
294
|
import { LanceVectorStore } from "@mastra/lance";
|
|
310
295
|
|
|
311
296
|
const store = await LanceVectorStore.create("/path/to/db");
|
|
@@ -323,15 +308,13 @@ await store.upsert({
|
|
|
323
308
|
});
|
|
324
309
|
```
|
|
325
310
|
|
|
326
|
-
|
|
311
|
+
### Using LanceDB
|
|
327
312
|
|
|
328
|
-
LanceDB is an embedded vector database built on the Lance columnar format, suitable for local development or cloud deployment.
|
|
329
|
-
For detailed setup instructions and best practices, see the [official LanceDB documentation](https://lancedb.github.io/lancedb/).
|
|
313
|
+
LanceDB is an embedded vector database built on the Lance columnar format, suitable for local development or cloud deployment. For detailed setup instructions and best practices, see the [official LanceDB documentation](https://lancedb.github.io/lancedb/).
|
|
330
314
|
|
|
331
|
-
|
|
332
|
-
**s3vectors:**
|
|
315
|
+
**S3 Vectors**:
|
|
333
316
|
|
|
334
|
-
```ts
|
|
317
|
+
```ts
|
|
335
318
|
import { S3Vectors } from "@mastra/s3vectors";
|
|
336
319
|
|
|
337
320
|
const store = new S3Vectors({
|
|
@@ -354,8 +337,6 @@ await store.upsert({
|
|
|
354
337
|
});
|
|
355
338
|
```
|
|
356
339
|
|
|
357
|
-
|
|
358
|
-
|
|
359
340
|
## Using Vector Storage
|
|
360
341
|
|
|
361
342
|
Once initialized, all vector stores share the same interface for creating indexes, upserting embeddings, and querying.
|
|
@@ -364,7 +345,7 @@ Once initialized, all vector stores share the same interface for creating indexe
|
|
|
364
345
|
|
|
365
346
|
Before storing embeddings, you need to create an index with the appropriate dimension size for your embedding model:
|
|
366
347
|
|
|
367
|
-
```ts
|
|
348
|
+
```ts
|
|
368
349
|
// Create an index with dimension 1536 (for text-embedding-3-small)
|
|
369
350
|
await store.createIndex({
|
|
370
351
|
indexName: "myCollection",
|
|
@@ -376,150 +357,174 @@ The dimension size must match the output dimension of your chosen embedding mode
|
|
|
376
357
|
|
|
377
358
|
- OpenAI text-embedding-3-small: 1536 dimensions (or custom, e.g., 256)
|
|
378
359
|
- Cohere embed-multilingual-v3: 1024 dimensions
|
|
379
|
-
- Google
|
|
360
|
+
- Google gemini-embedding-001: 768 dimensions (or custom)
|
|
380
361
|
|
|
381
|
-
> **
|
|
382
|
-
Index dimensions cannot be changed after creation. To use a different model, delete and recreate the index with the new dimension size.
|
|
362
|
+
> **Warning:** Index dimensions cannot be changed after creation. To use a different model, delete and recreate the index with the new dimension size.
|
|
383
363
|
|
|
384
364
|
### Naming Rules for Databases
|
|
385
365
|
|
|
386
366
|
Each vector database enforces specific naming conventions for indexes and collections to ensure compatibility and prevent conflicts.
|
|
387
367
|
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
368
|
+
**MongoDB**:
|
|
369
|
+
|
|
370
|
+
Collection (index) names must:
|
|
371
|
+
|
|
372
|
+
- Start with a letter or underscore
|
|
373
|
+
- Be up to 120 bytes long
|
|
374
|
+
- Contain only letters, numbers, underscores, or dots
|
|
375
|
+
- Cannot contain `$` or the null character
|
|
376
|
+
- Example: `my_collection.123` is valid
|
|
377
|
+
- Example: `my-index` is not valid (contains hyphen)
|
|
378
|
+
- Example: `My$Collection` is not valid (contains `$`)
|
|
379
|
+
|
|
380
|
+
**PgVector**:
|
|
381
|
+
|
|
382
|
+
Index names must:
|
|
383
|
+
|
|
384
|
+
- Start with a letter or underscore
|
|
385
|
+
- Contain only letters, numbers, and underscores
|
|
386
|
+
- Example: `my_index_123` is valid
|
|
387
|
+
- Example: `my-index` is not valid (contains hyphen)
|
|
388
|
+
|
|
389
|
+
**Pinecone**:
|
|
390
|
+
|
|
391
|
+
Index names must:
|
|
392
|
+
|
|
393
|
+
- Use only lowercase letters, numbers, and dashes
|
|
394
|
+
|
|
395
|
+
- Not contain dots (used for DNS routing)
|
|
396
|
+
|
|
397
|
+
- Not use non-Latin characters or emojis
|
|
398
|
+
|
|
399
|
+
- Have a combined length (with project ID) under 52 characters
|
|
400
|
+
|
|
401
|
+
- Example: `my-index-123` is valid
|
|
402
|
+
- Example: `my.index` is not valid (contains dot)
|
|
403
|
+
|
|
404
|
+
**Qdrant**:
|
|
405
|
+
|
|
406
|
+
Collection names must:
|
|
407
|
+
|
|
408
|
+
- Be 1-255 characters long
|
|
409
|
+
|
|
410
|
+
- Not contain any of these special characters:
|
|
411
|
+
|
|
412
|
+
- `< > : " / \ | ? *`
|
|
413
|
+
- Null character (`\0`)
|
|
414
|
+
- Unit separator (`\u{1F}`)
|
|
415
|
+
|
|
416
|
+
- Example: `my_collection_123` is valid
|
|
417
|
+
|
|
418
|
+
- Example: `my/collection` is not valid (contains slash)
|
|
419
|
+
|
|
420
|
+
**Chroma**:
|
|
421
|
+
|
|
422
|
+
Collection names must:
|
|
423
|
+
|
|
424
|
+
- Be 3-63 characters long
|
|
425
|
+
- Start and end with a letter or number
|
|
426
|
+
- Contain only letters, numbers, underscores, or hyphens
|
|
427
|
+
- Not contain consecutive periods (..)
|
|
428
|
+
- Not be a valid IPv4 address
|
|
429
|
+
- Example: `my-collection-123` is valid
|
|
430
|
+
- Example: `my..collection` is not valid (consecutive periods)
|
|
431
|
+
|
|
432
|
+
**Astra**:
|
|
433
|
+
|
|
434
|
+
Collection names must:
|
|
435
|
+
|
|
436
|
+
- Not be empty
|
|
437
|
+
- Be 48 characters or less
|
|
438
|
+
- Contain only letters, numbers, and underscores
|
|
439
|
+
- Example: `my_collection_123` is valid
|
|
440
|
+
- Example: `my-collection` is not valid (contains hyphen)
|
|
441
|
+
|
|
442
|
+
**libSQL**:
|
|
443
|
+
|
|
444
|
+
Index names must:
|
|
445
|
+
|
|
446
|
+
- Start with a letter or underscore
|
|
447
|
+
- Contain only letters, numbers, and underscores
|
|
448
|
+
- Example: `my_index_123` is valid
|
|
449
|
+
- Example: `my-index` is not valid (contains hyphen)
|
|
450
|
+
|
|
451
|
+
**Upstash**:
|
|
452
|
+
|
|
453
|
+
Namespace names must:
|
|
454
|
+
|
|
455
|
+
- Be 2-100 characters long
|
|
456
|
+
|
|
457
|
+
- Contain only:
|
|
458
|
+
|
|
459
|
+
- Alphanumeric characters (a-z, A-Z, 0-9)
|
|
460
|
+
- Underscores, hyphens, dots
|
|
461
|
+
|
|
462
|
+
- Not start or end with special characters (\_, -, .)
|
|
463
|
+
|
|
464
|
+
- Can be case-sensitive
|
|
465
|
+
|
|
466
|
+
- Example: `MyNamespace123` is valid
|
|
467
|
+
|
|
468
|
+
- Example: `_namespace` is not valid (starts with underscore)
|
|
469
|
+
|
|
470
|
+
**Cloudflare**:
|
|
471
|
+
|
|
472
|
+
Index names must:
|
|
473
|
+
|
|
474
|
+
- Start with a letter
|
|
475
|
+
- Be shorter than 32 characters
|
|
476
|
+
- Contain only lowercase ASCII letters, numbers, and dashes
|
|
477
|
+
- Use dashes instead of spaces
|
|
478
|
+
- Example: `my-index-123` is valid
|
|
479
|
+
- Example: `My_Index` is not valid (uppercase and underscore)
|
|
480
|
+
|
|
481
|
+
**OpenSearch**:
|
|
482
|
+
|
|
483
|
+
Index names must:
|
|
484
|
+
|
|
485
|
+
- Use only lowercase letters
|
|
486
|
+
- Not begin with underscores or hyphens
|
|
487
|
+
- Not contain spaces, commas
|
|
488
|
+
- Not contain special characters (e.g. `:`, `"`, `*`, `+`, `/`, `\`, `|`, `?`, `#`, `>`, `<`)
|
|
489
|
+
- Example: `my-index-123` is valid
|
|
490
|
+
- Example: `My_Index` is not valid (contains uppercase letters)
|
|
491
|
+
- Example: `_myindex` is not valid (begins with underscore)
|
|
492
|
+
|
|
493
|
+
**ElasticSearch**:
|
|
494
|
+
|
|
495
|
+
Index names must:
|
|
496
|
+
|
|
497
|
+
- Use only lowercase letters
|
|
498
|
+
- Not exceed 255 bytes (counting multi-byte characters)
|
|
499
|
+
- Not begin with underscores, hyphens, or plus signs
|
|
500
|
+
- Not contain spaces, commas
|
|
501
|
+
- Not contain special characters (e.g. `:`, `"`, `*`, `+`, `/`, `\`, `|`, `?`, `#`, `>`, `<`)
|
|
502
|
+
- Not be "." or ".."
|
|
503
|
+
- Not start with "." (deprecated except for system/hidden indices)
|
|
504
|
+
- Example: `my-index-123` is valid
|
|
505
|
+
- Example: `My_Index` is not valid (contains uppercase letters)
|
|
506
|
+
- Example: `_myindex` is not valid (begins with underscore)
|
|
507
|
+
- Example: `.myindex` is not valid (begins with dot, deprecated)
|
|
508
|
+
|
|
509
|
+
**S3 Vectors**:
|
|
510
|
+
|
|
511
|
+
Index names must:
|
|
512
|
+
|
|
513
|
+
- Be unique within the same vector bucket
|
|
514
|
+
- Be 3–63 characters long
|
|
515
|
+
- Use only lowercase letters (`a–z`), numbers (`0–9`), hyphens (`-`), and dots (`.`)
|
|
516
|
+
- Begin and end with a letter or number
|
|
517
|
+
- Example: `my-index.123` is valid
|
|
518
|
+
- Example: `my_index` is not valid (contains underscore)
|
|
519
|
+
- Example: `-myindex` is not valid (begins with hyphen)
|
|
520
|
+
- Example: `myindex-` is not valid (ends with hyphen)
|
|
521
|
+
- Example: `MyIndex` is not valid (contains uppercase letters)
|
|
517
522
|
|
|
518
523
|
### Upserting Embeddings
|
|
519
524
|
|
|
520
525
|
After creating an index, you can store embeddings along with their basic metadata:
|
|
521
526
|
|
|
522
|
-
```ts
|
|
527
|
+
```ts
|
|
523
528
|
// Store embeddings with their corresponding metadata
|
|
524
529
|
await store.upsert({
|
|
525
530
|
indexName: "myCollection", // index name
|
|
@@ -542,8 +547,7 @@ The upsert operation:
|
|
|
542
547
|
|
|
543
548
|
Vector stores support rich metadata (any JSON-serializable fields) for filtering and organization. Since metadata is stored with no fixed schema, use consistent field naming to avoid unexpected query results.
|
|
544
549
|
|
|
545
|
-
> **
|
|
546
|
-
Metadata is crucial for vector storage - without it, you'd only have numerical embeddings with no way to return the original text or filter results. Always store at least the source text as metadata.
|
|
550
|
+
> **Warning:** Metadata is crucial for vector storage - without it, you'd only have numerical embeddings with no way to return the original text or filter results. Always store at least the source text as metadata.
|
|
547
551
|
|
|
548
552
|
```ts
|
|
549
553
|
// Store embeddings with rich metadata for better organization and filtering
|
|
@@ -585,7 +589,7 @@ When building RAG applications, you often need to clean up stale vectors when do
|
|
|
585
589
|
|
|
586
590
|
The most common use case is deleting all vectors for a specific document when a user deletes it:
|
|
587
591
|
|
|
588
|
-
```ts
|
|
592
|
+
```ts
|
|
589
593
|
// Delete all vectors for a specific document
|
|
590
594
|
await store.deleteVectors({
|
|
591
595
|
indexName: "myCollection",
|
|
@@ -594,6 +598,7 @@ await store.deleteVectors({
|
|
|
594
598
|
```
|
|
595
599
|
|
|
596
600
|
This is particularly useful when:
|
|
601
|
+
|
|
597
602
|
- A user deletes a document and you need to remove all its chunks
|
|
598
603
|
- You're re-indexing a document and want to remove old vectors first
|
|
599
604
|
- You need to clean up vectors for a specific user or tenant
|
|
@@ -602,7 +607,7 @@ This is particularly useful when:
|
|
|
602
607
|
|
|
603
608
|
You can also use complex filters to delete vectors matching multiple conditions:
|
|
604
609
|
|
|
605
|
-
```ts
|
|
610
|
+
```ts
|
|
606
611
|
// Delete all vectors for multiple documents
|
|
607
612
|
await store.deleteVectors({
|
|
608
613
|
indexName: "myCollection",
|
|
@@ -627,7 +632,7 @@ await store.deleteVectors({
|
|
|
627
632
|
|
|
628
633
|
If you have specific vector IDs to delete, you can pass them directly:
|
|
629
634
|
|
|
630
|
-
```ts
|
|
635
|
+
```ts
|
|
631
636
|
// Delete specific vectors by their IDs
|
|
632
637
|
await store.deleteVectors({
|
|
633
638
|
indexName: "myCollection",
|
|
@@ -1,20 +1,33 @@
|
|
|
1
|
-
# Storage
|
|
1
|
+
# LanceDB Storage
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
The LanceDB storage implementation provides a high-performance storage solution using the LanceDB database system, which excels at handling both traditional data storage and vector operations.
|
|
4
4
|
|
|
5
|
+
> **Observability Not Supported:** LanceDB storage **does not support the observability domain**. Traces from the `DefaultExporter` cannot be persisted to LanceDB, and Mastra Studio's observability features won't work with LanceDB as your only storage provider. To enable observability, use [composite storage](https://mastra.ai/reference/storage/composite) to route observability data to a supported provider like ClickHouse or PostgreSQL.
|
|
5
6
|
|
|
6
|
-
|
|
7
|
+
## Installation
|
|
7
8
|
|
|
8
|
-
|
|
9
|
+
**npm**:
|
|
9
10
|
|
|
10
|
-
|
|
11
|
+
```bash
|
|
12
|
+
npm install @mastra/lance@latest
|
|
13
|
+
```
|
|
11
14
|
|
|
12
|
-
|
|
15
|
+
**pnpm**:
|
|
13
16
|
|
|
14
|
-
|
|
17
|
+
```bash
|
|
18
|
+
pnpm add @mastra/lance@latest
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
**Yarn**:
|
|
15
22
|
|
|
16
23
|
```bash
|
|
17
|
-
|
|
24
|
+
yarn add @mastra/lance@latest
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
**Bun**:
|
|
28
|
+
|
|
29
|
+
```bash
|
|
30
|
+
bun add @mastra/lance@latest
|
|
18
31
|
```
|
|
19
32
|
|
|
20
33
|
## Usage
|
|
@@ -40,6 +53,12 @@ const storage = await LanceStorage.create("my-storage", "s3://bucket/db", {
|
|
|
40
53
|
|
|
41
54
|
### LanceStorage.create()
|
|
42
55
|
|
|
56
|
+
**name:** (`string`): Name identifier for the storage instance
|
|
57
|
+
|
|
58
|
+
**uri:** (`string`): URI to connect to the LanceDB database. Can be a local path, cloud DB URL, or S3 bucket URL
|
|
59
|
+
|
|
60
|
+
**options?:** (`ConnectionOptions`): Connection options for LanceDB, such as timeout settings, authentication, etc.
|
|
61
|
+
|
|
43
62
|
## Additional Notes
|
|
44
63
|
|
|
45
64
|
### Schema Management
|
|
@@ -82,23 +101,22 @@ const memoryStore = await storage.getStore('memory');
|
|
|
82
101
|
const thread = await memoryStore?.getThreadById({ threadId: "..." });
|
|
83
102
|
```
|
|
84
103
|
|
|
85
|
-
> **
|
|
86
|
-
If `init()` is not called, tables won't be created and storage operations will fail silently or throw errors.
|
|
104
|
+
> **Warning:** If `init()` is not called, tables won't be created and storage operations will fail silently or throw errors.
|
|
87
105
|
|
|
88
106
|
### Deployment Options
|
|
89
107
|
|
|
90
108
|
LanceDB storage can be configured for different deployment scenarios:
|
|
91
109
|
|
|
92
110
|
- **Local Development**: Use a local file path for development and testing
|
|
93
|
-
```
|
|
111
|
+
```text
|
|
94
112
|
/path/to/db
|
|
95
113
|
```
|
|
96
114
|
- **Cloud Deployment**: Connect to a hosted LanceDB instance
|
|
97
|
-
```
|
|
115
|
+
```text
|
|
98
116
|
db://host:port
|
|
99
117
|
```
|
|
100
118
|
- **S3 Storage**: Use Amazon S3 for scalable cloud storage
|
|
101
|
-
```
|
|
119
|
+
```text
|
|
102
120
|
s3://bucket/db
|
|
103
121
|
```
|
|
104
122
|
|