@mastra/qdrant 1.0.0-beta.0 → 1.0.0-beta.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 +9 -0
- package/README.md +3 -0
- package/dist/index.cjs +215 -46
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +215 -46
- package/dist/index.js.map +1 -1
- package/dist/vector/index.d.ts +15 -5
- package/dist/vector/index.d.ts.map +1 -1
- package/package.json +9 -5
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,14 @@
|
|
|
1
1
|
# @mastra/qdrant
|
|
2
2
|
|
|
3
|
+
## 1.0.0-beta.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Add new deleteVectors, updateVector by filter ([#10408](https://github.com/mastra-ai/mastra/pull/10408))
|
|
8
|
+
|
|
9
|
+
- Updated dependencies [[`21a15de`](https://github.com/mastra-ai/mastra/commit/21a15de369fe82aac26bb642ed7be73505475e8b), [`feb7ee4`](https://github.com/mastra-ai/mastra/commit/feb7ee4d09a75edb46c6669a3beaceec78811747), [`b0e2ea5`](https://github.com/mastra-ai/mastra/commit/b0e2ea5b52c40fae438b9e2f7baee6f0f89c5442), [`c456e01`](https://github.com/mastra-ai/mastra/commit/c456e0149e3c176afcefdbd9bb1d2c5917723725), [`ab035c2`](https://github.com/mastra-ai/mastra/commit/ab035c2ef6d8cc7bb25f06f1a38508bd9e6f126b), [`1a46a56`](https://github.com/mastra-ai/mastra/commit/1a46a566f45a3fcbadc1cf36bf86d351f264bfa3), [`3cf540b`](https://github.com/mastra-ai/mastra/commit/3cf540b9fbfea8f4fc8d3a2319a4e6c0b0cbfd52), [`1c6ce51`](https://github.com/mastra-ai/mastra/commit/1c6ce51f875915ab57fd36873623013699a2a65d), [`898a972`](https://github.com/mastra-ai/mastra/commit/898a9727d286c2510d6b702dfd367e6aaf5c6b0f), [`a97003a`](https://github.com/mastra-ai/mastra/commit/a97003aa1cf2f4022a41912324a1e77263b326b8), [`ccc141e`](https://github.com/mastra-ai/mastra/commit/ccc141ed27da0abc3a3fc28e9e5128152e8e37f4), [`fe3b897`](https://github.com/mastra-ai/mastra/commit/fe3b897c2ccbcd2b10e81b099438c7337feddf89), [`00123ba`](https://github.com/mastra-ai/mastra/commit/00123ba96dc9e5cd0b110420ebdba56d8f237b25), [`29c4309`](https://github.com/mastra-ai/mastra/commit/29c4309f818b24304c041bcb4a8f19b5f13f6b62), [`16785ce`](https://github.com/mastra-ai/mastra/commit/16785ced928f6f22638f4488cf8a125d99211799), [`de8239b`](https://github.com/mastra-ai/mastra/commit/de8239bdcb1d8c0cfa06da21f1569912a66bbc8a), [`b5e6cd7`](https://github.com/mastra-ai/mastra/commit/b5e6cd77fc8c8e64e0494c1d06cee3d84e795d1e), [`3759cb0`](https://github.com/mastra-ai/mastra/commit/3759cb064935b5f74c65ac2f52a1145f7352899d), [`651e772`](https://github.com/mastra-ai/mastra/commit/651e772eb1475fb13e126d3fcc01751297a88214), [`b61b93f`](https://github.com/mastra-ai/mastra/commit/b61b93f9e058b11dd2eec169853175d31dbdd567), [`bae33d9`](https://github.com/mastra-ai/mastra/commit/bae33d91a63fbb64d1e80519e1fc1acaed1e9013), [`c0b731f`](https://github.com/mastra-ai/mastra/commit/c0b731fb27d712dc8582e846df5c0332a6a0c5ba), [`43ca8f2`](https://github.com/mastra-ai/mastra/commit/43ca8f2c7334851cc7b4d3d2f037d8784bfbdd5f), [`2ca67cc`](https://github.com/mastra-ai/mastra/commit/2ca67cc3bb1f6a617353fdcab197d9efebe60d6f), [`9e67002`](https://github.com/mastra-ai/mastra/commit/9e67002b52c9be19936c420a489dbee9c5fd6a78), [`35edc49`](https://github.com/mastra-ai/mastra/commit/35edc49ac0556db609189641d6341e76771b81fc)]:
|
|
10
|
+
- @mastra/core@1.0.0-beta.5
|
|
11
|
+
|
|
3
12
|
## 1.0.0-beta.0
|
|
4
13
|
|
|
5
14
|
### Major Changes
|
package/README.md
CHANGED
|
@@ -72,6 +72,9 @@ The following distance metrics are supported:
|
|
|
72
72
|
- `createIndex({ indexName, dimension, metric? })`: Create a new collection
|
|
73
73
|
- `upsert({ indexName, vectors, metadata?, ids? })`: Add or update vectors
|
|
74
74
|
- `query({ indexName, queryVector, topK?, filter?, includeVector? })`: Search for similar vectors
|
|
75
|
+
- `updateVector({ indexName, id?, filter?, update })`: Update a single vector by ID or metadata filter
|
|
76
|
+
- `deleteVector({ indexName, id })`: Delete a single vector by ID
|
|
77
|
+
- `deleteVectors({ indexName, ids?, filter? })`: Delete multiple vectors by IDs or metadata filter
|
|
75
78
|
- `listIndexes()`: List all collections
|
|
76
79
|
- `describeIndex(indexName)`: Get collection statistics
|
|
77
80
|
- `deleteIndex(indexName)`: Delete a collection
|
package/dist/index.cjs
CHANGED
|
@@ -418,6 +418,11 @@ var QdrantVector = class extends vector.MastraVector {
|
|
|
418
418
|
try {
|
|
419
419
|
await this.client.deleteCollection(indexName);
|
|
420
420
|
} catch (error$1) {
|
|
421
|
+
const errorMessage = error$1?.message || error$1?.toString() || "";
|
|
422
|
+
if (error$1?.status === 404 || errorMessage.toLowerCase().includes("not found") || errorMessage.toLowerCase().includes("not exist")) {
|
|
423
|
+
this.logger.info(`Collection ${indexName} does not exist, treating as already deleted`);
|
|
424
|
+
return;
|
|
425
|
+
}
|
|
421
426
|
throw new error.MastraError(
|
|
422
427
|
{
|
|
423
428
|
id: "STORAGE_QDRANT_VECTOR_DELETE_INDEX_FAILED",
|
|
@@ -430,66 +435,143 @@ var QdrantVector = class extends vector.MastraVector {
|
|
|
430
435
|
}
|
|
431
436
|
}
|
|
432
437
|
/**
|
|
433
|
-
* Updates a vector by its ID
|
|
434
|
-
* @param indexName - The name of the index containing the vector.
|
|
435
|
-
* @param id - The ID of the vector to update.
|
|
438
|
+
* Updates a vector by its ID or multiple vectors matching a filter.
|
|
439
|
+
* @param indexName - The name of the index containing the vector(s).
|
|
440
|
+
* @param id - The ID of the vector to update (mutually exclusive with filter).
|
|
441
|
+
* @param filter - Filter to match multiple vectors to update (mutually exclusive with id).
|
|
436
442
|
* @param update - An object containing the vector and/or metadata to update.
|
|
437
443
|
* @param update.vector - An optional array of numbers representing the new vector.
|
|
438
444
|
* @param update.metadata - An optional record containing the new metadata.
|
|
439
445
|
* @returns A promise that resolves when the update is complete.
|
|
440
446
|
* @throws Will throw an error if no updates are provided or if the update operation fails.
|
|
441
447
|
*/
|
|
442
|
-
async updateVector({ indexName, id, update }) {
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
{
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
448
|
+
async updateVector({ indexName, id, filter, update }) {
|
|
449
|
+
if (id && filter) {
|
|
450
|
+
throw new error.MastraError({
|
|
451
|
+
id: "STORAGE_QDRANT_VECTOR_UPDATE_MUTUALLY_EXCLUSIVE",
|
|
452
|
+
text: "Cannot specify both id and filter - they are mutually exclusive",
|
|
453
|
+
domain: error.ErrorDomain.STORAGE,
|
|
454
|
+
category: error.ErrorCategory.USER,
|
|
455
|
+
details: { indexName }
|
|
456
|
+
});
|
|
457
|
+
}
|
|
458
|
+
if (!id && !filter) {
|
|
459
|
+
throw new error.MastraError({
|
|
460
|
+
id: "STORAGE_QDRANT_VECTOR_UPDATE_NO_TARGET",
|
|
461
|
+
text: "Either id or filter must be provided",
|
|
462
|
+
domain: error.ErrorDomain.STORAGE,
|
|
463
|
+
category: error.ErrorCategory.USER,
|
|
464
|
+
details: { indexName }
|
|
465
|
+
});
|
|
466
|
+
}
|
|
467
|
+
if (!update.vector && !update.metadata) {
|
|
468
|
+
throw new error.MastraError({
|
|
469
|
+
id: "STORAGE_QDRANT_VECTOR_UPDATE_NO_PAYLOAD",
|
|
470
|
+
text: "No updates provided",
|
|
471
|
+
domain: error.ErrorDomain.STORAGE,
|
|
472
|
+
category: error.ErrorCategory.USER,
|
|
473
|
+
details: {
|
|
474
|
+
indexName,
|
|
475
|
+
...id && { id }
|
|
476
|
+
}
|
|
477
|
+
});
|
|
478
|
+
}
|
|
479
|
+
if (filter && Object.keys(filter).length === 0) {
|
|
480
|
+
throw new error.MastraError({
|
|
481
|
+
id: "STORAGE_QDRANT_VECTOR_UPDATE_EMPTY_FILTER",
|
|
482
|
+
text: "Filter cannot be an empty filter object",
|
|
483
|
+
domain: error.ErrorDomain.STORAGE,
|
|
484
|
+
category: error.ErrorCategory.USER,
|
|
485
|
+
details: { indexName }
|
|
486
|
+
});
|
|
457
487
|
}
|
|
458
|
-
const pointId = this.parsePointId(id);
|
|
459
488
|
try {
|
|
460
|
-
if (
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
489
|
+
if (id) {
|
|
490
|
+
const pointId = this.parsePointId(id);
|
|
491
|
+
if (update.metadata && !update.vector) {
|
|
492
|
+
await this.client.setPayload(indexName, { payload: update.metadata, points: [pointId] });
|
|
493
|
+
return;
|
|
494
|
+
}
|
|
495
|
+
if (update.vector && !update.metadata) {
|
|
496
|
+
await this.client.updateVectors(indexName, {
|
|
497
|
+
points: [
|
|
498
|
+
{
|
|
499
|
+
id: pointId,
|
|
500
|
+
vector: update.vector
|
|
501
|
+
}
|
|
502
|
+
]
|
|
503
|
+
});
|
|
504
|
+
return;
|
|
505
|
+
}
|
|
506
|
+
if (update.vector && update.metadata) {
|
|
507
|
+
const point = {
|
|
508
|
+
id: pointId,
|
|
509
|
+
vector: update.vector,
|
|
510
|
+
payload: update.metadata
|
|
511
|
+
};
|
|
512
|
+
await this.client.upsert(indexName, {
|
|
513
|
+
points: [point]
|
|
514
|
+
});
|
|
515
|
+
return;
|
|
516
|
+
}
|
|
517
|
+
} else if (filter) {
|
|
518
|
+
const translatedFilter = this.transformFilter(filter);
|
|
519
|
+
const matchingPoints = [];
|
|
520
|
+
let offset = void 0;
|
|
521
|
+
do {
|
|
522
|
+
const scrollResult = await this.client.scroll(indexName, {
|
|
523
|
+
filter: translatedFilter,
|
|
524
|
+
limit: 100,
|
|
525
|
+
offset,
|
|
526
|
+
with_payload: false,
|
|
527
|
+
with_vector: update.vector ? false : true
|
|
528
|
+
// Only fetch vectors if not updating them
|
|
529
|
+
});
|
|
530
|
+
matchingPoints.push(
|
|
531
|
+
...scrollResult.points.map((point) => ({
|
|
532
|
+
id: point.id,
|
|
533
|
+
vector: Array.isArray(point.vector) ? point.vector : void 0
|
|
534
|
+
}))
|
|
535
|
+
);
|
|
536
|
+
const nextOffset = scrollResult.next_page_offset;
|
|
537
|
+
offset = typeof nextOffset === "string" || typeof nextOffset === "number" ? nextOffset : void 0;
|
|
538
|
+
} while (offset !== void 0);
|
|
539
|
+
if (matchingPoints.length === 0) {
|
|
540
|
+
return;
|
|
541
|
+
}
|
|
542
|
+
const pointIds = matchingPoints.map((p) => p.id);
|
|
543
|
+
if (update.metadata && !update.vector) {
|
|
544
|
+
await this.client.setPayload(indexName, { payload: update.metadata, points: pointIds });
|
|
545
|
+
return;
|
|
546
|
+
}
|
|
547
|
+
if (update.vector) {
|
|
548
|
+
const points = matchingPoints.map((p) => ({
|
|
549
|
+
id: p.id,
|
|
550
|
+
vector: update.vector,
|
|
551
|
+
payload: update.metadata || {}
|
|
552
|
+
}));
|
|
553
|
+
for (let i = 0; i < points.length; i += BATCH_SIZE) {
|
|
554
|
+
const batch = points.slice(i, i + BATCH_SIZE);
|
|
555
|
+
await this.client.upsert(indexName, {
|
|
556
|
+
points: batch,
|
|
557
|
+
wait: true
|
|
558
|
+
});
|
|
559
|
+
}
|
|
560
|
+
return;
|
|
561
|
+
}
|
|
485
562
|
}
|
|
486
563
|
} catch (error$1) {
|
|
564
|
+
if (error$1 instanceof error.MastraError) throw error$1;
|
|
487
565
|
throw new error.MastraError(
|
|
488
566
|
{
|
|
489
567
|
id: "STORAGE_QDRANT_VECTOR_UPDATE_VECTOR_FAILED",
|
|
490
568
|
domain: error.ErrorDomain.STORAGE,
|
|
491
569
|
category: error.ErrorCategory.THIRD_PARTY,
|
|
492
|
-
details: {
|
|
570
|
+
details: {
|
|
571
|
+
indexName,
|
|
572
|
+
...id && { id },
|
|
573
|
+
...filter && { filter: JSON.stringify(filter) }
|
|
574
|
+
}
|
|
493
575
|
},
|
|
494
576
|
error$1
|
|
495
577
|
);
|
|
@@ -514,7 +596,10 @@ var QdrantVector = class extends vector.MastraVector {
|
|
|
514
596
|
id: "STORAGE_QDRANT_VECTOR_DELETE_VECTOR_FAILED",
|
|
515
597
|
domain: error.ErrorDomain.STORAGE,
|
|
516
598
|
category: error.ErrorCategory.THIRD_PARTY,
|
|
517
|
-
details: {
|
|
599
|
+
details: {
|
|
600
|
+
indexName,
|
|
601
|
+
...id && { id }
|
|
602
|
+
}
|
|
518
603
|
},
|
|
519
604
|
error$1
|
|
520
605
|
);
|
|
@@ -555,6 +640,90 @@ var QdrantVector = class extends vector.MastraVector {
|
|
|
555
640
|
}
|
|
556
641
|
return id;
|
|
557
642
|
}
|
|
643
|
+
/**
|
|
644
|
+
* Deletes multiple vectors by IDs or filter.
|
|
645
|
+
* @param indexName - The name of the index containing the vectors.
|
|
646
|
+
* @param ids - Array of vector IDs to delete (mutually exclusive with filter).
|
|
647
|
+
* @param filter - Filter to match vectors to delete (mutually exclusive with ids).
|
|
648
|
+
* @returns A promise that resolves when the deletion is complete.
|
|
649
|
+
* @throws Will throw an error if both ids and filter are provided, or if neither is provided.
|
|
650
|
+
*/
|
|
651
|
+
async deleteVectors({ indexName, filter, ids }) {
|
|
652
|
+
if (ids && filter) {
|
|
653
|
+
throw new error.MastraError({
|
|
654
|
+
id: "STORAGE_QDRANT_VECTOR_DELETE_VECTORS_MUTUALLY_EXCLUSIVE",
|
|
655
|
+
text: "Cannot specify both ids and filter - they are mutually exclusive",
|
|
656
|
+
domain: error.ErrorDomain.STORAGE,
|
|
657
|
+
category: error.ErrorCategory.USER,
|
|
658
|
+
details: { indexName }
|
|
659
|
+
});
|
|
660
|
+
}
|
|
661
|
+
if (!ids && !filter) {
|
|
662
|
+
throw new error.MastraError({
|
|
663
|
+
id: "STORAGE_QDRANT_VECTOR_DELETE_VECTORS_NO_TARGET",
|
|
664
|
+
text: "Either filter or ids must be provided",
|
|
665
|
+
domain: error.ErrorDomain.STORAGE,
|
|
666
|
+
category: error.ErrorCategory.USER,
|
|
667
|
+
details: { indexName }
|
|
668
|
+
});
|
|
669
|
+
}
|
|
670
|
+
if (ids && ids.length === 0) {
|
|
671
|
+
throw new error.MastraError({
|
|
672
|
+
id: "STORAGE_QDRANT_VECTOR_DELETE_VECTORS_EMPTY_IDS",
|
|
673
|
+
text: "Cannot delete with empty ids array",
|
|
674
|
+
domain: error.ErrorDomain.STORAGE,
|
|
675
|
+
category: error.ErrorCategory.USER,
|
|
676
|
+
details: { indexName }
|
|
677
|
+
});
|
|
678
|
+
}
|
|
679
|
+
if (filter && Object.keys(filter).length === 0) {
|
|
680
|
+
throw new error.MastraError({
|
|
681
|
+
id: "STORAGE_QDRANT_VECTOR_DELETE_VECTORS_EMPTY_FILTER",
|
|
682
|
+
text: "Cannot delete with empty filter object",
|
|
683
|
+
domain: error.ErrorDomain.STORAGE,
|
|
684
|
+
category: error.ErrorCategory.USER,
|
|
685
|
+
details: { indexName }
|
|
686
|
+
});
|
|
687
|
+
}
|
|
688
|
+
try {
|
|
689
|
+
if (ids) {
|
|
690
|
+
const pointIds = ids.map((id) => this.parsePointId(id));
|
|
691
|
+
try {
|
|
692
|
+
await this.client.delete(indexName, {
|
|
693
|
+
points: pointIds,
|
|
694
|
+
wait: true
|
|
695
|
+
});
|
|
696
|
+
} catch (error) {
|
|
697
|
+
const message = error?.message || error?.toString() || "";
|
|
698
|
+
if (message.toLowerCase().includes("bad request")) {
|
|
699
|
+
return;
|
|
700
|
+
}
|
|
701
|
+
throw error;
|
|
702
|
+
}
|
|
703
|
+
} else if (filter) {
|
|
704
|
+
const translatedFilter = this.transformFilter(filter) ?? {};
|
|
705
|
+
await this.client.delete(indexName, {
|
|
706
|
+
filter: translatedFilter,
|
|
707
|
+
wait: true
|
|
708
|
+
});
|
|
709
|
+
}
|
|
710
|
+
} catch (error$1) {
|
|
711
|
+
if (error$1 instanceof error.MastraError) throw error$1;
|
|
712
|
+
throw new error.MastraError(
|
|
713
|
+
{
|
|
714
|
+
id: "STORAGE_QDRANT_VECTOR_DELETE_VECTORS_FAILED",
|
|
715
|
+
domain: error.ErrorDomain.STORAGE,
|
|
716
|
+
category: error.ErrorCategory.THIRD_PARTY,
|
|
717
|
+
details: {
|
|
718
|
+
indexName,
|
|
719
|
+
...filter && { filter: JSON.stringify(filter) },
|
|
720
|
+
...ids && { idsCount: ids.length }
|
|
721
|
+
}
|
|
722
|
+
},
|
|
723
|
+
error$1
|
|
724
|
+
);
|
|
725
|
+
}
|
|
726
|
+
}
|
|
558
727
|
};
|
|
559
728
|
|
|
560
729
|
// src/vector/prompt.ts
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/vector/filter.ts","../src/vector/index.ts","../src/vector/prompt.ts"],"names":["BaseFilterTranslator","MastraVector","QdrantClient","error","MastraError","ErrorDomain","ErrorCategory"],"mappings":";;;;;;;;AAwHO,IAAM,sBAAA,GAAN,cAAqCA,2BAAA,CAAyC;AAAA,EAChE,kBAAkB,GAAA,EAAqC;AACxE,IAAA,OAAO,MAAM,iBAAA,CAAkB,GAAG,CAAA,IAAK,GAAA,KAAQ,YAAY,GAAA,KAAQ,YAAA;AAAA,EACrE;AAAA,EAEmB,qBAAA,GAAyC;AA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;AAAA;;AAAA;AAAA;AAAA;AAAA;AAAA;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,CAAA","file":"index.cjs","sourcesContent":["import { BaseFilterTranslator } from '@mastra/core/vector/filter';\nimport type {\n VectorFilter,\n LogicalOperator,\n OperatorSupport,\n OperatorValueMap,\n LogicalOperatorValueMap,\n BlacklistedRootOperators,\n} from '@mastra/core/vector/filter';\n\ntype QdrantOperatorValueMap = Omit<OperatorValueMap, '$options' | '$elemMatch' | '$all'> & {\n /**\n * $count: Filter by array length or value count.\n * Example: { tags: { $count: { gt: 2 } } }\n */\n $count: {\n $gt?: number;\n $gte?: number;\n $lt?: number;\n $lte?: number;\n $eq?: number;\n };\n\n /**\n * $geo: Geospatial filter.\n * Example: { location: { $geo: { type: 'geo_radius', center: [lon, lat], radius: 1000 } } }\n */\n $geo: {\n type: string;\n [key: string]: any;\n };\n\n /**\n * $hasId: Filter by point IDs.\n * Allowed at root level.\n * Example: { $hasId: '123' } or { $hasId: ['123', '456'] }\n */\n $hasId: string | string[];\n\n /**\n * $nested: Nested object filter.\n * Example: { metadata: { $nested: { key: 'foo', filter: { $eq: 'bar' } } } }\n */\n $nested: {\n // Additional properties depend on the nested object structure\n [key: string]: any;\n };\n\n /**\n * $hasVector: Filter by vector existence or field.\n * Allowed at root level.\n * Example: { $hasVector: true } or { $hasVector: 'vector_field' }\n */\n $hasVector: boolean | string;\n\n /**\n * $datetime: RFC 3339 datetime range.\n * Example: { createdAt: { $datetime: { gte: '2024-01-01T00:00:00Z' } } }\n */\n $datetime: {\n key?: string;\n range?: {\n gt?: Date | string;\n gte?: Date | string;\n lt?: Date | string;\n lte?: Date | string;\n eq?: Date | string;\n };\n };\n\n /**\n * $null: Check if a field is null.\n * Example: { metadata: { $null: true } }\n */\n $null: boolean;\n\n /**\n * $empty: Check if an array or object field is empty.\n * Example: { tags: { $empty: true } }\n */\n $empty: boolean;\n};\n\ntype QdrantLogicalOperatorValueMap = Omit<LogicalOperatorValueMap, '$nor'>;\n\ntype QdrantBlacklistedRootOperators =\n | BlacklistedRootOperators\n | '$count'\n | '$geo'\n | '$nested'\n | '$datetime'\n | '$null'\n | '$empty';\n\nexport type QdrantVectorFilter = VectorFilter<\n keyof QdrantOperatorValueMap,\n QdrantOperatorValueMap,\n QdrantLogicalOperatorValueMap,\n QdrantBlacklistedRootOperators\n>;\n\n/**\n * Translates MongoDB-style filters to Qdrant compatible filters.\n *\n * Key transformations:\n * - $and -> must\n * - $or -> should\n * - $not -> must_not\n * - { field: { $op: value } } -> { key: field, match/range: { value/gt/lt: value } }\n *\n * Custom operators (Qdrant-specific):\n * - $count -> values_count (array length/value count)\n * - $geo -> geo filters (box, radius, polygon)\n * - $hasId -> has_id filter\n * - $nested -> nested object filters\n * - $hasVector -> vector existence check\n * - $datetime -> RFC 3339 datetime range\n * - $null -> is_null check\n * - $empty -> is_empty check\n */\nexport class QdrantFilterTranslator extends BaseFilterTranslator<QdrantVectorFilter> {\n protected override isLogicalOperator(key: string): key is LogicalOperator {\n return super.isLogicalOperator(key) || key === '$hasId' || key === '$hasVector';\n }\n\n protected override getSupportedOperators(): OperatorSupport {\n return {\n ...BaseFilterTranslator.DEFAULT_OPERATORS,\n logical: ['$and', '$or', '$not'],\n array: ['$in', '$nin'],\n regex: ['$regex'],\n custom: ['$count', '$geo', '$nested', '$datetime', '$null', '$empty', '$hasId', '$hasVector'],\n };\n }\n\n translate(filter?: QdrantVectorFilter): QdrantVectorFilter {\n if (this.isEmpty(filter)) return filter;\n this.validateFilter(filter);\n return this.translateNode(filter);\n }\n\n private createCondition(type: string, value: any, fieldKey?: string) {\n const condition = { [type]: value };\n return fieldKey ? { key: fieldKey, ...condition } : condition;\n }\n\n private translateNode(node: QdrantVectorFilter, isNested: boolean = false, fieldKey?: string): any {\n if (!this.isEmpty(node) && !!node && typeof node === 'object' && 'must' in node) {\n return node;\n }\n\n if (this.isPrimitive(node)) {\n if (node === null) {\n return { is_null: { key: fieldKey } };\n }\n return this.createCondition('match', { value: this.normalizeComparisonValue(node) }, fieldKey);\n }\n\n if (this.isRegex(node)) {\n throw new Error('Direct regex pattern format is not supported in Qdrant');\n }\n\n if (Array.isArray(node)) {\n return node.length === 0\n ? { is_empty: { key: fieldKey } }\n : this.createCondition('match', { any: this.normalizeArrayValues(node) }, fieldKey);\n }\n\n const entries = Object.entries(node as Record<string, any>);\n\n // Handle logical operators first\n const logicalResult = this.handleLogicalOperators(entries, isNested);\n if (logicalResult) {\n return logicalResult;\n }\n\n // Handle field conditions\n const { conditions, range, matchCondition } = this.handleFieldConditions(entries, fieldKey);\n\n if (Object.keys(range).length > 0) {\n conditions.push({ key: fieldKey, range });\n }\n\n if (matchCondition) {\n conditions.push({ key: fieldKey, match: matchCondition });\n }\n\n return this.buildFinalConditions(conditions, isNested);\n }\n\n private buildFinalConditions(conditions: any[], isNested: boolean): any {\n if (conditions.length === 0) {\n return {};\n } else if (conditions.length === 1 && isNested) {\n return conditions[0];\n } else {\n return { must: conditions };\n }\n }\n\n private handleLogicalOperators(entries: [string, any][], isNested: boolean): any | null {\n const firstKey = entries[0]?.[0];\n\n if (firstKey && this.isLogicalOperator(firstKey) && !this.isCustomOperator(firstKey)) {\n const [key, value] = entries[0]!;\n const qdrantOp = this.getQdrantLogicalOp(key);\n return {\n [qdrantOp]: Array.isArray(value)\n ? value.map(v => this.translateNode(v, true))\n : [this.translateNode(value, true)],\n };\n }\n\n if (\n entries.length > 1 &&\n !isNested &&\n entries.every(([key]) => !this.isOperator(key) && !this.isCustomOperator(key))\n ) {\n return {\n must: entries.map(([key, value]) => this.translateNode(value, true, key)),\n };\n }\n\n return null;\n }\n\n private handleFieldConditions(\n entries: [string, any][],\n fieldKey?: string,\n ): { conditions: any[]; range: Record<string, any>; matchCondition: Record<string, any> | null } {\n const conditions = [];\n let range: Record<string, any> = {};\n let matchCondition: Record<string, any> | null = null;\n\n for (const [key, value] of entries) {\n if (this.isCustomOperator(key)) {\n const customOp = this.translateCustomOperator(key, value, fieldKey);\n conditions.push(customOp);\n } else if (this.isOperator(key)) {\n const opResult = this.translateOperatorValue(key, value);\n if (opResult.range) {\n Object.assign(range, opResult.range);\n } else {\n matchCondition = opResult;\n }\n } else {\n const nestedKey = fieldKey ? `${fieldKey}.${key}` : key;\n const nestedCondition = this.translateNode(value, true, nestedKey);\n\n if (nestedCondition.must) {\n conditions.push(...nestedCondition.must);\n } else if (!this.isEmpty(nestedCondition)) {\n conditions.push(nestedCondition);\n }\n }\n }\n\n return { conditions, range, matchCondition };\n }\n\n private translateCustomOperator(op: string, value: any, fieldKey?: string): any {\n switch (op) {\n case '$count':\n const countConditions = Object.entries(value).reduce(\n (acc, [k, v]) => ({\n ...acc,\n [k.replace('$', '')]: v,\n }),\n {},\n );\n return { key: fieldKey, values_count: countConditions };\n case '$geo':\n const geoOp = this.translateGeoFilter(value.type, value);\n return { key: fieldKey, ...geoOp };\n case '$hasId':\n return { has_id: Array.isArray(value) ? value : [value] };\n case '$nested':\n return {\n nested: {\n key: fieldKey,\n filter: this.translateNode(value),\n },\n };\n case '$hasVector':\n return { has_vector: value };\n case '$datetime':\n return {\n key: fieldKey,\n range: this.normalizeDatetimeRange(value.range),\n };\n case '$null':\n return { is_null: { key: fieldKey } };\n case '$empty':\n return { is_empty: { key: fieldKey } };\n default:\n throw new Error(`Unsupported custom operator: ${op}`);\n }\n }\n\n private getQdrantLogicalOp(op: string): string {\n switch (op) {\n case '$and':\n return 'must';\n case '$or':\n return 'should';\n case '$not':\n return 'must_not';\n default:\n throw new Error(`Unsupported logical operator: ${op}`);\n }\n }\n\n private translateOperatorValue(operator: string, value: any): any {\n const normalizedValue = this.normalizeComparisonValue(value);\n\n switch (operator) {\n case '$eq':\n return { value: normalizedValue };\n case '$ne':\n return { except: [normalizedValue] };\n case '$gt':\n return { range: { gt: normalizedValue } };\n case '$gte':\n return { range: { gte: normalizedValue } };\n case '$lt':\n return { range: { lt: normalizedValue } };\n case '$lte':\n return { range: { lte: normalizedValue } };\n case '$in':\n return { any: this.normalizeArrayValues(value) };\n case '$nin':\n return { except: this.normalizeArrayValues(value) };\n case '$regex':\n return { text: value };\n case 'exists':\n return value\n ? {\n must_not: [{ is_null: { key: value } }, { is_empty: { key: value } }],\n }\n : {\n is_empty: { key: value },\n };\n default:\n throw new Error(`Unsupported operator: ${operator}`);\n }\n }\n\n private translateGeoFilter(type: string, value: any): any {\n switch (type) {\n case 'box':\n return {\n geo_bounding_box: {\n top_left: value.top_left,\n bottom_right: value.bottom_right,\n },\n };\n case 'radius':\n return {\n geo_radius: {\n center: value.center,\n radius: value.radius,\n },\n };\n case 'polygon':\n return {\n geo_polygon: {\n exterior: value.exterior,\n interiors: value.interiors,\n },\n };\n default:\n throw new Error(`Unsupported geo filter type: ${type}`);\n }\n }\n\n private normalizeDatetimeRange(value: any): any {\n const range: Record<string, string> = {};\n for (const [op, val] of Object.entries(value)) {\n if (val instanceof Date) {\n range[op] = val.toISOString();\n } else if (typeof val === 'string') {\n // Assume string is already in proper format\n range[op] = val;\n }\n }\n return range;\n }\n}\n","import { MastraError, ErrorDomain, ErrorCategory } from '@mastra/core/error';\nimport { MastraVector } from '@mastra/core/vector';\nimport type {\n QueryResult,\n IndexStats,\n CreateIndexParams,\n UpsertVectorParams,\n QueryVectorParams,\n DescribeIndexParams,\n DeleteIndexParams,\n DeleteVectorParams,\n UpdateVectorParams,\n} from '@mastra/core/vector';\nimport { QdrantClient } from '@qdrant/js-client-rest';\nimport type { QdrantClientParams, Schemas } from '@qdrant/js-client-rest';\n\nimport { QdrantFilterTranslator } from './filter';\nimport type { QdrantVectorFilter } from './filter';\n\nconst BATCH_SIZE = 256;\nconst DISTANCE_MAPPING: Record<string, Schemas['Distance']> = {\n cosine: 'Cosine',\n euclidean: 'Euclid',\n dotproduct: 'Dot',\n};\n\ntype QdrantQueryVectorParams = QueryVectorParams<QdrantVectorFilter>;\n\nexport class QdrantVector extends MastraVector {\n private client: QdrantClient;\n\n /**\n * Creates a new QdrantVector client.\n * @param id - The unique identifier for this vector store instance.\n * @param url - The URL of the Qdrant server.\n * @param apiKey - The API key for Qdrant.\n * @param https - Whether to use HTTPS.\n */\n constructor({ id, ...qdrantParams }: QdrantClientParams & { id: string }) {\n super({ id });\n this.client = new QdrantClient(qdrantParams);\n }\n\n async upsert({ indexName, vectors, metadata, ids }: UpsertVectorParams): Promise<string[]> {\n const pointIds = ids || vectors.map(() => crypto.randomUUID());\n\n const records = vectors.map((vector, i) => ({\n id: pointIds[i],\n vector: vector,\n payload: metadata?.[i] || {},\n }));\n\n try {\n for (let i = 0; i < records.length; i += BATCH_SIZE) {\n const batch = records.slice(i, i + BATCH_SIZE);\n await this.client.upsert(indexName, {\n // @ts-expect-error\n points: batch,\n wait: true,\n });\n }\n\n return pointIds;\n } catch (error) {\n throw new MastraError(\n {\n id: 'STORAGE_QDRANT_VECTOR_UPSERT_FAILED',\n domain: ErrorDomain.STORAGE,\n category: ErrorCategory.THIRD_PARTY,\n details: { indexName, vectorCount: vectors.length },\n },\n error,\n );\n }\n }\n\n async createIndex({ indexName, dimension, metric = 'cosine' }: CreateIndexParams): Promise<void> {\n try {\n if (!Number.isInteger(dimension) || dimension <= 0) {\n throw new Error('Dimension must be a positive integer');\n }\n if (!DISTANCE_MAPPING[metric]) {\n throw new Error(`Invalid metric: \"${metric}\". Must be one of: cosine, euclidean, dotproduct`);\n }\n } catch (validationError) {\n throw new MastraError(\n {\n id: 'STORAGE_QDRANT_VECTOR_CREATE_INDEX_INVALID_ARGS',\n domain: ErrorDomain.STORAGE,\n category: ErrorCategory.USER,\n details: { indexName, dimension, metric },\n },\n validationError,\n );\n }\n\n try {\n await this.client.createCollection(indexName, {\n vectors: {\n size: dimension,\n distance: DISTANCE_MAPPING[metric],\n },\n });\n } catch (error: any) {\n const message = error?.message || error?.toString();\n // Qdrant typically returns 409 for existing collection\n if (error?.status === 409 || (typeof message === 'string' && message.toLowerCase().includes('exists'))) {\n // Fetch collection info and check dimension\n await this.validateExistingIndex(indexName, dimension, metric);\n return;\n }\n\n throw new MastraError(\n {\n id: 'STORAGE_QDRANT_VECTOR_CREATE_INDEX_FAILED',\n domain: ErrorDomain.STORAGE,\n category: ErrorCategory.THIRD_PARTY,\n details: { indexName, dimension, metric },\n },\n error,\n );\n }\n }\n\n transformFilter(filter?: QdrantVectorFilter) {\n const translator = new QdrantFilterTranslator();\n return translator.translate(filter);\n }\n\n async query({\n indexName,\n queryVector,\n topK = 10,\n filter,\n includeVector = false,\n }: QdrantQueryVectorParams): Promise<QueryResult[]> {\n const translatedFilter = this.transformFilter(filter) ?? {};\n\n try {\n const results = (\n await this.client.query(indexName, {\n query: queryVector,\n limit: topK,\n filter: translatedFilter,\n with_payload: true,\n with_vector: includeVector,\n })\n ).points;\n\n return results.map(match => {\n let vector: number[] = [];\n if (includeVector) {\n if (Array.isArray(match.vector)) {\n // If it's already an array of numbers\n vector = match.vector as number[];\n } else if (typeof match.vector === 'object' && match.vector !== null) {\n // If it's an object with vector data\n vector = Object.values(match.vector).filter(v => typeof v === 'number');\n }\n }\n\n return {\n id: match.id as string,\n score: match.score || 0,\n metadata: match.payload as Record<string, any>,\n ...(includeVector && { vector }),\n };\n });\n } catch (error) {\n throw new MastraError(\n {\n id: 'STORAGE_QDRANT_VECTOR_QUERY_FAILED',\n domain: ErrorDomain.STORAGE,\n category: ErrorCategory.THIRD_PARTY,\n details: { indexName, topK },\n },\n error,\n );\n }\n }\n\n async listIndexes(): Promise<string[]> {\n try {\n const response = await this.client.getCollections();\n return response.collections.map(collection => collection.name) || [];\n } catch (error) {\n throw new MastraError(\n {\n id: 'STORAGE_QDRANT_VECTOR_LIST_INDEXES_FAILED',\n domain: ErrorDomain.STORAGE,\n category: ErrorCategory.THIRD_PARTY,\n },\n error,\n );\n }\n }\n\n /**\n * Retrieves statistics about a vector index.\n *\n * @param {string} indexName - The name of the index to describe\n * @returns A promise that resolves to the index statistics including dimension, count and metric\n */\n async describeIndex({ indexName }: DescribeIndexParams): Promise<IndexStats> {\n try {\n const { config, points_count } = await this.client.getCollection(indexName);\n\n const distance = config.params.vectors?.distance as Schemas['Distance'];\n return {\n dimension: config.params.vectors?.size as number,\n count: points_count || 0,\n // @ts-expect-error\n metric: Object.keys(DISTANCE_MAPPING).find(key => DISTANCE_MAPPING[key] === distance),\n };\n } catch (error) {\n throw new MastraError(\n {\n id: 'STORAGE_QDRANT_VECTOR_DESCRIBE_INDEX_FAILED',\n domain: ErrorDomain.STORAGE,\n category: ErrorCategory.THIRD_PARTY,\n details: { indexName },\n },\n error,\n );\n }\n }\n\n async deleteIndex({ indexName }: DeleteIndexParams): Promise<void> {\n try {\n await this.client.deleteCollection(indexName);\n } catch (error) {\n throw new MastraError(\n {\n id: 'STORAGE_QDRANT_VECTOR_DELETE_INDEX_FAILED',\n domain: ErrorDomain.STORAGE,\n category: ErrorCategory.THIRD_PARTY,\n details: { indexName },\n },\n error,\n );\n }\n }\n\n /**\n * Updates a vector by its ID with the provided vector and/or metadata.\n * @param indexName - The name of the index containing the vector.\n * @param id - The ID of the vector to update.\n * @param update - An object containing the vector and/or metadata to update.\n * @param update.vector - An optional array of numbers representing the new vector.\n * @param update.metadata - An optional record containing the new metadata.\n * @returns A promise that resolves when the update is complete.\n * @throws Will throw an error if no updates are provided or if the update operation fails.\n */\n async updateVector({ indexName, id, update }: UpdateVectorParams): Promise<void> {\n try {\n if (!update.vector && !update.metadata) {\n throw new Error('No updates provided');\n }\n } catch (validationError) {\n throw new MastraError(\n {\n id: 'STORAGE_QDRANT_VECTOR_UPDATE_VECTOR_INVALID_ARGS',\n domain: ErrorDomain.STORAGE,\n category: ErrorCategory.USER,\n details: { indexName, id },\n },\n validationError,\n );\n }\n\n const pointId = this.parsePointId(id);\n\n try {\n // Handle metadata-only update\n if (update.metadata && !update.vector) {\n // For metadata-only updates, use the setPayload method\n await this.client.setPayload(indexName, { payload: update.metadata, points: [pointId] });\n return;\n }\n\n // Handle vector-only update\n if (update.vector && !update.metadata) {\n await this.client.updateVectors(indexName, {\n points: [\n {\n id: pointId,\n vector: update.vector,\n },\n ],\n });\n return;\n }\n\n // Handle both vector and metadata update\n if (update.vector && update.metadata) {\n const point = {\n id: pointId,\n vector: update.vector,\n payload: update.metadata,\n };\n\n await this.client.upsert(indexName, {\n points: [point],\n });\n return;\n }\n } catch (error) {\n throw new MastraError(\n {\n id: 'STORAGE_QDRANT_VECTOR_UPDATE_VECTOR_FAILED',\n domain: ErrorDomain.STORAGE,\n category: ErrorCategory.THIRD_PARTY,\n details: { indexName, id },\n },\n error,\n );\n }\n }\n\n /**\n * Deletes a vector by its ID.\n * @param indexName - The name of the index containing the vector.\n * @param id - The ID of the vector to delete.\n * @returns A promise that resolves when the deletion is complete.\n * @throws Will throw an error if the deletion operation fails.\n */\n async deleteVector({ indexName, id }: DeleteVectorParams): Promise<void> {\n try {\n // Parse the ID - Qdrant supports both string and numeric IDs\n const pointId = this.parsePointId(id);\n\n // Use the Qdrant client to delete the point from the collection\n await this.client.delete(indexName, {\n points: [pointId],\n });\n } catch (error) {\n throw new MastraError(\n {\n id: 'STORAGE_QDRANT_VECTOR_DELETE_VECTOR_FAILED',\n domain: ErrorDomain.STORAGE,\n category: ErrorCategory.THIRD_PARTY,\n details: { indexName, id },\n },\n error,\n );\n }\n }\n\n /**\n * Parses and converts a string ID to the appropriate type (string or number) for Qdrant point operations.\n *\n * Qdrant supports both numeric and string IDs. This helper method ensures IDs are in the correct format\n * before sending them to the Qdrant client API.\n *\n * @param id - The ID string to parse\n * @returns The parsed ID as either a number (if string contains only digits) or the original string\n *\n * @example\n * // Numeric ID strings are converted to numbers\n * parsePointId(\"123\") => 123\n * parsePointId(\"42\") => 42\n * parsePointId(\"0\") => 0\n *\n * // String IDs containing any non-digit characters remain as strings\n * parsePointId(\"doc-123\") => \"doc-123\"\n * parsePointId(\"user_42\") => \"user_42\"\n * parsePointId(\"abc123\") => \"abc123\"\n * parsePointId(\"123abc\") => \"123abc\"\n * parsePointId(\"\") => \"\"\n * parsePointId(\"uuid-5678-xyz\") => \"uuid-5678-xyz\"\n *\n * @remarks\n * - This conversion is important because Qdrant treats numeric and string IDs differently\n * - Only positive integers are converted to numbers (negative numbers with minus signs remain strings)\n * - The method uses base-10 parsing, so leading zeros will be dropped in numeric conversions\n * - reference: https://qdrant.tech/documentation/concepts/points/?q=qdrant+point+id#point-ids\n */\n private parsePointId(id: string): string | number {\n // Try to parse as number if it looks like one\n if (/^\\d+$/.test(id)) {\n return parseInt(id, 10);\n }\n return id;\n }\n}\n","/**\n * Vector store specific prompt that details supported operators and examples.\n * This prompt helps users construct valid filters for Qdrant Vector.\n */\nexport const QDRANT_PROMPT = `When querying Qdrant, you can ONLY use the operators listed below. Any other operators will be rejected.\nImportant: Don't explain how to construct the filter - use the specified operators and fields to search the content and return relevant results.\nIf a user tries to give an explicit operator that is not supported, reject the filter entirely and let them know that the operator is not supported.\n\nBasic Comparison Operators:\n- $eq: Exact match (default when using field: value)\n Example: { \"category\": \"electronics\" }\n- $ne: Not equal\n Example: { \"category\": { \"$ne\": \"electronics\" } }\n- $gt: Greater than\n Example: { \"price\": { \"$gt\": 100 } }\n- $gte: Greater than or equal\n Example: { \"price\": { \"$gte\": 100 } }\n- $lt: Less than\n Example: { \"price\": { \"$lt\": 100 } }\n- $lte: Less than or equal\n Example: { \"price\": { \"$lte\": 100 } }\n\nArray Operators:\n- $in: Match any value in array\n Example: { \"category\": { \"$in\": [\"electronics\", \"books\"] } }\n- $nin: Does not match any value in array\n Example: { \"category\": { \"$nin\": [\"electronics\", \"books\"] } }\n\nLogical Operators:\n- $and: Logical AND (can be implicit or explicit)\n Implicit Example: { \"price\": { \"$gt\": 100 }, \"category\": \"electronics\" }\n Explicit Example: { \"$and\": [{ \"price\": { \"$gt\": 100 } }, { \"category\": \"electronics\" }] }\n- $or: Logical OR\n Example: { \"$or\": [{ \"price\": { \"$lt\": 50 } }, { \"category\": \"books\" }] }\n- $not: Logical NOT\n Example: { \"$not\": { \"category\": \"electronics\" } }\n\nElement Operators:\n- $exists: Check if field exists\n Example: { \"rating\": { \"$exists\": true } }\n- $match: Match text using full-text search\n Example: { \"description\": { \"$match\": \"gaming laptop\" } }\n- $null: Check if field is null\n Example: { \"rating\": { \"$null\": true } }\n\nRestrictions:\n- Regex patterns are not supported\n- Only $and, $or, and $not logical operators are supported at the top level\n- Empty arrays in $in/$nin will return no results\n- Nested fields are supported using dot notation\n- Multiple conditions on the same field are supported with both implicit and explicit $and\n- At least one key-value pair is required in filter object\n- Empty objects and undefined values are treated as no filter\n- Invalid types in comparison operators will throw errors\n- All non-logical operators must be used within a field condition\n Valid: { \"field\": { \"$gt\": 100 } }\n Valid: { \"$and\": [...] }\n Invalid: { \"$gt\": 100 }\n- Logical operators must contain field conditions, not direct operators\n Valid: { \"$and\": [{ \"field\": { \"$gt\": 100 } }] }\n Invalid: { \"$and\": [{ \"$gt\": 100 }] }\n- Logical operators ($and, $or, $not):\n - Can only be used at top level or nested within other logical operators\n - Can not be used on a field level, or be nested inside a field\n - Can not be used inside an operator\n - Valid: { \"$and\": [{ \"field\": { \"$gt\": 100 } }] }\n - Valid: { \"$or\": [{ \"$and\": [{ \"field\": { \"$gt\": 100 } }] }] }\n - Invalid: { \"field\": { \"$and\": [{ \"$gt\": 100 }] } }\n - Invalid: { \"field\": { \"$or\": [{ \"$gt\": 100 }] } }\n - Invalid: { \"field\": { \"$gt\": { \"$and\": [{...}] } } }\n\nExample Complex Query:\n{\n \"$and\": [\n { \"category\": { \"$in\": [\"electronics\", \"computers\"] } },\n { \"price\": { \"$gte\": 100, \"$lte\": 1000 } },\n { \"description\": { \"$match\": \"gaming laptop\" } },\n { \"rating\": { \"$exists\": true, \"$gt\": 4 } },\n { \"$or\": [\n { \"stock\": { \"$gt\": 0 } },\n { \"preorder\": { \"$null\": false } }\n ]},\n { \"$not\": { \"status\": \"discontinued\" } }\n ]\n}`;\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/vector/filter.ts","../src/vector/index.ts","../src/vector/prompt.ts"],"names":["BaseFilterTranslator","MastraVector","QdrantClient","error","MastraError","ErrorDomain","ErrorCategory"],"mappings":";;;;;;;;AAwHO,IAAM,sBAAA,GAAN,cAAqCA,2BAAA,CAAyC;AAAA,EAChE,kBAAkB,GAAA,EAAqC;AACxE,IAAA,OAAO,MAAM,iBAAA,CAAkB,GAAG,CAAA,IAAK,GAAA,KAAQ,YAAY,GAAA,KAAQ,YAAA;AAAA,EACrE;AAAA,EAEmB,qBAAA,GAAyC;AAC1D,IAAA,OAAO;AAAA,MACL,GAAGA,2BAAA,CAAqB,iBAAA;AAAA,MACxB,OAAA,EAAS,CAAC,MAAA,EAAQ,KAAA,EAAO,MAAM,CAAA;AAAA,MAC/B,KAAA,EAAO,CAAC,KAAA,EAAO,MAAM,CAAA;AAAA,MACrB,KAAA,EAAO,CAAC,QAAQ,CAAA;AAAA,MAChB,MAAA,EAAQ,CAAC,QAAA,EAAU,MAAA,EAAQ,WAAW,WAAA,EAAa,OAAA,EAAS,QAAA,EAAU,QAAA,EAAU,YAAY;AAAA,KAC9F;AAAA,EACF;AAAA,EAEA,UAAU,MAAA,EAAiD;AACzD,IAAA,IAAI,IAAA,CAAK,OAAA,CAAQ,MAAM,CAAA,EAAG,OAAO,MAAA;AACjC,IAAA,IAAA,CAAK,eAAe,MAAM,CAAA;AAC1B,IAAA,OAAO,IAAA,CAAK,cAAc,MAAM,CAAA;AAAA,EAClC;AAAA,EAEQ,eAAA,CAAgB,IAAA,EAAc,KAAA,EAAY,QAAA,EAAmB;AACnE,IAAA,MAAM,SAAA,GAAY,EAAE,C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AA;AAAA,UACpB,UAAUC,mBAAA,CAAc,WAAA;AAAA,UACxB,OAAA,EAAS;AAAA,YACP,SAAA;AAAA,YACA,GAAI,MAAA,IAAU,EAAE,QAAQ,IAAA,CAAK,SAAA,CAAU,MAAM,CAAA,EAAE;AAAA,YAC/C,GAAI,GAAA,IAAO,EAAE,QAAA,EAAU,IAAI,MAAA;AAAO;AACpC,SACF;AAAA,QACAH;AAAA,OACF;AAAA,IACF;AAAA,EACF;AACF;;;AC5kBO,IAAM,aAAA,GAAgB,CAAA;AAAA;AAAA;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;AAAA;AAAA;AAAA;AAAA;AAAA;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,CAAA","file":"index.cjs","sourcesContent":["import { BaseFilterTranslator } from '@mastra/core/vector/filter';\nimport type {\n VectorFilter,\n LogicalOperator,\n OperatorSupport,\n OperatorValueMap,\n LogicalOperatorValueMap,\n BlacklistedRootOperators,\n} from '@mastra/core/vector/filter';\n\ntype QdrantOperatorValueMap = Omit<OperatorValueMap, '$options' | '$elemMatch' | '$all'> & {\n /**\n * $count: Filter by array length or value count.\n * Example: { tags: { $count: { gt: 2 } } }\n */\n $count: {\n $gt?: number;\n $gte?: number;\n $lt?: number;\n $lte?: number;\n $eq?: number;\n };\n\n /**\n * $geo: Geospatial filter.\n * Example: { location: { $geo: { type: 'geo_radius', center: [lon, lat], radius: 1000 } } }\n */\n $geo: {\n type: string;\n [key: string]: any;\n };\n\n /**\n * $hasId: Filter by point IDs.\n * Allowed at root level.\n * Example: { $hasId: '123' } or { $hasId: ['123', '456'] }\n */\n $hasId: string | string[];\n\n /**\n * $nested: Nested object filter.\n * Example: { metadata: { $nested: { key: 'foo', filter: { $eq: 'bar' } } } }\n */\n $nested: {\n // Additional properties depend on the nested object structure\n [key: string]: any;\n };\n\n /**\n * $hasVector: Filter by vector existence or field.\n * Allowed at root level.\n * Example: { $hasVector: true } or { $hasVector: 'vector_field' }\n */\n $hasVector: boolean | string;\n\n /**\n * $datetime: RFC 3339 datetime range.\n * Example: { createdAt: { $datetime: { gte: '2024-01-01T00:00:00Z' } } }\n */\n $datetime: {\n key?: string;\n range?: {\n gt?: Date | string;\n gte?: Date | string;\n lt?: Date | string;\n lte?: Date | string;\n eq?: Date | string;\n };\n };\n\n /**\n * $null: Check if a field is null.\n * Example: { metadata: { $null: true } }\n */\n $null: boolean;\n\n /**\n * $empty: Check if an array or object field is empty.\n * Example: { tags: { $empty: true } }\n */\n $empty: boolean;\n};\n\ntype QdrantLogicalOperatorValueMap = Omit<LogicalOperatorValueMap, '$nor'>;\n\ntype QdrantBlacklistedRootOperators =\n | BlacklistedRootOperators\n | '$count'\n | '$geo'\n | '$nested'\n | '$datetime'\n | '$null'\n | '$empty';\n\nexport type QdrantVectorFilter = VectorFilter<\n keyof QdrantOperatorValueMap,\n QdrantOperatorValueMap,\n QdrantLogicalOperatorValueMap,\n QdrantBlacklistedRootOperators\n>;\n\n/**\n * Translates MongoDB-style filters to Qdrant compatible filters.\n *\n * Key transformations:\n * - $and -> must\n * - $or -> should\n * - $not -> must_not\n * - { field: { $op: value } } -> { key: field, match/range: { value/gt/lt: value } }\n *\n * Custom operators (Qdrant-specific):\n * - $count -> values_count (array length/value count)\n * - $geo -> geo filters (box, radius, polygon)\n * - $hasId -> has_id filter\n * - $nested -> nested object filters\n * - $hasVector -> vector existence check\n * - $datetime -> RFC 3339 datetime range\n * - $null -> is_null check\n * - $empty -> is_empty check\n */\nexport class QdrantFilterTranslator extends BaseFilterTranslator<QdrantVectorFilter> {\n protected override isLogicalOperator(key: string): key is LogicalOperator {\n return super.isLogicalOperator(key) || key === '$hasId' || key === '$hasVector';\n }\n\n protected override getSupportedOperators(): OperatorSupport {\n return {\n ...BaseFilterTranslator.DEFAULT_OPERATORS,\n logical: ['$and', '$or', '$not'],\n array: ['$in', '$nin'],\n regex: ['$regex'],\n custom: ['$count', '$geo', '$nested', '$datetime', '$null', '$empty', '$hasId', '$hasVector'],\n };\n }\n\n translate(filter?: QdrantVectorFilter): QdrantVectorFilter {\n if (this.isEmpty(filter)) return filter;\n this.validateFilter(filter);\n return this.translateNode(filter);\n }\n\n private createCondition(type: string, value: any, fieldKey?: string) {\n const condition = { [type]: value };\n return fieldKey ? { key: fieldKey, ...condition } : condition;\n }\n\n private translateNode(node: QdrantVectorFilter, isNested: boolean = false, fieldKey?: string): any {\n if (!this.isEmpty(node) && !!node && typeof node === 'object' && 'must' in node) {\n return node;\n }\n\n if (this.isPrimitive(node)) {\n if (node === null) {\n return { is_null: { key: fieldKey } };\n }\n return this.createCondition('match', { value: this.normalizeComparisonValue(node) }, fieldKey);\n }\n\n if (this.isRegex(node)) {\n throw new Error('Direct regex pattern format is not supported in Qdrant');\n }\n\n if (Array.isArray(node)) {\n return node.length === 0\n ? { is_empty: { key: fieldKey } }\n : this.createCondition('match', { any: this.normalizeArrayValues(node) }, fieldKey);\n }\n\n const entries = Object.entries(node as Record<string, any>);\n\n // Handle logical operators first\n const logicalResult = this.handleLogicalOperators(entries, isNested);\n if (logicalResult) {\n return logicalResult;\n }\n\n // Handle field conditions\n const { conditions, range, matchCondition } = this.handleFieldConditions(entries, fieldKey);\n\n if (Object.keys(range).length > 0) {\n conditions.push({ key: fieldKey, range });\n }\n\n if (matchCondition) {\n conditions.push({ key: fieldKey, match: matchCondition });\n }\n\n return this.buildFinalConditions(conditions, isNested);\n }\n\n private buildFinalConditions(conditions: any[], isNested: boolean): any {\n if (conditions.length === 0) {\n return {};\n } else if (conditions.length === 1 && isNested) {\n return conditions[0];\n } else {\n return { must: conditions };\n }\n }\n\n private handleLogicalOperators(entries: [string, any][], isNested: boolean): any | null {\n const firstKey = entries[0]?.[0];\n\n if (firstKey && this.isLogicalOperator(firstKey) && !this.isCustomOperator(firstKey)) {\n const [key, value] = entries[0]!;\n const qdrantOp = this.getQdrantLogicalOp(key);\n return {\n [qdrantOp]: Array.isArray(value)\n ? value.map(v => this.translateNode(v, true))\n : [this.translateNode(value, true)],\n };\n }\n\n if (\n entries.length > 1 &&\n !isNested &&\n entries.every(([key]) => !this.isOperator(key) && !this.isCustomOperator(key))\n ) {\n return {\n must: entries.map(([key, value]) => this.translateNode(value, true, key)),\n };\n }\n\n return null;\n }\n\n private handleFieldConditions(\n entries: [string, any][],\n fieldKey?: string,\n ): { conditions: any[]; range: Record<string, any>; matchCondition: Record<string, any> | null } {\n const conditions = [];\n let range: Record<string, any> = {};\n let matchCondition: Record<string, any> | null = null;\n\n for (const [key, value] of entries) {\n if (this.isCustomOperator(key)) {\n const customOp = this.translateCustomOperator(key, value, fieldKey);\n conditions.push(customOp);\n } else if (this.isOperator(key)) {\n const opResult = this.translateOperatorValue(key, value);\n if (opResult.range) {\n Object.assign(range, opResult.range);\n } else {\n matchCondition = opResult;\n }\n } else {\n const nestedKey = fieldKey ? `${fieldKey}.${key}` : key;\n const nestedCondition = this.translateNode(value, true, nestedKey);\n\n if (nestedCondition.must) {\n conditions.push(...nestedCondition.must);\n } else if (!this.isEmpty(nestedCondition)) {\n conditions.push(nestedCondition);\n }\n }\n }\n\n return { conditions, range, matchCondition };\n }\n\n private translateCustomOperator(op: string, value: any, fieldKey?: string): any {\n switch (op) {\n case '$count':\n const countConditions = Object.entries(value).reduce(\n (acc, [k, v]) => ({\n ...acc,\n [k.replace('$', '')]: v,\n }),\n {},\n );\n return { key: fieldKey, values_count: countConditions };\n case '$geo':\n const geoOp = this.translateGeoFilter(value.type, value);\n return { key: fieldKey, ...geoOp };\n case '$hasId':\n return { has_id: Array.isArray(value) ? value : [value] };\n case '$nested':\n return {\n nested: {\n key: fieldKey,\n filter: this.translateNode(value),\n },\n };\n case '$hasVector':\n return { has_vector: value };\n case '$datetime':\n return {\n key: fieldKey,\n range: this.normalizeDatetimeRange(value.range),\n };\n case '$null':\n return { is_null: { key: fieldKey } };\n case '$empty':\n return { is_empty: { key: fieldKey } };\n default:\n throw new Error(`Unsupported custom operator: ${op}`);\n }\n }\n\n private getQdrantLogicalOp(op: string): string {\n switch (op) {\n case '$and':\n return 'must';\n case '$or':\n return 'should';\n case '$not':\n return 'must_not';\n default:\n throw new Error(`Unsupported logical operator: ${op}`);\n }\n }\n\n private translateOperatorValue(operator: string, value: any): any {\n const normalizedValue = this.normalizeComparisonValue(value);\n\n switch (operator) {\n case '$eq':\n return { value: normalizedValue };\n case '$ne':\n return { except: [normalizedValue] };\n case '$gt':\n return { range: { gt: normalizedValue } };\n case '$gte':\n return { range: { gte: normalizedValue } };\n case '$lt':\n return { range: { lt: normalizedValue } };\n case '$lte':\n return { range: { lte: normalizedValue } };\n case '$in':\n return { any: this.normalizeArrayValues(value) };\n case '$nin':\n return { except: this.normalizeArrayValues(value) };\n case '$regex':\n return { text: value };\n case 'exists':\n return value\n ? {\n must_not: [{ is_null: { key: value } }, { is_empty: { key: value } }],\n }\n : {\n is_empty: { key: value },\n };\n default:\n throw new Error(`Unsupported operator: ${operator}`);\n }\n }\n\n private translateGeoFilter(type: string, value: any): any {\n switch (type) {\n case 'box':\n return {\n geo_bounding_box: {\n top_left: value.top_left,\n bottom_right: value.bottom_right,\n },\n };\n case 'radius':\n return {\n geo_radius: {\n center: value.center,\n radius: value.radius,\n },\n };\n case 'polygon':\n return {\n geo_polygon: {\n exterior: value.exterior,\n interiors: value.interiors,\n },\n };\n default:\n throw new Error(`Unsupported geo filter type: ${type}`);\n }\n }\n\n private normalizeDatetimeRange(value: any): any {\n const range: Record<string, string> = {};\n for (const [op, val] of Object.entries(value)) {\n if (val instanceof Date) {\n range[op] = val.toISOString();\n } else if (typeof val === 'string') {\n // Assume string is already in proper format\n range[op] = val;\n }\n }\n return range;\n }\n}\n","import { MastraError, ErrorDomain, ErrorCategory } from '@mastra/core/error';\nimport { MastraVector } from '@mastra/core/vector';\nimport type {\n QueryResult,\n IndexStats,\n CreateIndexParams,\n UpsertVectorParams,\n QueryVectorParams,\n DescribeIndexParams,\n DeleteIndexParams,\n DeleteVectorParams,\n UpdateVectorParams,\n DeleteVectorsParams,\n} from '@mastra/core/vector';\nimport { QdrantClient } from '@qdrant/js-client-rest';\nimport type { QdrantClientParams, Schemas } from '@qdrant/js-client-rest';\n\nimport { QdrantFilterTranslator } from './filter';\nimport type { QdrantVectorFilter } from './filter';\n\nconst BATCH_SIZE = 256;\nconst DISTANCE_MAPPING: Record<string, Schemas['Distance']> = {\n cosine: 'Cosine',\n euclidean: 'Euclid',\n dotproduct: 'Dot',\n};\n\ntype QdrantQueryVectorParams = QueryVectorParams<QdrantVectorFilter>;\n\nexport class QdrantVector extends MastraVector {\n private client: QdrantClient;\n\n /**\n * Creates a new QdrantVector client.\n * @param id - The unique identifier for this vector store instance.\n * @param url - The URL of the Qdrant server.\n * @param apiKey - The API key for Qdrant.\n * @param https - Whether to use HTTPS.\n */\n constructor({ id, ...qdrantParams }: QdrantClientParams & { id: string }) {\n super({ id });\n this.client = new QdrantClient(qdrantParams);\n }\n\n async upsert({ indexName, vectors, metadata, ids }: UpsertVectorParams): Promise<string[]> {\n const pointIds = ids || vectors.map(() => crypto.randomUUID());\n\n const records = vectors.map((vector, i) => ({\n id: pointIds[i],\n vector: vector,\n payload: metadata?.[i] || {},\n }));\n\n try {\n for (let i = 0; i < records.length; i += BATCH_SIZE) {\n const batch = records.slice(i, i + BATCH_SIZE);\n await this.client.upsert(indexName, {\n // @ts-expect-error\n points: batch,\n wait: true,\n });\n }\n\n return pointIds;\n } catch (error) {\n throw new MastraError(\n {\n id: 'STORAGE_QDRANT_VECTOR_UPSERT_FAILED',\n domain: ErrorDomain.STORAGE,\n category: ErrorCategory.THIRD_PARTY,\n details: { indexName, vectorCount: vectors.length },\n },\n error,\n );\n }\n }\n\n async createIndex({ indexName, dimension, metric = 'cosine' }: CreateIndexParams): Promise<void> {\n try {\n if (!Number.isInteger(dimension) || dimension <= 0) {\n throw new Error('Dimension must be a positive integer');\n }\n if (!DISTANCE_MAPPING[metric]) {\n throw new Error(`Invalid metric: \"${metric}\". Must be one of: cosine, euclidean, dotproduct`);\n }\n } catch (validationError) {\n throw new MastraError(\n {\n id: 'STORAGE_QDRANT_VECTOR_CREATE_INDEX_INVALID_ARGS',\n domain: ErrorDomain.STORAGE,\n category: ErrorCategory.USER,\n details: { indexName, dimension, metric },\n },\n validationError,\n );\n }\n\n try {\n await this.client.createCollection(indexName, {\n vectors: {\n size: dimension,\n distance: DISTANCE_MAPPING[metric],\n },\n });\n } catch (error: any) {\n const message = error?.message || error?.toString();\n // Qdrant typically returns 409 for existing collection\n if (error?.status === 409 || (typeof message === 'string' && message.toLowerCase().includes('exists'))) {\n // Fetch collection info and check dimension\n await this.validateExistingIndex(indexName, dimension, metric);\n return;\n }\n\n throw new MastraError(\n {\n id: 'STORAGE_QDRANT_VECTOR_CREATE_INDEX_FAILED',\n domain: ErrorDomain.STORAGE,\n category: ErrorCategory.THIRD_PARTY,\n details: { indexName, dimension, metric },\n },\n error,\n );\n }\n }\n\n transformFilter(filter?: QdrantVectorFilter) {\n const translator = new QdrantFilterTranslator();\n return translator.translate(filter);\n }\n\n async query({\n indexName,\n queryVector,\n topK = 10,\n filter,\n includeVector = false,\n }: QdrantQueryVectorParams): Promise<QueryResult[]> {\n const translatedFilter = this.transformFilter(filter) ?? {};\n\n try {\n const results = (\n await this.client.query(indexName, {\n query: queryVector,\n limit: topK,\n filter: translatedFilter,\n with_payload: true,\n with_vector: includeVector,\n })\n ).points;\n\n return results.map(match => {\n let vector: number[] = [];\n if (includeVector) {\n if (Array.isArray(match.vector)) {\n // If it's already an array of numbers\n vector = match.vector as number[];\n } else if (typeof match.vector === 'object' && match.vector !== null) {\n // If it's an object with vector data\n vector = Object.values(match.vector).filter(v => typeof v === 'number');\n }\n }\n\n return {\n id: match.id as string,\n score: match.score || 0,\n metadata: match.payload as Record<string, any>,\n ...(includeVector && { vector }),\n };\n });\n } catch (error) {\n throw new MastraError(\n {\n id: 'STORAGE_QDRANT_VECTOR_QUERY_FAILED',\n domain: ErrorDomain.STORAGE,\n category: ErrorCategory.THIRD_PARTY,\n details: { indexName, topK },\n },\n error,\n );\n }\n }\n\n async listIndexes(): Promise<string[]> {\n try {\n const response = await this.client.getCollections();\n return response.collections.map(collection => collection.name) || [];\n } catch (error) {\n throw new MastraError(\n {\n id: 'STORAGE_QDRANT_VECTOR_LIST_INDEXES_FAILED',\n domain: ErrorDomain.STORAGE,\n category: ErrorCategory.THIRD_PARTY,\n },\n error,\n );\n }\n }\n\n /**\n * Retrieves statistics about a vector index.\n *\n * @param {string} indexName - The name of the index to describe\n * @returns A promise that resolves to the index statistics including dimension, count and metric\n */\n async describeIndex({ indexName }: DescribeIndexParams): Promise<IndexStats> {\n try {\n const { config, points_count } = await this.client.getCollection(indexName);\n\n const distance = config.params.vectors?.distance as Schemas['Distance'];\n return {\n dimension: config.params.vectors?.size as number,\n count: points_count || 0,\n // @ts-expect-error\n metric: Object.keys(DISTANCE_MAPPING).find(key => DISTANCE_MAPPING[key] === distance),\n };\n } catch (error) {\n throw new MastraError(\n {\n id: 'STORAGE_QDRANT_VECTOR_DESCRIBE_INDEX_FAILED',\n domain: ErrorDomain.STORAGE,\n category: ErrorCategory.THIRD_PARTY,\n details: { indexName },\n },\n error,\n );\n }\n }\n\n async deleteIndex({ indexName }: DeleteIndexParams): Promise<void> {\n try {\n await this.client.deleteCollection(indexName);\n } catch (error: any) {\n // If the collection doesn't exist, treat it as a no-op (already deleted)\n const errorMessage = error?.message || error?.toString() || '';\n if (\n error?.status === 404 ||\n errorMessage.toLowerCase().includes('not found') ||\n errorMessage.toLowerCase().includes('not exist')\n ) {\n this.logger.info(`Collection ${indexName} does not exist, treating as already deleted`);\n return;\n }\n throw new MastraError(\n {\n id: 'STORAGE_QDRANT_VECTOR_DELETE_INDEX_FAILED',\n domain: ErrorDomain.STORAGE,\n category: ErrorCategory.THIRD_PARTY,\n details: { indexName },\n },\n error,\n );\n }\n }\n\n /**\n * Updates a vector by its ID or multiple vectors matching a filter.\n * @param indexName - The name of the index containing the vector(s).\n * @param id - The ID of the vector to update (mutually exclusive with filter).\n * @param filter - Filter to match multiple vectors to update (mutually exclusive with id).\n * @param update - An object containing the vector and/or metadata to update.\n * @param update.vector - An optional array of numbers representing the new vector.\n * @param update.metadata - An optional record containing the new metadata.\n * @returns A promise that resolves when the update is complete.\n * @throws Will throw an error if no updates are provided or if the update operation fails.\n */\n async updateVector({ indexName, id, filter, update }: UpdateVectorParams<QdrantVectorFilter>): Promise<void> {\n // Validate mutually exclusive parameters\n if (id && filter) {\n throw new MastraError({\n id: 'STORAGE_QDRANT_VECTOR_UPDATE_MUTUALLY_EXCLUSIVE',\n text: 'Cannot specify both id and filter - they are mutually exclusive',\n domain: ErrorDomain.STORAGE,\n category: ErrorCategory.USER,\n details: { indexName },\n });\n }\n\n if (!id && !filter) {\n throw new MastraError({\n id: 'STORAGE_QDRANT_VECTOR_UPDATE_NO_TARGET',\n text: 'Either id or filter must be provided',\n domain: ErrorDomain.STORAGE,\n category: ErrorCategory.USER,\n details: { indexName },\n });\n }\n\n if (!update.vector && !update.metadata) {\n throw new MastraError({\n id: 'STORAGE_QDRANT_VECTOR_UPDATE_NO_PAYLOAD',\n text: 'No updates provided',\n domain: ErrorDomain.STORAGE,\n category: ErrorCategory.USER,\n details: {\n indexName,\n ...(id && { id }),\n },\n });\n }\n\n // Validate filter is not empty\n if (filter && Object.keys(filter).length === 0) {\n throw new MastraError({\n id: 'STORAGE_QDRANT_VECTOR_UPDATE_EMPTY_FILTER',\n text: 'Filter cannot be an empty filter object',\n domain: ErrorDomain.STORAGE,\n category: ErrorCategory.USER,\n details: { indexName },\n });\n }\n\n try {\n if (id) {\n // Update single vector by ID\n const pointId = this.parsePointId(id);\n\n // Handle metadata-only update\n if (update.metadata && !update.vector) {\n await this.client.setPayload(indexName, { payload: update.metadata, points: [pointId] });\n return;\n }\n\n // Handle vector-only update\n if (update.vector && !update.metadata) {\n await this.client.updateVectors(indexName, {\n points: [\n {\n id: pointId,\n vector: update.vector,\n },\n ],\n });\n return;\n }\n\n // Handle both vector and metadata update\n if (update.vector && update.metadata) {\n const point = {\n id: pointId,\n vector: update.vector,\n payload: update.metadata,\n };\n\n await this.client.upsert(indexName, {\n points: [point],\n });\n return;\n }\n } else if (filter) {\n // Update multiple vectors matching filter\n const translatedFilter = this.transformFilter(filter);\n\n // First, scroll through all matching points to get their IDs\n const matchingPoints: Array<{ id: string | number; vector?: number[] }> = [];\n let offset: string | number | undefined = undefined;\n\n do {\n const scrollResult = await this.client.scroll(indexName, {\n filter: translatedFilter,\n limit: 100,\n offset,\n with_payload: false,\n with_vector: update.vector ? false : true, // Only fetch vectors if not updating them\n });\n\n matchingPoints.push(\n ...scrollResult.points.map(point => ({\n id: point.id,\n vector: Array.isArray(point.vector) ? (point.vector as number[]) : undefined,\n })),\n );\n\n const nextOffset = scrollResult.next_page_offset;\n offset = typeof nextOffset === 'string' || typeof nextOffset === 'number' ? nextOffset : undefined;\n } while (offset !== undefined);\n\n if (matchingPoints.length === 0) {\n // No vectors to update - this is not an error\n return;\n }\n\n const pointIds = matchingPoints.map(p => p.id);\n\n // Handle metadata-only update\n if (update.metadata && !update.vector) {\n await this.client.setPayload(indexName, { payload: update.metadata, points: pointIds });\n return;\n }\n\n // Handle vector-only or both updates\n if (update.vector) {\n // For vector updates with filter, we need to upsert each point\n const points = matchingPoints.map(p => ({\n id: p.id,\n vector: update.vector!,\n payload: update.metadata || {},\n }));\n\n // Batch upsert\n for (let i = 0; i < points.length; i += BATCH_SIZE) {\n const batch = points.slice(i, i + BATCH_SIZE);\n await this.client.upsert(indexName, {\n points: batch,\n wait: true,\n });\n }\n return;\n }\n }\n } catch (error) {\n if (error instanceof MastraError) throw error;\n throw new MastraError(\n {\n id: 'STORAGE_QDRANT_VECTOR_UPDATE_VECTOR_FAILED',\n domain: ErrorDomain.STORAGE,\n category: ErrorCategory.THIRD_PARTY,\n details: {\n indexName,\n ...(id && { id }),\n ...(filter && { filter: JSON.stringify(filter) }),\n },\n },\n error,\n );\n }\n }\n\n /**\n * Deletes a vector by its ID.\n * @param indexName - The name of the index containing the vector.\n * @param id - The ID of the vector to delete.\n * @returns A promise that resolves when the deletion is complete.\n * @throws Will throw an error if the deletion operation fails.\n */\n async deleteVector({ indexName, id }: DeleteVectorParams): Promise<void> {\n try {\n // Parse the ID - Qdrant supports both string and numeric IDs\n const pointId = this.parsePointId(id);\n\n // Use the Qdrant client to delete the point from the collection\n await this.client.delete(indexName, {\n points: [pointId],\n });\n } catch (error) {\n throw new MastraError(\n {\n id: 'STORAGE_QDRANT_VECTOR_DELETE_VECTOR_FAILED',\n domain: ErrorDomain.STORAGE,\n category: ErrorCategory.THIRD_PARTY,\n details: {\n indexName,\n ...(id && { id }),\n },\n },\n error,\n );\n }\n }\n\n /**\n * Parses and converts a string ID to the appropriate type (string or number) for Qdrant point operations.\n *\n * Qdrant supports both numeric and string IDs. This helper method ensures IDs are in the correct format\n * before sending them to the Qdrant client API.\n *\n * @param id - The ID string to parse\n * @returns The parsed ID as either a number (if string contains only digits) or the original string\n *\n * @example\n * // Numeric ID strings are converted to numbers\n * parsePointId(\"123\") => 123\n * parsePointId(\"42\") => 42\n * parsePointId(\"0\") => 0\n *\n * // String IDs containing any non-digit characters remain as strings\n * parsePointId(\"doc-123\") => \"doc-123\"\n * parsePointId(\"user_42\") => \"user_42\"\n * parsePointId(\"abc123\") => \"abc123\"\n * parsePointId(\"123abc\") => \"123abc\"\n * parsePointId(\"\") => \"\"\n * parsePointId(\"uuid-5678-xyz\") => \"uuid-5678-xyz\"\n *\n * @remarks\n * - This conversion is important because Qdrant treats numeric and string IDs differently\n * - Only positive integers are converted to numbers (negative numbers with minus signs remain strings)\n * - The method uses base-10 parsing, so leading zeros will be dropped in numeric conversions\n * - reference: https://qdrant.tech/documentation/concepts/points/?q=qdrant+point+id#point-ids\n */\n private parsePointId(id: string): string | number {\n // Try to parse as number if it looks like one\n if (/^\\d+$/.test(id)) {\n return parseInt(id, 10);\n }\n return id;\n }\n\n /**\n * Deletes multiple vectors by IDs or filter.\n * @param indexName - The name of the index containing the vectors.\n * @param ids - Array of vector IDs to delete (mutually exclusive with filter).\n * @param filter - Filter to match vectors to delete (mutually exclusive with ids).\n * @returns A promise that resolves when the deletion is complete.\n * @throws Will throw an error if both ids and filter are provided, or if neither is provided.\n */\n async deleteVectors({ indexName, filter, ids }: DeleteVectorsParams<QdrantVectorFilter>): Promise<void> {\n // Validate mutually exclusive parameters\n if (ids && filter) {\n throw new MastraError({\n id: 'STORAGE_QDRANT_VECTOR_DELETE_VECTORS_MUTUALLY_EXCLUSIVE',\n text: 'Cannot specify both ids and filter - they are mutually exclusive',\n domain: ErrorDomain.STORAGE,\n category: ErrorCategory.USER,\n details: { indexName },\n });\n }\n\n if (!ids && !filter) {\n throw new MastraError({\n id: 'STORAGE_QDRANT_VECTOR_DELETE_VECTORS_NO_TARGET',\n text: 'Either filter or ids must be provided',\n domain: ErrorDomain.STORAGE,\n category: ErrorCategory.USER,\n details: { indexName },\n });\n }\n\n // Validate ids array is not empty\n if (ids && ids.length === 0) {\n throw new MastraError({\n id: 'STORAGE_QDRANT_VECTOR_DELETE_VECTORS_EMPTY_IDS',\n text: 'Cannot delete with empty ids array',\n domain: ErrorDomain.STORAGE,\n category: ErrorCategory.USER,\n details: { indexName },\n });\n }\n\n // Validate filter is not empty\n if (filter && Object.keys(filter).length === 0) {\n throw new MastraError({\n id: 'STORAGE_QDRANT_VECTOR_DELETE_VECTORS_EMPTY_FILTER',\n text: 'Cannot delete with empty filter object',\n domain: ErrorDomain.STORAGE,\n category: ErrorCategory.USER,\n details: { indexName },\n });\n }\n\n try {\n if (ids) {\n // Delete by IDs - parse all IDs to support both string and numeric formats\n const pointIds = ids.map(id => this.parsePointId(id));\n try {\n await this.client.delete(indexName, {\n points: pointIds,\n wait: true,\n });\n } catch (error: any) {\n // Qdrant throws \"Bad Request\" when trying to delete non-existent IDs\n // This is expected behavior and should be handled gracefully\n const message = error?.message || error?.toString() || '';\n if (message.toLowerCase().includes('bad request')) {\n // Silently ignore - deleting non-existent IDs is not an error\n return;\n }\n throw error;\n }\n } else if (filter) {\n // Delete by filter\n const translatedFilter = this.transformFilter(filter) ?? {};\n await this.client.delete(indexName, {\n filter: translatedFilter as any,\n wait: true,\n });\n }\n } catch (error) {\n if (error instanceof MastraError) throw error;\n throw new MastraError(\n {\n id: 'STORAGE_QDRANT_VECTOR_DELETE_VECTORS_FAILED',\n domain: ErrorDomain.STORAGE,\n category: ErrorCategory.THIRD_PARTY,\n details: {\n indexName,\n ...(filter && { filter: JSON.stringify(filter) }),\n ...(ids && { idsCount: ids.length }),\n },\n },\n error,\n );\n }\n }\n}\n","/**\n * Vector store specific prompt that details supported operators and examples.\n * This prompt helps users construct valid filters for Qdrant Vector.\n */\nexport const QDRANT_PROMPT = `When querying Qdrant, you can ONLY use the operators listed below. Any other operators will be rejected.\nImportant: Don't explain how to construct the filter - use the specified operators and fields to search the content and return relevant results.\nIf a user tries to give an explicit operator that is not supported, reject the filter entirely and let them know that the operator is not supported.\n\nBasic Comparison Operators:\n- $eq: Exact match (default when using field: value)\n Example: { \"category\": \"electronics\" }\n- $ne: Not equal\n Example: { \"category\": { \"$ne\": \"electronics\" } }\n- $gt: Greater than\n Example: { \"price\": { \"$gt\": 100 } }\n- $gte: Greater than or equal\n Example: { \"price\": { \"$gte\": 100 } }\n- $lt: Less than\n Example: { \"price\": { \"$lt\": 100 } }\n- $lte: Less than or equal\n Example: { \"price\": { \"$lte\": 100 } }\n\nArray Operators:\n- $in: Match any value in array\n Example: { \"category\": { \"$in\": [\"electronics\", \"books\"] } }\n- $nin: Does not match any value in array\n Example: { \"category\": { \"$nin\": [\"electronics\", \"books\"] } }\n\nLogical Operators:\n- $and: Logical AND (can be implicit or explicit)\n Implicit Example: { \"price\": { \"$gt\": 100 }, \"category\": \"electronics\" }\n Explicit Example: { \"$and\": [{ \"price\": { \"$gt\": 100 } }, { \"category\": \"electronics\" }] }\n- $or: Logical OR\n Example: { \"$or\": [{ \"price\": { \"$lt\": 50 } }, { \"category\": \"books\" }] }\n- $not: Logical NOT\n Example: { \"$not\": { \"category\": \"electronics\" } }\n\nElement Operators:\n- $exists: Check if field exists\n Example: { \"rating\": { \"$exists\": true } }\n- $match: Match text using full-text search\n Example: { \"description\": { \"$match\": \"gaming laptop\" } }\n- $null: Check if field is null\n Example: { \"rating\": { \"$null\": true } }\n\nRestrictions:\n- Regex patterns are not supported\n- Only $and, $or, and $not logical operators are supported at the top level\n- Empty arrays in $in/$nin will return no results\n- Nested fields are supported using dot notation\n- Multiple conditions on the same field are supported with both implicit and explicit $and\n- At least one key-value pair is required in filter object\n- Empty objects and undefined values are treated as no filter\n- Invalid types in comparison operators will throw errors\n- All non-logical operators must be used within a field condition\n Valid: { \"field\": { \"$gt\": 100 } }\n Valid: { \"$and\": [...] }\n Invalid: { \"$gt\": 100 }\n- Logical operators must contain field conditions, not direct operators\n Valid: { \"$and\": [{ \"field\": { \"$gt\": 100 } }] }\n Invalid: { \"$and\": [{ \"$gt\": 100 }] }\n- Logical operators ($and, $or, $not):\n - Can only be used at top level or nested within other logical operators\n - Can not be used on a field level, or be nested inside a field\n - Can not be used inside an operator\n - Valid: { \"$and\": [{ \"field\": { \"$gt\": 100 } }] }\n - Valid: { \"$or\": [{ \"$and\": [{ \"field\": { \"$gt\": 100 } }] }] }\n - Invalid: { \"field\": { \"$and\": [{ \"$gt\": 100 }] } }\n - Invalid: { \"field\": { \"$or\": [{ \"$gt\": 100 }] } }\n - Invalid: { \"field\": { \"$gt\": { \"$and\": [{...}] } } }\n\nExample Complex Query:\n{\n \"$and\": [\n { \"category\": { \"$in\": [\"electronics\", \"computers\"] } },\n { \"price\": { \"$gte\": 100, \"$lte\": 1000 } },\n { \"description\": { \"$match\": \"gaming laptop\" } },\n { \"rating\": { \"$exists\": true, \"$gt\": 4 } },\n { \"$or\": [\n { \"stock\": { \"$gt\": 0 } },\n { \"preorder\": { \"$null\": false } }\n ]},\n { \"$not\": { \"status\": \"discontinued\" } }\n ]\n}`;\n"]}
|
package/dist/index.js
CHANGED
|
@@ -416,6 +416,11 @@ var QdrantVector = class extends MastraVector {
|
|
|
416
416
|
try {
|
|
417
417
|
await this.client.deleteCollection(indexName);
|
|
418
418
|
} catch (error) {
|
|
419
|
+
const errorMessage = error?.message || error?.toString() || "";
|
|
420
|
+
if (error?.status === 404 || errorMessage.toLowerCase().includes("not found") || errorMessage.toLowerCase().includes("not exist")) {
|
|
421
|
+
this.logger.info(`Collection ${indexName} does not exist, treating as already deleted`);
|
|
422
|
+
return;
|
|
423
|
+
}
|
|
419
424
|
throw new MastraError(
|
|
420
425
|
{
|
|
421
426
|
id: "STORAGE_QDRANT_VECTOR_DELETE_INDEX_FAILED",
|
|
@@ -428,66 +433,143 @@ var QdrantVector = class extends MastraVector {
|
|
|
428
433
|
}
|
|
429
434
|
}
|
|
430
435
|
/**
|
|
431
|
-
* Updates a vector by its ID
|
|
432
|
-
* @param indexName - The name of the index containing the vector.
|
|
433
|
-
* @param id - The ID of the vector to update.
|
|
436
|
+
* Updates a vector by its ID or multiple vectors matching a filter.
|
|
437
|
+
* @param indexName - The name of the index containing the vector(s).
|
|
438
|
+
* @param id - The ID of the vector to update (mutually exclusive with filter).
|
|
439
|
+
* @param filter - Filter to match multiple vectors to update (mutually exclusive with id).
|
|
434
440
|
* @param update - An object containing the vector and/or metadata to update.
|
|
435
441
|
* @param update.vector - An optional array of numbers representing the new vector.
|
|
436
442
|
* @param update.metadata - An optional record containing the new metadata.
|
|
437
443
|
* @returns A promise that resolves when the update is complete.
|
|
438
444
|
* @throws Will throw an error if no updates are provided or if the update operation fails.
|
|
439
445
|
*/
|
|
440
|
-
async updateVector({ indexName, id, update }) {
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
{
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
446
|
+
async updateVector({ indexName, id, filter, update }) {
|
|
447
|
+
if (id && filter) {
|
|
448
|
+
throw new MastraError({
|
|
449
|
+
id: "STORAGE_QDRANT_VECTOR_UPDATE_MUTUALLY_EXCLUSIVE",
|
|
450
|
+
text: "Cannot specify both id and filter - they are mutually exclusive",
|
|
451
|
+
domain: ErrorDomain.STORAGE,
|
|
452
|
+
category: ErrorCategory.USER,
|
|
453
|
+
details: { indexName }
|
|
454
|
+
});
|
|
455
|
+
}
|
|
456
|
+
if (!id && !filter) {
|
|
457
|
+
throw new MastraError({
|
|
458
|
+
id: "STORAGE_QDRANT_VECTOR_UPDATE_NO_TARGET",
|
|
459
|
+
text: "Either id or filter must be provided",
|
|
460
|
+
domain: ErrorDomain.STORAGE,
|
|
461
|
+
category: ErrorCategory.USER,
|
|
462
|
+
details: { indexName }
|
|
463
|
+
});
|
|
464
|
+
}
|
|
465
|
+
if (!update.vector && !update.metadata) {
|
|
466
|
+
throw new MastraError({
|
|
467
|
+
id: "STORAGE_QDRANT_VECTOR_UPDATE_NO_PAYLOAD",
|
|
468
|
+
text: "No updates provided",
|
|
469
|
+
domain: ErrorDomain.STORAGE,
|
|
470
|
+
category: ErrorCategory.USER,
|
|
471
|
+
details: {
|
|
472
|
+
indexName,
|
|
473
|
+
...id && { id }
|
|
474
|
+
}
|
|
475
|
+
});
|
|
476
|
+
}
|
|
477
|
+
if (filter && Object.keys(filter).length === 0) {
|
|
478
|
+
throw new MastraError({
|
|
479
|
+
id: "STORAGE_QDRANT_VECTOR_UPDATE_EMPTY_FILTER",
|
|
480
|
+
text: "Filter cannot be an empty filter object",
|
|
481
|
+
domain: ErrorDomain.STORAGE,
|
|
482
|
+
category: ErrorCategory.USER,
|
|
483
|
+
details: { indexName }
|
|
484
|
+
});
|
|
455
485
|
}
|
|
456
|
-
const pointId = this.parsePointId(id);
|
|
457
486
|
try {
|
|
458
|
-
if (
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
487
|
+
if (id) {
|
|
488
|
+
const pointId = this.parsePointId(id);
|
|
489
|
+
if (update.metadata && !update.vector) {
|
|
490
|
+
await this.client.setPayload(indexName, { payload: update.metadata, points: [pointId] });
|
|
491
|
+
return;
|
|
492
|
+
}
|
|
493
|
+
if (update.vector && !update.metadata) {
|
|
494
|
+
await this.client.updateVectors(indexName, {
|
|
495
|
+
points: [
|
|
496
|
+
{
|
|
497
|
+
id: pointId,
|
|
498
|
+
vector: update.vector
|
|
499
|
+
}
|
|
500
|
+
]
|
|
501
|
+
});
|
|
502
|
+
return;
|
|
503
|
+
}
|
|
504
|
+
if (update.vector && update.metadata) {
|
|
505
|
+
const point = {
|
|
506
|
+
id: pointId,
|
|
507
|
+
vector: update.vector,
|
|
508
|
+
payload: update.metadata
|
|
509
|
+
};
|
|
510
|
+
await this.client.upsert(indexName, {
|
|
511
|
+
points: [point]
|
|
512
|
+
});
|
|
513
|
+
return;
|
|
514
|
+
}
|
|
515
|
+
} else if (filter) {
|
|
516
|
+
const translatedFilter = this.transformFilter(filter);
|
|
517
|
+
const matchingPoints = [];
|
|
518
|
+
let offset = void 0;
|
|
519
|
+
do {
|
|
520
|
+
const scrollResult = await this.client.scroll(indexName, {
|
|
521
|
+
filter: translatedFilter,
|
|
522
|
+
limit: 100,
|
|
523
|
+
offset,
|
|
524
|
+
with_payload: false,
|
|
525
|
+
with_vector: update.vector ? false : true
|
|
526
|
+
// Only fetch vectors if not updating them
|
|
527
|
+
});
|
|
528
|
+
matchingPoints.push(
|
|
529
|
+
...scrollResult.points.map((point) => ({
|
|
530
|
+
id: point.id,
|
|
531
|
+
vector: Array.isArray(point.vector) ? point.vector : void 0
|
|
532
|
+
}))
|
|
533
|
+
);
|
|
534
|
+
const nextOffset = scrollResult.next_page_offset;
|
|
535
|
+
offset = typeof nextOffset === "string" || typeof nextOffset === "number" ? nextOffset : void 0;
|
|
536
|
+
} while (offset !== void 0);
|
|
537
|
+
if (matchingPoints.length === 0) {
|
|
538
|
+
return;
|
|
539
|
+
}
|
|
540
|
+
const pointIds = matchingPoints.map((p) => p.id);
|
|
541
|
+
if (update.metadata && !update.vector) {
|
|
542
|
+
await this.client.setPayload(indexName, { payload: update.metadata, points: pointIds });
|
|
543
|
+
return;
|
|
544
|
+
}
|
|
545
|
+
if (update.vector) {
|
|
546
|
+
const points = matchingPoints.map((p) => ({
|
|
547
|
+
id: p.id,
|
|
548
|
+
vector: update.vector,
|
|
549
|
+
payload: update.metadata || {}
|
|
550
|
+
}));
|
|
551
|
+
for (let i = 0; i < points.length; i += BATCH_SIZE) {
|
|
552
|
+
const batch = points.slice(i, i + BATCH_SIZE);
|
|
553
|
+
await this.client.upsert(indexName, {
|
|
554
|
+
points: batch,
|
|
555
|
+
wait: true
|
|
556
|
+
});
|
|
557
|
+
}
|
|
558
|
+
return;
|
|
559
|
+
}
|
|
483
560
|
}
|
|
484
561
|
} catch (error) {
|
|
562
|
+
if (error instanceof MastraError) throw error;
|
|
485
563
|
throw new MastraError(
|
|
486
564
|
{
|
|
487
565
|
id: "STORAGE_QDRANT_VECTOR_UPDATE_VECTOR_FAILED",
|
|
488
566
|
domain: ErrorDomain.STORAGE,
|
|
489
567
|
category: ErrorCategory.THIRD_PARTY,
|
|
490
|
-
details: {
|
|
568
|
+
details: {
|
|
569
|
+
indexName,
|
|
570
|
+
...id && { id },
|
|
571
|
+
...filter && { filter: JSON.stringify(filter) }
|
|
572
|
+
}
|
|
491
573
|
},
|
|
492
574
|
error
|
|
493
575
|
);
|
|
@@ -512,7 +594,10 @@ var QdrantVector = class extends MastraVector {
|
|
|
512
594
|
id: "STORAGE_QDRANT_VECTOR_DELETE_VECTOR_FAILED",
|
|
513
595
|
domain: ErrorDomain.STORAGE,
|
|
514
596
|
category: ErrorCategory.THIRD_PARTY,
|
|
515
|
-
details: {
|
|
597
|
+
details: {
|
|
598
|
+
indexName,
|
|
599
|
+
...id && { id }
|
|
600
|
+
}
|
|
516
601
|
},
|
|
517
602
|
error
|
|
518
603
|
);
|
|
@@ -553,6 +638,90 @@ var QdrantVector = class extends MastraVector {
|
|
|
553
638
|
}
|
|
554
639
|
return id;
|
|
555
640
|
}
|
|
641
|
+
/**
|
|
642
|
+
* Deletes multiple vectors by IDs or filter.
|
|
643
|
+
* @param indexName - The name of the index containing the vectors.
|
|
644
|
+
* @param ids - Array of vector IDs to delete (mutually exclusive with filter).
|
|
645
|
+
* @param filter - Filter to match vectors to delete (mutually exclusive with ids).
|
|
646
|
+
* @returns A promise that resolves when the deletion is complete.
|
|
647
|
+
* @throws Will throw an error if both ids and filter are provided, or if neither is provided.
|
|
648
|
+
*/
|
|
649
|
+
async deleteVectors({ indexName, filter, ids }) {
|
|
650
|
+
if (ids && filter) {
|
|
651
|
+
throw new MastraError({
|
|
652
|
+
id: "STORAGE_QDRANT_VECTOR_DELETE_VECTORS_MUTUALLY_EXCLUSIVE",
|
|
653
|
+
text: "Cannot specify both ids and filter - they are mutually exclusive",
|
|
654
|
+
domain: ErrorDomain.STORAGE,
|
|
655
|
+
category: ErrorCategory.USER,
|
|
656
|
+
details: { indexName }
|
|
657
|
+
});
|
|
658
|
+
}
|
|
659
|
+
if (!ids && !filter) {
|
|
660
|
+
throw new MastraError({
|
|
661
|
+
id: "STORAGE_QDRANT_VECTOR_DELETE_VECTORS_NO_TARGET",
|
|
662
|
+
text: "Either filter or ids must be provided",
|
|
663
|
+
domain: ErrorDomain.STORAGE,
|
|
664
|
+
category: ErrorCategory.USER,
|
|
665
|
+
details: { indexName }
|
|
666
|
+
});
|
|
667
|
+
}
|
|
668
|
+
if (ids && ids.length === 0) {
|
|
669
|
+
throw new MastraError({
|
|
670
|
+
id: "STORAGE_QDRANT_VECTOR_DELETE_VECTORS_EMPTY_IDS",
|
|
671
|
+
text: "Cannot delete with empty ids array",
|
|
672
|
+
domain: ErrorDomain.STORAGE,
|
|
673
|
+
category: ErrorCategory.USER,
|
|
674
|
+
details: { indexName }
|
|
675
|
+
});
|
|
676
|
+
}
|
|
677
|
+
if (filter && Object.keys(filter).length === 0) {
|
|
678
|
+
throw new MastraError({
|
|
679
|
+
id: "STORAGE_QDRANT_VECTOR_DELETE_VECTORS_EMPTY_FILTER",
|
|
680
|
+
text: "Cannot delete with empty filter object",
|
|
681
|
+
domain: ErrorDomain.STORAGE,
|
|
682
|
+
category: ErrorCategory.USER,
|
|
683
|
+
details: { indexName }
|
|
684
|
+
});
|
|
685
|
+
}
|
|
686
|
+
try {
|
|
687
|
+
if (ids) {
|
|
688
|
+
const pointIds = ids.map((id) => this.parsePointId(id));
|
|
689
|
+
try {
|
|
690
|
+
await this.client.delete(indexName, {
|
|
691
|
+
points: pointIds,
|
|
692
|
+
wait: true
|
|
693
|
+
});
|
|
694
|
+
} catch (error) {
|
|
695
|
+
const message = error?.message || error?.toString() || "";
|
|
696
|
+
if (message.toLowerCase().includes("bad request")) {
|
|
697
|
+
return;
|
|
698
|
+
}
|
|
699
|
+
throw error;
|
|
700
|
+
}
|
|
701
|
+
} else if (filter) {
|
|
702
|
+
const translatedFilter = this.transformFilter(filter) ?? {};
|
|
703
|
+
await this.client.delete(indexName, {
|
|
704
|
+
filter: translatedFilter,
|
|
705
|
+
wait: true
|
|
706
|
+
});
|
|
707
|
+
}
|
|
708
|
+
} catch (error) {
|
|
709
|
+
if (error instanceof MastraError) throw error;
|
|
710
|
+
throw new MastraError(
|
|
711
|
+
{
|
|
712
|
+
id: "STORAGE_QDRANT_VECTOR_DELETE_VECTORS_FAILED",
|
|
713
|
+
domain: ErrorDomain.STORAGE,
|
|
714
|
+
category: ErrorCategory.THIRD_PARTY,
|
|
715
|
+
details: {
|
|
716
|
+
indexName,
|
|
717
|
+
...filter && { filter: JSON.stringify(filter) },
|
|
718
|
+
...ids && { idsCount: ids.length }
|
|
719
|
+
}
|
|
720
|
+
},
|
|
721
|
+
error
|
|
722
|
+
);
|
|
723
|
+
}
|
|
724
|
+
}
|
|
556
725
|
};
|
|
557
726
|
|
|
558
727
|
// src/vector/prompt.ts
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/vector/filter.ts","../src/vector/index.ts","../src/vector/prompt.ts"],"names":[],"mappings":";;;;;;AAwHO,IAAM,sBAAA,GAAN,cAAqC,oBAAA,CAAyC;AAAA,EAChE,kBAAkB,GAAA,EAAqC;AACxE,IAAA,OAAO,MAAM,iBAAA,CAAkB,GAAG,CAAA,IAAK,GAAA,KAAQ,YAAY,GAAA,KAAQ,YAAA;AAAA,EACrE;AAAA,EAEmB,qBAAA,GAAyC;AAC1D,IAAA,OAAO;AAAA,MACL,GAAG,oBAAA,CAAqB,iBAAA;AAAA,MACxB,OAAA,EAAS,CAAC,MAAA,EAAQ,KAAA,EAAO,MAAM,CAAA;AAAA,MAC/B,KAAA,EAAO,CAAC,KAAA,EAAO,MAAM,CAAA;AAAA,MACrB,KAAA,EAAO,CAAC,QAAQ,CAAA;AAAA,MAChB,MAAA,EAAQ,CAAC,QAAA,EAAU,MAAA,EAAQ,WAAW,WAAA,EAAa,OAAA,EAAS,QAAA,EAAU,QAAA,EAAU,YAAY;AAAA,KAC9F;AAAA,EACF;AAAA,EAEA,UAAU,MAAA,EA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AAA,IACH,SAAS,KAAA,EAAO;AACd,MAAA,MAAM,IAAI,WAAA;AAAA,QACR;AAAA,UACE,EAAA,EAAI,4CAAA;AAAA,UACJ,QAAQ,WAAA,CAAY,OAAA;AAAA,UACpB,UAAU,aAAA,CAAc,WAAA;AAAA,UACxB,OAAA,EAAS,EAAE,SAAA,EAAW,EAAA;AAAG,SAC3B;AAAA,QACA;AAAA,OACF;AAAA,IACF;AAAA,EACF;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EA+BQ,aAAa,EAAA,EAA6B;AAEhD,IAAA,IAAI,OAAA,CAAQ,IAAA,CAAK,EAAE,CAAA,EAAG;AACpB,MAAA,OAAO,QAAA,CAAS,IAAI,EAAE,CAAA;AAAA,IACxB;AACA,IAAA,OAAO,EAAA;AAAA,EACT;AACF;;;AC5XO,IAAM,aAAA,GAAgB,CAAA;AAAA;AAAA;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;AAAA;AAAA;AAAA;AAAA;AAAA;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,CAAA","file":"index.js","sourcesContent":["import { BaseFilterTranslator } from '@mastra/core/vector/filter';\nimport type {\n VectorFilter,\n LogicalOperator,\n OperatorSupport,\n OperatorValueMap,\n LogicalOperatorValueMap,\n BlacklistedRootOperators,\n} from '@mastra/core/vector/filter';\n\ntype QdrantOperatorValueMap = Omit<OperatorValueMap, '$options' | '$elemMatch' | '$all'> & {\n /**\n * $count: Filter by array length or value count.\n * Example: { tags: { $count: { gt: 2 } } }\n */\n $count: {\n $gt?: number;\n $gte?: number;\n $lt?: number;\n $lte?: number;\n $eq?: number;\n };\n\n /**\n * $geo: Geospatial filter.\n * Example: { location: { $geo: { type: 'geo_radius', center: [lon, lat], radius: 1000 } } }\n */\n $geo: {\n type: string;\n [key: string]: any;\n };\n\n /**\n * $hasId: Filter by point IDs.\n * Allowed at root level.\n * Example: { $hasId: '123' } or { $hasId: ['123', '456'] }\n */\n $hasId: string | string[];\n\n /**\n * $nested: Nested object filter.\n * Example: { metadata: { $nested: { key: 'foo', filter: { $eq: 'bar' } } } }\n */\n $nested: {\n // Additional properties depend on the nested object structure\n [key: string]: any;\n };\n\n /**\n * $hasVector: Filter by vector existence or field.\n * Allowed at root level.\n * Example: { $hasVector: true } or { $hasVector: 'vector_field' }\n */\n $hasVector: boolean | string;\n\n /**\n * $datetime: RFC 3339 datetime range.\n * Example: { createdAt: { $datetime: { gte: '2024-01-01T00:00:00Z' } } }\n */\n $datetime: {\n key?: string;\n range?: {\n gt?: Date | string;\n gte?: Date | string;\n lt?: Date | string;\n lte?: Date | string;\n eq?: Date | string;\n };\n };\n\n /**\n * $null: Check if a field is null.\n * Example: { metadata: { $null: true } }\n */\n $null: boolean;\n\n /**\n * $empty: Check if an array or object field is empty.\n * Example: { tags: { $empty: true } }\n */\n $empty: boolean;\n};\n\ntype QdrantLogicalOperatorValueMap = Omit<LogicalOperatorValueMap, '$nor'>;\n\ntype QdrantBlacklistedRootOperators =\n | BlacklistedRootOperators\n | '$count'\n | '$geo'\n | '$nested'\n | '$datetime'\n | '$null'\n | '$empty';\n\nexport type QdrantVectorFilter = VectorFilter<\n keyof QdrantOperatorValueMap,\n QdrantOperatorValueMap,\n QdrantLogicalOperatorValueMap,\n QdrantBlacklistedRootOperators\n>;\n\n/**\n * Translates MongoDB-style filters to Qdrant compatible filters.\n *\n * Key transformations:\n * - $and -> must\n * - $or -> should\n * - $not -> must_not\n * - { field: { $op: value } } -> { key: field, match/range: { value/gt/lt: value } }\n *\n * Custom operators (Qdrant-specific):\n * - $count -> values_count (array length/value count)\n * - $geo -> geo filters (box, radius, polygon)\n * - $hasId -> has_id filter\n * - $nested -> nested object filters\n * - $hasVector -> vector existence check\n * - $datetime -> RFC 3339 datetime range\n * - $null -> is_null check\n * - $empty -> is_empty check\n */\nexport class QdrantFilterTranslator extends BaseFilterTranslator<QdrantVectorFilter> {\n protected override isLogicalOperator(key: string): key is LogicalOperator {\n return super.isLogicalOperator(key) || key === '$hasId' || key === '$hasVector';\n }\n\n protected override getSupportedOperators(): OperatorSupport {\n return {\n ...BaseFilterTranslator.DEFAULT_OPERATORS,\n logical: ['$and', '$or', '$not'],\n array: ['$in', '$nin'],\n regex: ['$regex'],\n custom: ['$count', '$geo', '$nested', '$datetime', '$null', '$empty', '$hasId', '$hasVector'],\n };\n }\n\n translate(filter?: QdrantVectorFilter): QdrantVectorFilter {\n if (this.isEmpty(filter)) return filter;\n this.validateFilter(filter);\n return this.translateNode(filter);\n }\n\n private createCondition(type: string, value: any, fieldKey?: string) {\n const condition = { [type]: value };\n return fieldKey ? { key: fieldKey, ...condition } : condition;\n }\n\n private translateNode(node: QdrantVectorFilter, isNested: boolean = false, fieldKey?: string): any {\n if (!this.isEmpty(node) && !!node && typeof node === 'object' && 'must' in node) {\n return node;\n }\n\n if (this.isPrimitive(node)) {\n if (node === null) {\n return { is_null: { key: fieldKey } };\n }\n return this.createCondition('match', { value: this.normalizeComparisonValue(node) }, fieldKey);\n }\n\n if (this.isRegex(node)) {\n throw new Error('Direct regex pattern format is not supported in Qdrant');\n }\n\n if (Array.isArray(node)) {\n return node.length === 0\n ? { is_empty: { key: fieldKey } }\n : this.createCondition('match', { any: this.normalizeArrayValues(node) }, fieldKey);\n }\n\n const entries = Object.entries(node as Record<string, any>);\n\n // Handle logical operators first\n const logicalResult = this.handleLogicalOperators(entries, isNested);\n if (logicalResult) {\n return logicalResult;\n }\n\n // Handle field conditions\n const { conditions, range, matchCondition } = this.handleFieldConditions(entries, fieldKey);\n\n if (Object.keys(range).length > 0) {\n conditions.push({ key: fieldKey, range });\n }\n\n if (matchCondition) {\n conditions.push({ key: fieldKey, match: matchCondition });\n }\n\n return this.buildFinalConditions(conditions, isNested);\n }\n\n private buildFinalConditions(conditions: any[], isNested: boolean): any {\n if (conditions.length === 0) {\n return {};\n } else if (conditions.length === 1 && isNested) {\n return conditions[0];\n } else {\n return { must: conditions };\n }\n }\n\n private handleLogicalOperators(entries: [string, any][], isNested: boolean): any | null {\n const firstKey = entries[0]?.[0];\n\n if (firstKey && this.isLogicalOperator(firstKey) && !this.isCustomOperator(firstKey)) {\n const [key, value] = entries[0]!;\n const qdrantOp = this.getQdrantLogicalOp(key);\n return {\n [qdrantOp]: Array.isArray(value)\n ? value.map(v => this.translateNode(v, true))\n : [this.translateNode(value, true)],\n };\n }\n\n if (\n entries.length > 1 &&\n !isNested &&\n entries.every(([key]) => !this.isOperator(key) && !this.isCustomOperator(key))\n ) {\n return {\n must: entries.map(([key, value]) => this.translateNode(value, true, key)),\n };\n }\n\n return null;\n }\n\n private handleFieldConditions(\n entries: [string, any][],\n fieldKey?: string,\n ): { conditions: any[]; range: Record<string, any>; matchCondition: Record<string, any> | null } {\n const conditions = [];\n let range: Record<string, any> = {};\n let matchCondition: Record<string, any> | null = null;\n\n for (const [key, value] of entries) {\n if (this.isCustomOperator(key)) {\n const customOp = this.translateCustomOperator(key, value, fieldKey);\n conditions.push(customOp);\n } else if (this.isOperator(key)) {\n const opResult = this.translateOperatorValue(key, value);\n if (opResult.range) {\n Object.assign(range, opResult.range);\n } else {\n matchCondition = opResult;\n }\n } else {\n const nestedKey = fieldKey ? `${fieldKey}.${key}` : key;\n const nestedCondition = this.translateNode(value, true, nestedKey);\n\n if (nestedCondition.must) {\n conditions.push(...nestedCondition.must);\n } else if (!this.isEmpty(nestedCondition)) {\n conditions.push(nestedCondition);\n }\n }\n }\n\n return { conditions, range, matchCondition };\n }\n\n private translateCustomOperator(op: string, value: any, fieldKey?: string): any {\n switch (op) {\n case '$count':\n const countConditions = Object.entries(value).reduce(\n (acc, [k, v]) => ({\n ...acc,\n [k.replace('$', '')]: v,\n }),\n {},\n );\n return { key: fieldKey, values_count: countConditions };\n case '$geo':\n const geoOp = this.translateGeoFilter(value.type, value);\n return { key: fieldKey, ...geoOp };\n case '$hasId':\n return { has_id: Array.isArray(value) ? value : [value] };\n case '$nested':\n return {\n nested: {\n key: fieldKey,\n filter: this.translateNode(value),\n },\n };\n case '$hasVector':\n return { has_vector: value };\n case '$datetime':\n return {\n key: fieldKey,\n range: this.normalizeDatetimeRange(value.range),\n };\n case '$null':\n return { is_null: { key: fieldKey } };\n case '$empty':\n return { is_empty: { key: fieldKey } };\n default:\n throw new Error(`Unsupported custom operator: ${op}`);\n }\n }\n\n private getQdrantLogicalOp(op: string): string {\n switch (op) {\n case '$and':\n return 'must';\n case '$or':\n return 'should';\n case '$not':\n return 'must_not';\n default:\n throw new Error(`Unsupported logical operator: ${op}`);\n }\n }\n\n private translateOperatorValue(operator: string, value: any): any {\n const normalizedValue = this.normalizeComparisonValue(value);\n\n switch (operator) {\n case '$eq':\n return { value: normalizedValue };\n case '$ne':\n return { except: [normalizedValue] };\n case '$gt':\n return { range: { gt: normalizedValue } };\n case '$gte':\n return { range: { gte: normalizedValue } };\n case '$lt':\n return { range: { lt: normalizedValue } };\n case '$lte':\n return { range: { lte: normalizedValue } };\n case '$in':\n return { any: this.normalizeArrayValues(value) };\n case '$nin':\n return { except: this.normalizeArrayValues(value) };\n case '$regex':\n return { text: value };\n case 'exists':\n return value\n ? {\n must_not: [{ is_null: { key: value } }, { is_empty: { key: value } }],\n }\n : {\n is_empty: { key: value },\n };\n default:\n throw new Error(`Unsupported operator: ${operator}`);\n }\n }\n\n private translateGeoFilter(type: string, value: any): any {\n switch (type) {\n case 'box':\n return {\n geo_bounding_box: {\n top_left: value.top_left,\n bottom_right: value.bottom_right,\n },\n };\n case 'radius':\n return {\n geo_radius: {\n center: value.center,\n radius: value.radius,\n },\n };\n case 'polygon':\n return {\n geo_polygon: {\n exterior: value.exterior,\n interiors: value.interiors,\n },\n };\n default:\n throw new Error(`Unsupported geo filter type: ${type}`);\n }\n }\n\n private normalizeDatetimeRange(value: any): any {\n const range: Record<string, string> = {};\n for (const [op, val] of Object.entries(value)) {\n if (val instanceof Date) {\n range[op] = val.toISOString();\n } else if (typeof val === 'string') {\n // Assume string is already in proper format\n range[op] = val;\n }\n }\n return range;\n }\n}\n","import { MastraError, ErrorDomain, ErrorCategory } from '@mastra/core/error';\nimport { MastraVector } from '@mastra/core/vector';\nimport type {\n QueryResult,\n IndexStats,\n CreateIndexParams,\n UpsertVectorParams,\n QueryVectorParams,\n DescribeIndexParams,\n DeleteIndexParams,\n DeleteVectorParams,\n UpdateVectorParams,\n} from '@mastra/core/vector';\nimport { QdrantClient } from '@qdrant/js-client-rest';\nimport type { QdrantClientParams, Schemas } from '@qdrant/js-client-rest';\n\nimport { QdrantFilterTranslator } from './filter';\nimport type { QdrantVectorFilter } from './filter';\n\nconst BATCH_SIZE = 256;\nconst DISTANCE_MAPPING: Record<string, Schemas['Distance']> = {\n cosine: 'Cosine',\n euclidean: 'Euclid',\n dotproduct: 'Dot',\n};\n\ntype QdrantQueryVectorParams = QueryVectorParams<QdrantVectorFilter>;\n\nexport class QdrantVector extends MastraVector {\n private client: QdrantClient;\n\n /**\n * Creates a new QdrantVector client.\n * @param id - The unique identifier for this vector store instance.\n * @param url - The URL of the Qdrant server.\n * @param apiKey - The API key for Qdrant.\n * @param https - Whether to use HTTPS.\n */\n constructor({ id, ...qdrantParams }: QdrantClientParams & { id: string }) {\n super({ id });\n this.client = new QdrantClient(qdrantParams);\n }\n\n async upsert({ indexName, vectors, metadata, ids }: UpsertVectorParams): Promise<string[]> {\n const pointIds = ids || vectors.map(() => crypto.randomUUID());\n\n const records = vectors.map((vector, i) => ({\n id: pointIds[i],\n vector: vector,\n payload: metadata?.[i] || {},\n }));\n\n try {\n for (let i = 0; i < records.length; i += BATCH_SIZE) {\n const batch = records.slice(i, i + BATCH_SIZE);\n await this.client.upsert(indexName, {\n // @ts-expect-error\n points: batch,\n wait: true,\n });\n }\n\n return pointIds;\n } catch (error) {\n throw new MastraError(\n {\n id: 'STORAGE_QDRANT_VECTOR_UPSERT_FAILED',\n domain: ErrorDomain.STORAGE,\n category: ErrorCategory.THIRD_PARTY,\n details: { indexName, vectorCount: vectors.length },\n },\n error,\n );\n }\n }\n\n async createIndex({ indexName, dimension, metric = 'cosine' }: CreateIndexParams): Promise<void> {\n try {\n if (!Number.isInteger(dimension) || dimension <= 0) {\n throw new Error('Dimension must be a positive integer');\n }\n if (!DISTANCE_MAPPING[metric]) {\n throw new Error(`Invalid metric: \"${metric}\". Must be one of: cosine, euclidean, dotproduct`);\n }\n } catch (validationError) {\n throw new MastraError(\n {\n id: 'STORAGE_QDRANT_VECTOR_CREATE_INDEX_INVALID_ARGS',\n domain: ErrorDomain.STORAGE,\n category: ErrorCategory.USER,\n details: { indexName, dimension, metric },\n },\n validationError,\n );\n }\n\n try {\n await this.client.createCollection(indexName, {\n vectors: {\n size: dimension,\n distance: DISTANCE_MAPPING[metric],\n },\n });\n } catch (error: any) {\n const message = error?.message || error?.toString();\n // Qdrant typically returns 409 for existing collection\n if (error?.status === 409 || (typeof message === 'string' && message.toLowerCase().includes('exists'))) {\n // Fetch collection info and check dimension\n await this.validateExistingIndex(indexName, dimension, metric);\n return;\n }\n\n throw new MastraError(\n {\n id: 'STORAGE_QDRANT_VECTOR_CREATE_INDEX_FAILED',\n domain: ErrorDomain.STORAGE,\n category: ErrorCategory.THIRD_PARTY,\n details: { indexName, dimension, metric },\n },\n error,\n );\n }\n }\n\n transformFilter(filter?: QdrantVectorFilter) {\n const translator = new QdrantFilterTranslator();\n return translator.translate(filter);\n }\n\n async query({\n indexName,\n queryVector,\n topK = 10,\n filter,\n includeVector = false,\n }: QdrantQueryVectorParams): Promise<QueryResult[]> {\n const translatedFilter = this.transformFilter(filter) ?? {};\n\n try {\n const results = (\n await this.client.query(indexName, {\n query: queryVector,\n limit: topK,\n filter: translatedFilter,\n with_payload: true,\n with_vector: includeVector,\n })\n ).points;\n\n return results.map(match => {\n let vector: number[] = [];\n if (includeVector) {\n if (Array.isArray(match.vector)) {\n // If it's already an array of numbers\n vector = match.vector as number[];\n } else if (typeof match.vector === 'object' && match.vector !== null) {\n // If it's an object with vector data\n vector = Object.values(match.vector).filter(v => typeof v === 'number');\n }\n }\n\n return {\n id: match.id as string,\n score: match.score || 0,\n metadata: match.payload as Record<string, any>,\n ...(includeVector && { vector }),\n };\n });\n } catch (error) {\n throw new MastraError(\n {\n id: 'STORAGE_QDRANT_VECTOR_QUERY_FAILED',\n domain: ErrorDomain.STORAGE,\n category: ErrorCategory.THIRD_PARTY,\n details: { indexName, topK },\n },\n error,\n );\n }\n }\n\n async listIndexes(): Promise<string[]> {\n try {\n const response = await this.client.getCollections();\n return response.collections.map(collection => collection.name) || [];\n } catch (error) {\n throw new MastraError(\n {\n id: 'STORAGE_QDRANT_VECTOR_LIST_INDEXES_FAILED',\n domain: ErrorDomain.STORAGE,\n category: ErrorCategory.THIRD_PARTY,\n },\n error,\n );\n }\n }\n\n /**\n * Retrieves statistics about a vector index.\n *\n * @param {string} indexName - The name of the index to describe\n * @returns A promise that resolves to the index statistics including dimension, count and metric\n */\n async describeIndex({ indexName }: DescribeIndexParams): Promise<IndexStats> {\n try {\n const { config, points_count } = await this.client.getCollection(indexName);\n\n const distance = config.params.vectors?.distance as Schemas['Distance'];\n return {\n dimension: config.params.vectors?.size as number,\n count: points_count || 0,\n // @ts-expect-error\n metric: Object.keys(DISTANCE_MAPPING).find(key => DISTANCE_MAPPING[key] === distance),\n };\n } catch (error) {\n throw new MastraError(\n {\n id: 'STORAGE_QDRANT_VECTOR_DESCRIBE_INDEX_FAILED',\n domain: ErrorDomain.STORAGE,\n category: ErrorCategory.THIRD_PARTY,\n details: { indexName },\n },\n error,\n );\n }\n }\n\n async deleteIndex({ indexName }: DeleteIndexParams): Promise<void> {\n try {\n await this.client.deleteCollection(indexName);\n } catch (error) {\n throw new MastraError(\n {\n id: 'STORAGE_QDRANT_VECTOR_DELETE_INDEX_FAILED',\n domain: ErrorDomain.STORAGE,\n category: ErrorCategory.THIRD_PARTY,\n details: { indexName },\n },\n error,\n );\n }\n }\n\n /**\n * Updates a vector by its ID with the provided vector and/or metadata.\n * @param indexName - The name of the index containing the vector.\n * @param id - The ID of the vector to update.\n * @param update - An object containing the vector and/or metadata to update.\n * @param update.vector - An optional array of numbers representing the new vector.\n * @param update.metadata - An optional record containing the new metadata.\n * @returns A promise that resolves when the update is complete.\n * @throws Will throw an error if no updates are provided or if the update operation fails.\n */\n async updateVector({ indexName, id, update }: UpdateVectorParams): Promise<void> {\n try {\n if (!update.vector && !update.metadata) {\n throw new Error('No updates provided');\n }\n } catch (validationError) {\n throw new MastraError(\n {\n id: 'STORAGE_QDRANT_VECTOR_UPDATE_VECTOR_INVALID_ARGS',\n domain: ErrorDomain.STORAGE,\n category: ErrorCategory.USER,\n details: { indexName, id },\n },\n validationError,\n );\n }\n\n const pointId = this.parsePointId(id);\n\n try {\n // Handle metadata-only update\n if (update.metadata && !update.vector) {\n // For metadata-only updates, use the setPayload method\n await this.client.setPayload(indexName, { payload: update.metadata, points: [pointId] });\n return;\n }\n\n // Handle vector-only update\n if (update.vector && !update.metadata) {\n await this.client.updateVectors(indexName, {\n points: [\n {\n id: pointId,\n vector: update.vector,\n },\n ],\n });\n return;\n }\n\n // Handle both vector and metadata update\n if (update.vector && update.metadata) {\n const point = {\n id: pointId,\n vector: update.vector,\n payload: update.metadata,\n };\n\n await this.client.upsert(indexName, {\n points: [point],\n });\n return;\n }\n } catch (error) {\n throw new MastraError(\n {\n id: 'STORAGE_QDRANT_VECTOR_UPDATE_VECTOR_FAILED',\n domain: ErrorDomain.STORAGE,\n category: ErrorCategory.THIRD_PARTY,\n details: { indexName, id },\n },\n error,\n );\n }\n }\n\n /**\n * Deletes a vector by its ID.\n * @param indexName - The name of the index containing the vector.\n * @param id - The ID of the vector to delete.\n * @returns A promise that resolves when the deletion is complete.\n * @throws Will throw an error if the deletion operation fails.\n */\n async deleteVector({ indexName, id }: DeleteVectorParams): Promise<void> {\n try {\n // Parse the ID - Qdrant supports both string and numeric IDs\n const pointId = this.parsePointId(id);\n\n // Use the Qdrant client to delete the point from the collection\n await this.client.delete(indexName, {\n points: [pointId],\n });\n } catch (error) {\n throw new MastraError(\n {\n id: 'STORAGE_QDRANT_VECTOR_DELETE_VECTOR_FAILED',\n domain: ErrorDomain.STORAGE,\n category: ErrorCategory.THIRD_PARTY,\n details: { indexName, id },\n },\n error,\n );\n }\n }\n\n /**\n * Parses and converts a string ID to the appropriate type (string or number) for Qdrant point operations.\n *\n * Qdrant supports both numeric and string IDs. This helper method ensures IDs are in the correct format\n * before sending them to the Qdrant client API.\n *\n * @param id - The ID string to parse\n * @returns The parsed ID as either a number (if string contains only digits) or the original string\n *\n * @example\n * // Numeric ID strings are converted to numbers\n * parsePointId(\"123\") => 123\n * parsePointId(\"42\") => 42\n * parsePointId(\"0\") => 0\n *\n * // String IDs containing any non-digit characters remain as strings\n * parsePointId(\"doc-123\") => \"doc-123\"\n * parsePointId(\"user_42\") => \"user_42\"\n * parsePointId(\"abc123\") => \"abc123\"\n * parsePointId(\"123abc\") => \"123abc\"\n * parsePointId(\"\") => \"\"\n * parsePointId(\"uuid-5678-xyz\") => \"uuid-5678-xyz\"\n *\n * @remarks\n * - This conversion is important because Qdrant treats numeric and string IDs differently\n * - Only positive integers are converted to numbers (negative numbers with minus signs remain strings)\n * - The method uses base-10 parsing, so leading zeros will be dropped in numeric conversions\n * - reference: https://qdrant.tech/documentation/concepts/points/?q=qdrant+point+id#point-ids\n */\n private parsePointId(id: string): string | number {\n // Try to parse as number if it looks like one\n if (/^\\d+$/.test(id)) {\n return parseInt(id, 10);\n }\n return id;\n }\n}\n","/**\n * Vector store specific prompt that details supported operators and examples.\n * This prompt helps users construct valid filters for Qdrant Vector.\n */\nexport const QDRANT_PROMPT = `When querying Qdrant, you can ONLY use the operators listed below. Any other operators will be rejected.\nImportant: Don't explain how to construct the filter - use the specified operators and fields to search the content and return relevant results.\nIf a user tries to give an explicit operator that is not supported, reject the filter entirely and let them know that the operator is not supported.\n\nBasic Comparison Operators:\n- $eq: Exact match (default when using field: value)\n Example: { \"category\": \"electronics\" }\n- $ne: Not equal\n Example: { \"category\": { \"$ne\": \"electronics\" } }\n- $gt: Greater than\n Example: { \"price\": { \"$gt\": 100 } }\n- $gte: Greater than or equal\n Example: { \"price\": { \"$gte\": 100 } }\n- $lt: Less than\n Example: { \"price\": { \"$lt\": 100 } }\n- $lte: Less than or equal\n Example: { \"price\": { \"$lte\": 100 } }\n\nArray Operators:\n- $in: Match any value in array\n Example: { \"category\": { \"$in\": [\"electronics\", \"books\"] } }\n- $nin: Does not match any value in array\n Example: { \"category\": { \"$nin\": [\"electronics\", \"books\"] } }\n\nLogical Operators:\n- $and: Logical AND (can be implicit or explicit)\n Implicit Example: { \"price\": { \"$gt\": 100 }, \"category\": \"electronics\" }\n Explicit Example: { \"$and\": [{ \"price\": { \"$gt\": 100 } }, { \"category\": \"electronics\" }] }\n- $or: Logical OR\n Example: { \"$or\": [{ \"price\": { \"$lt\": 50 } }, { \"category\": \"books\" }] }\n- $not: Logical NOT\n Example: { \"$not\": { \"category\": \"electronics\" } }\n\nElement Operators:\n- $exists: Check if field exists\n Example: { \"rating\": { \"$exists\": true } }\n- $match: Match text using full-text search\n Example: { \"description\": { \"$match\": \"gaming laptop\" } }\n- $null: Check if field is null\n Example: { \"rating\": { \"$null\": true } }\n\nRestrictions:\n- Regex patterns are not supported\n- Only $and, $or, and $not logical operators are supported at the top level\n- Empty arrays in $in/$nin will return no results\n- Nested fields are supported using dot notation\n- Multiple conditions on the same field are supported with both implicit and explicit $and\n- At least one key-value pair is required in filter object\n- Empty objects and undefined values are treated as no filter\n- Invalid types in comparison operators will throw errors\n- All non-logical operators must be used within a field condition\n Valid: { \"field\": { \"$gt\": 100 } }\n Valid: { \"$and\": [...] }\n Invalid: { \"$gt\": 100 }\n- Logical operators must contain field conditions, not direct operators\n Valid: { \"$and\": [{ \"field\": { \"$gt\": 100 } }] }\n Invalid: { \"$and\": [{ \"$gt\": 100 }] }\n- Logical operators ($and, $or, $not):\n - Can only be used at top level or nested within other logical operators\n - Can not be used on a field level, or be nested inside a field\n - Can not be used inside an operator\n - Valid: { \"$and\": [{ \"field\": { \"$gt\": 100 } }] }\n - Valid: { \"$or\": [{ \"$and\": [{ \"field\": { \"$gt\": 100 } }] }] }\n - Invalid: { \"field\": { \"$and\": [{ \"$gt\": 100 }] } }\n - Invalid: { \"field\": { \"$or\": [{ \"$gt\": 100 }] } }\n - Invalid: { \"field\": { \"$gt\": { \"$and\": [{...}] } } }\n\nExample Complex Query:\n{\n \"$and\": [\n { \"category\": { \"$in\": [\"electronics\", \"computers\"] } },\n { \"price\": { \"$gte\": 100, \"$lte\": 1000 } },\n { \"description\": { \"$match\": \"gaming laptop\" } },\n { \"rating\": { \"$exists\": true, \"$gt\": 4 } },\n { \"$or\": [\n { \"stock\": { \"$gt\": 0 } },\n { \"preorder\": { \"$null\": false } }\n ]},\n { \"$not\": { \"status\": \"discontinued\" } }\n ]\n}`;\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/vector/filter.ts","../src/vector/index.ts","../src/vector/prompt.ts"],"names":[],"mappings":";;;;;;AAwHO,IAAM,sBAAA,GAAN,cAAqC,oBAAA,CAAyC;AAAA,EAChE,kBAAkB,GAAA,EAAqC;AACxE,IAAA,OAAO,MAAM,iBAAA,CAAkB,GAAG,CAAA,IAAK,GAAA,KAAQ,YAAY,GAAA,KAAQ,YAAA;AAAA,EACrE;A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;AAAA;AAAA;AAAA;AAAA;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,CAAA","file":"index.js","sourcesContent":["import { BaseFilterTranslator } from '@mastra/core/vector/filter';\nimport type {\n VectorFilter,\n LogicalOperator,\n OperatorSupport,\n OperatorValueMap,\n LogicalOperatorValueMap,\n BlacklistedRootOperators,\n} from '@mastra/core/vector/filter';\n\ntype QdrantOperatorValueMap = Omit<OperatorValueMap, '$options' | '$elemMatch' | '$all'> & {\n /**\n * $count: Filter by array length or value count.\n * Example: { tags: { $count: { gt: 2 } } }\n */\n $count: {\n $gt?: number;\n $gte?: number;\n $lt?: number;\n $lte?: number;\n $eq?: number;\n };\n\n /**\n * $geo: Geospatial filter.\n * Example: { location: { $geo: { type: 'geo_radius', center: [lon, lat], radius: 1000 } } }\n */\n $geo: {\n type: string;\n [key: string]: any;\n };\n\n /**\n * $hasId: Filter by point IDs.\n * Allowed at root level.\n * Example: { $hasId: '123' } or { $hasId: ['123', '456'] }\n */\n $hasId: string | string[];\n\n /**\n * $nested: Nested object filter.\n * Example: { metadata: { $nested: { key: 'foo', filter: { $eq: 'bar' } } } }\n */\n $nested: {\n // Additional properties depend on the nested object structure\n [key: string]: any;\n };\n\n /**\n * $hasVector: Filter by vector existence or field.\n * Allowed at root level.\n * Example: { $hasVector: true } or { $hasVector: 'vector_field' }\n */\n $hasVector: boolean | string;\n\n /**\n * $datetime: RFC 3339 datetime range.\n * Example: { createdAt: { $datetime: { gte: '2024-01-01T00:00:00Z' } } }\n */\n $datetime: {\n key?: string;\n range?: {\n gt?: Date | string;\n gte?: Date | string;\n lt?: Date | string;\n lte?: Date | string;\n eq?: Date | string;\n };\n };\n\n /**\n * $null: Check if a field is null.\n * Example: { metadata: { $null: true } }\n */\n $null: boolean;\n\n /**\n * $empty: Check if an array or object field is empty.\n * Example: { tags: { $empty: true } }\n */\n $empty: boolean;\n};\n\ntype QdrantLogicalOperatorValueMap = Omit<LogicalOperatorValueMap, '$nor'>;\n\ntype QdrantBlacklistedRootOperators =\n | BlacklistedRootOperators\n | '$count'\n | '$geo'\n | '$nested'\n | '$datetime'\n | '$null'\n | '$empty';\n\nexport type QdrantVectorFilter = VectorFilter<\n keyof QdrantOperatorValueMap,\n QdrantOperatorValueMap,\n QdrantLogicalOperatorValueMap,\n QdrantBlacklistedRootOperators\n>;\n\n/**\n * Translates MongoDB-style filters to Qdrant compatible filters.\n *\n * Key transformations:\n * - $and -> must\n * - $or -> should\n * - $not -> must_not\n * - { field: { $op: value } } -> { key: field, match/range: { value/gt/lt: value } }\n *\n * Custom operators (Qdrant-specific):\n * - $count -> values_count (array length/value count)\n * - $geo -> geo filters (box, radius, polygon)\n * - $hasId -> has_id filter\n * - $nested -> nested object filters\n * - $hasVector -> vector existence check\n * - $datetime -> RFC 3339 datetime range\n * - $null -> is_null check\n * - $empty -> is_empty check\n */\nexport class QdrantFilterTranslator extends BaseFilterTranslator<QdrantVectorFilter> {\n protected override isLogicalOperator(key: string): key is LogicalOperator {\n return super.isLogicalOperator(key) || key === '$hasId' || key === '$hasVector';\n }\n\n protected override getSupportedOperators(): OperatorSupport {\n return {\n ...BaseFilterTranslator.DEFAULT_OPERATORS,\n logical: ['$and', '$or', '$not'],\n array: ['$in', '$nin'],\n regex: ['$regex'],\n custom: ['$count', '$geo', '$nested', '$datetime', '$null', '$empty', '$hasId', '$hasVector'],\n };\n }\n\n translate(filter?: QdrantVectorFilter): QdrantVectorFilter {\n if (this.isEmpty(filter)) return filter;\n this.validateFilter(filter);\n return this.translateNode(filter);\n }\n\n private createCondition(type: string, value: any, fieldKey?: string) {\n const condition = { [type]: value };\n return fieldKey ? { key: fieldKey, ...condition } : condition;\n }\n\n private translateNode(node: QdrantVectorFilter, isNested: boolean = false, fieldKey?: string): any {\n if (!this.isEmpty(node) && !!node && typeof node === 'object' && 'must' in node) {\n return node;\n }\n\n if (this.isPrimitive(node)) {\n if (node === null) {\n return { is_null: { key: fieldKey } };\n }\n return this.createCondition('match', { value: this.normalizeComparisonValue(node) }, fieldKey);\n }\n\n if (this.isRegex(node)) {\n throw new Error('Direct regex pattern format is not supported in Qdrant');\n }\n\n if (Array.isArray(node)) {\n return node.length === 0\n ? { is_empty: { key: fieldKey } }\n : this.createCondition('match', { any: this.normalizeArrayValues(node) }, fieldKey);\n }\n\n const entries = Object.entries(node as Record<string, any>);\n\n // Handle logical operators first\n const logicalResult = this.handleLogicalOperators(entries, isNested);\n if (logicalResult) {\n return logicalResult;\n }\n\n // Handle field conditions\n const { conditions, range, matchCondition } = this.handleFieldConditions(entries, fieldKey);\n\n if (Object.keys(range).length > 0) {\n conditions.push({ key: fieldKey, range });\n }\n\n if (matchCondition) {\n conditions.push({ key: fieldKey, match: matchCondition });\n }\n\n return this.buildFinalConditions(conditions, isNested);\n }\n\n private buildFinalConditions(conditions: any[], isNested: boolean): any {\n if (conditions.length === 0) {\n return {};\n } else if (conditions.length === 1 && isNested) {\n return conditions[0];\n } else {\n return { must: conditions };\n }\n }\n\n private handleLogicalOperators(entries: [string, any][], isNested: boolean): any | null {\n const firstKey = entries[0]?.[0];\n\n if (firstKey && this.isLogicalOperator(firstKey) && !this.isCustomOperator(firstKey)) {\n const [key, value] = entries[0]!;\n const qdrantOp = this.getQdrantLogicalOp(key);\n return {\n [qdrantOp]: Array.isArray(value)\n ? value.map(v => this.translateNode(v, true))\n : [this.translateNode(value, true)],\n };\n }\n\n if (\n entries.length > 1 &&\n !isNested &&\n entries.every(([key]) => !this.isOperator(key) && !this.isCustomOperator(key))\n ) {\n return {\n must: entries.map(([key, value]) => this.translateNode(value, true, key)),\n };\n }\n\n return null;\n }\n\n private handleFieldConditions(\n entries: [string, any][],\n fieldKey?: string,\n ): { conditions: any[]; range: Record<string, any>; matchCondition: Record<string, any> | null } {\n const conditions = [];\n let range: Record<string, any> = {};\n let matchCondition: Record<string, any> | null = null;\n\n for (const [key, value] of entries) {\n if (this.isCustomOperator(key)) {\n const customOp = this.translateCustomOperator(key, value, fieldKey);\n conditions.push(customOp);\n } else if (this.isOperator(key)) {\n const opResult = this.translateOperatorValue(key, value);\n if (opResult.range) {\n Object.assign(range, opResult.range);\n } else {\n matchCondition = opResult;\n }\n } else {\n const nestedKey = fieldKey ? `${fieldKey}.${key}` : key;\n const nestedCondition = this.translateNode(value, true, nestedKey);\n\n if (nestedCondition.must) {\n conditions.push(...nestedCondition.must);\n } else if (!this.isEmpty(nestedCondition)) {\n conditions.push(nestedCondition);\n }\n }\n }\n\n return { conditions, range, matchCondition };\n }\n\n private translateCustomOperator(op: string, value: any, fieldKey?: string): any {\n switch (op) {\n case '$count':\n const countConditions = Object.entries(value).reduce(\n (acc, [k, v]) => ({\n ...acc,\n [k.replace('$', '')]: v,\n }),\n {},\n );\n return { key: fieldKey, values_count: countConditions };\n case '$geo':\n const geoOp = this.translateGeoFilter(value.type, value);\n return { key: fieldKey, ...geoOp };\n case '$hasId':\n return { has_id: Array.isArray(value) ? value : [value] };\n case '$nested':\n return {\n nested: {\n key: fieldKey,\n filter: this.translateNode(value),\n },\n };\n case '$hasVector':\n return { has_vector: value };\n case '$datetime':\n return {\n key: fieldKey,\n range: this.normalizeDatetimeRange(value.range),\n };\n case '$null':\n return { is_null: { key: fieldKey } };\n case '$empty':\n return { is_empty: { key: fieldKey } };\n default:\n throw new Error(`Unsupported custom operator: ${op}`);\n }\n }\n\n private getQdrantLogicalOp(op: string): string {\n switch (op) {\n case '$and':\n return 'must';\n case '$or':\n return 'should';\n case '$not':\n return 'must_not';\n default:\n throw new Error(`Unsupported logical operator: ${op}`);\n }\n }\n\n private translateOperatorValue(operator: string, value: any): any {\n const normalizedValue = this.normalizeComparisonValue(value);\n\n switch (operator) {\n case '$eq':\n return { value: normalizedValue };\n case '$ne':\n return { except: [normalizedValue] };\n case '$gt':\n return { range: { gt: normalizedValue } };\n case '$gte':\n return { range: { gte: normalizedValue } };\n case '$lt':\n return { range: { lt: normalizedValue } };\n case '$lte':\n return { range: { lte: normalizedValue } };\n case '$in':\n return { any: this.normalizeArrayValues(value) };\n case '$nin':\n return { except: this.normalizeArrayValues(value) };\n case '$regex':\n return { text: value };\n case 'exists':\n return value\n ? {\n must_not: [{ is_null: { key: value } }, { is_empty: { key: value } }],\n }\n : {\n is_empty: { key: value },\n };\n default:\n throw new Error(`Unsupported operator: ${operator}`);\n }\n }\n\n private translateGeoFilter(type: string, value: any): any {\n switch (type) {\n case 'box':\n return {\n geo_bounding_box: {\n top_left: value.top_left,\n bottom_right: value.bottom_right,\n },\n };\n case 'radius':\n return {\n geo_radius: {\n center: value.center,\n radius: value.radius,\n },\n };\n case 'polygon':\n return {\n geo_polygon: {\n exterior: value.exterior,\n interiors: value.interiors,\n },\n };\n default:\n throw new Error(`Unsupported geo filter type: ${type}`);\n }\n }\n\n private normalizeDatetimeRange(value: any): any {\n const range: Record<string, string> = {};\n for (const [op, val] of Object.entries(value)) {\n if (val instanceof Date) {\n range[op] = val.toISOString();\n } else if (typeof val === 'string') {\n // Assume string is already in proper format\n range[op] = val;\n }\n }\n return range;\n }\n}\n","import { MastraError, ErrorDomain, ErrorCategory } from '@mastra/core/error';\nimport { MastraVector } from '@mastra/core/vector';\nimport type {\n QueryResult,\n IndexStats,\n CreateIndexParams,\n UpsertVectorParams,\n QueryVectorParams,\n DescribeIndexParams,\n DeleteIndexParams,\n DeleteVectorParams,\n UpdateVectorParams,\n DeleteVectorsParams,\n} from '@mastra/core/vector';\nimport { QdrantClient } from '@qdrant/js-client-rest';\nimport type { QdrantClientParams, Schemas } from '@qdrant/js-client-rest';\n\nimport { QdrantFilterTranslator } from './filter';\nimport type { QdrantVectorFilter } from './filter';\n\nconst BATCH_SIZE = 256;\nconst DISTANCE_MAPPING: Record<string, Schemas['Distance']> = {\n cosine: 'Cosine',\n euclidean: 'Euclid',\n dotproduct: 'Dot',\n};\n\ntype QdrantQueryVectorParams = QueryVectorParams<QdrantVectorFilter>;\n\nexport class QdrantVector extends MastraVector {\n private client: QdrantClient;\n\n /**\n * Creates a new QdrantVector client.\n * @param id - The unique identifier for this vector store instance.\n * @param url - The URL of the Qdrant server.\n * @param apiKey - The API key for Qdrant.\n * @param https - Whether to use HTTPS.\n */\n constructor({ id, ...qdrantParams }: QdrantClientParams & { id: string }) {\n super({ id });\n this.client = new QdrantClient(qdrantParams);\n }\n\n async upsert({ indexName, vectors, metadata, ids }: UpsertVectorParams): Promise<string[]> {\n const pointIds = ids || vectors.map(() => crypto.randomUUID());\n\n const records = vectors.map((vector, i) => ({\n id: pointIds[i],\n vector: vector,\n payload: metadata?.[i] || {},\n }));\n\n try {\n for (let i = 0; i < records.length; i += BATCH_SIZE) {\n const batch = records.slice(i, i + BATCH_SIZE);\n await this.client.upsert(indexName, {\n // @ts-expect-error\n points: batch,\n wait: true,\n });\n }\n\n return pointIds;\n } catch (error) {\n throw new MastraError(\n {\n id: 'STORAGE_QDRANT_VECTOR_UPSERT_FAILED',\n domain: ErrorDomain.STORAGE,\n category: ErrorCategory.THIRD_PARTY,\n details: { indexName, vectorCount: vectors.length },\n },\n error,\n );\n }\n }\n\n async createIndex({ indexName, dimension, metric = 'cosine' }: CreateIndexParams): Promise<void> {\n try {\n if (!Number.isInteger(dimension) || dimension <= 0) {\n throw new Error('Dimension must be a positive integer');\n }\n if (!DISTANCE_MAPPING[metric]) {\n throw new Error(`Invalid metric: \"${metric}\". Must be one of: cosine, euclidean, dotproduct`);\n }\n } catch (validationError) {\n throw new MastraError(\n {\n id: 'STORAGE_QDRANT_VECTOR_CREATE_INDEX_INVALID_ARGS',\n domain: ErrorDomain.STORAGE,\n category: ErrorCategory.USER,\n details: { indexName, dimension, metric },\n },\n validationError,\n );\n }\n\n try {\n await this.client.createCollection(indexName, {\n vectors: {\n size: dimension,\n distance: DISTANCE_MAPPING[metric],\n },\n });\n } catch (error: any) {\n const message = error?.message || error?.toString();\n // Qdrant typically returns 409 for existing collection\n if (error?.status === 409 || (typeof message === 'string' && message.toLowerCase().includes('exists'))) {\n // Fetch collection info and check dimension\n await this.validateExistingIndex(indexName, dimension, metric);\n return;\n }\n\n throw new MastraError(\n {\n id: 'STORAGE_QDRANT_VECTOR_CREATE_INDEX_FAILED',\n domain: ErrorDomain.STORAGE,\n category: ErrorCategory.THIRD_PARTY,\n details: { indexName, dimension, metric },\n },\n error,\n );\n }\n }\n\n transformFilter(filter?: QdrantVectorFilter) {\n const translator = new QdrantFilterTranslator();\n return translator.translate(filter);\n }\n\n async query({\n indexName,\n queryVector,\n topK = 10,\n filter,\n includeVector = false,\n }: QdrantQueryVectorParams): Promise<QueryResult[]> {\n const translatedFilter = this.transformFilter(filter) ?? {};\n\n try {\n const results = (\n await this.client.query(indexName, {\n query: queryVector,\n limit: topK,\n filter: translatedFilter,\n with_payload: true,\n with_vector: includeVector,\n })\n ).points;\n\n return results.map(match => {\n let vector: number[] = [];\n if (includeVector) {\n if (Array.isArray(match.vector)) {\n // If it's already an array of numbers\n vector = match.vector as number[];\n } else if (typeof match.vector === 'object' && match.vector !== null) {\n // If it's an object with vector data\n vector = Object.values(match.vector).filter(v => typeof v === 'number');\n }\n }\n\n return {\n id: match.id as string,\n score: match.score || 0,\n metadata: match.payload as Record<string, any>,\n ...(includeVector && { vector }),\n };\n });\n } catch (error) {\n throw new MastraError(\n {\n id: 'STORAGE_QDRANT_VECTOR_QUERY_FAILED',\n domain: ErrorDomain.STORAGE,\n category: ErrorCategory.THIRD_PARTY,\n details: { indexName, topK },\n },\n error,\n );\n }\n }\n\n async listIndexes(): Promise<string[]> {\n try {\n const response = await this.client.getCollections();\n return response.collections.map(collection => collection.name) || [];\n } catch (error) {\n throw new MastraError(\n {\n id: 'STORAGE_QDRANT_VECTOR_LIST_INDEXES_FAILED',\n domain: ErrorDomain.STORAGE,\n category: ErrorCategory.THIRD_PARTY,\n },\n error,\n );\n }\n }\n\n /**\n * Retrieves statistics about a vector index.\n *\n * @param {string} indexName - The name of the index to describe\n * @returns A promise that resolves to the index statistics including dimension, count and metric\n */\n async describeIndex({ indexName }: DescribeIndexParams): Promise<IndexStats> {\n try {\n const { config, points_count } = await this.client.getCollection(indexName);\n\n const distance = config.params.vectors?.distance as Schemas['Distance'];\n return {\n dimension: config.params.vectors?.size as number,\n count: points_count || 0,\n // @ts-expect-error\n metric: Object.keys(DISTANCE_MAPPING).find(key => DISTANCE_MAPPING[key] === distance),\n };\n } catch (error) {\n throw new MastraError(\n {\n id: 'STORAGE_QDRANT_VECTOR_DESCRIBE_INDEX_FAILED',\n domain: ErrorDomain.STORAGE,\n category: ErrorCategory.THIRD_PARTY,\n details: { indexName },\n },\n error,\n );\n }\n }\n\n async deleteIndex({ indexName }: DeleteIndexParams): Promise<void> {\n try {\n await this.client.deleteCollection(indexName);\n } catch (error: any) {\n // If the collection doesn't exist, treat it as a no-op (already deleted)\n const errorMessage = error?.message || error?.toString() || '';\n if (\n error?.status === 404 ||\n errorMessage.toLowerCase().includes('not found') ||\n errorMessage.toLowerCase().includes('not exist')\n ) {\n this.logger.info(`Collection ${indexName} does not exist, treating as already deleted`);\n return;\n }\n throw new MastraError(\n {\n id: 'STORAGE_QDRANT_VECTOR_DELETE_INDEX_FAILED',\n domain: ErrorDomain.STORAGE,\n category: ErrorCategory.THIRD_PARTY,\n details: { indexName },\n },\n error,\n );\n }\n }\n\n /**\n * Updates a vector by its ID or multiple vectors matching a filter.\n * @param indexName - The name of the index containing the vector(s).\n * @param id - The ID of the vector to update (mutually exclusive with filter).\n * @param filter - Filter to match multiple vectors to update (mutually exclusive with id).\n * @param update - An object containing the vector and/or metadata to update.\n * @param update.vector - An optional array of numbers representing the new vector.\n * @param update.metadata - An optional record containing the new metadata.\n * @returns A promise that resolves when the update is complete.\n * @throws Will throw an error if no updates are provided or if the update operation fails.\n */\n async updateVector({ indexName, id, filter, update }: UpdateVectorParams<QdrantVectorFilter>): Promise<void> {\n // Validate mutually exclusive parameters\n if (id && filter) {\n throw new MastraError({\n id: 'STORAGE_QDRANT_VECTOR_UPDATE_MUTUALLY_EXCLUSIVE',\n text: 'Cannot specify both id and filter - they are mutually exclusive',\n domain: ErrorDomain.STORAGE,\n category: ErrorCategory.USER,\n details: { indexName },\n });\n }\n\n if (!id && !filter) {\n throw new MastraError({\n id: 'STORAGE_QDRANT_VECTOR_UPDATE_NO_TARGET',\n text: 'Either id or filter must be provided',\n domain: ErrorDomain.STORAGE,\n category: ErrorCategory.USER,\n details: { indexName },\n });\n }\n\n if (!update.vector && !update.metadata) {\n throw new MastraError({\n id: 'STORAGE_QDRANT_VECTOR_UPDATE_NO_PAYLOAD',\n text: 'No updates provided',\n domain: ErrorDomain.STORAGE,\n category: ErrorCategory.USER,\n details: {\n indexName,\n ...(id && { id }),\n },\n });\n }\n\n // Validate filter is not empty\n if (filter && Object.keys(filter).length === 0) {\n throw new MastraError({\n id: 'STORAGE_QDRANT_VECTOR_UPDATE_EMPTY_FILTER',\n text: 'Filter cannot be an empty filter object',\n domain: ErrorDomain.STORAGE,\n category: ErrorCategory.USER,\n details: { indexName },\n });\n }\n\n try {\n if (id) {\n // Update single vector by ID\n const pointId = this.parsePointId(id);\n\n // Handle metadata-only update\n if (update.metadata && !update.vector) {\n await this.client.setPayload(indexName, { payload: update.metadata, points: [pointId] });\n return;\n }\n\n // Handle vector-only update\n if (update.vector && !update.metadata) {\n await this.client.updateVectors(indexName, {\n points: [\n {\n id: pointId,\n vector: update.vector,\n },\n ],\n });\n return;\n }\n\n // Handle both vector and metadata update\n if (update.vector && update.metadata) {\n const point = {\n id: pointId,\n vector: update.vector,\n payload: update.metadata,\n };\n\n await this.client.upsert(indexName, {\n points: [point],\n });\n return;\n }\n } else if (filter) {\n // Update multiple vectors matching filter\n const translatedFilter = this.transformFilter(filter);\n\n // First, scroll through all matching points to get their IDs\n const matchingPoints: Array<{ id: string | number; vector?: number[] }> = [];\n let offset: string | number | undefined = undefined;\n\n do {\n const scrollResult = await this.client.scroll(indexName, {\n filter: translatedFilter,\n limit: 100,\n offset,\n with_payload: false,\n with_vector: update.vector ? false : true, // Only fetch vectors if not updating them\n });\n\n matchingPoints.push(\n ...scrollResult.points.map(point => ({\n id: point.id,\n vector: Array.isArray(point.vector) ? (point.vector as number[]) : undefined,\n })),\n );\n\n const nextOffset = scrollResult.next_page_offset;\n offset = typeof nextOffset === 'string' || typeof nextOffset === 'number' ? nextOffset : undefined;\n } while (offset !== undefined);\n\n if (matchingPoints.length === 0) {\n // No vectors to update - this is not an error\n return;\n }\n\n const pointIds = matchingPoints.map(p => p.id);\n\n // Handle metadata-only update\n if (update.metadata && !update.vector) {\n await this.client.setPayload(indexName, { payload: update.metadata, points: pointIds });\n return;\n }\n\n // Handle vector-only or both updates\n if (update.vector) {\n // For vector updates with filter, we need to upsert each point\n const points = matchingPoints.map(p => ({\n id: p.id,\n vector: update.vector!,\n payload: update.metadata || {},\n }));\n\n // Batch upsert\n for (let i = 0; i < points.length; i += BATCH_SIZE) {\n const batch = points.slice(i, i + BATCH_SIZE);\n await this.client.upsert(indexName, {\n points: batch,\n wait: true,\n });\n }\n return;\n }\n }\n } catch (error) {\n if (error instanceof MastraError) throw error;\n throw new MastraError(\n {\n id: 'STORAGE_QDRANT_VECTOR_UPDATE_VECTOR_FAILED',\n domain: ErrorDomain.STORAGE,\n category: ErrorCategory.THIRD_PARTY,\n details: {\n indexName,\n ...(id && { id }),\n ...(filter && { filter: JSON.stringify(filter) }),\n },\n },\n error,\n );\n }\n }\n\n /**\n * Deletes a vector by its ID.\n * @param indexName - The name of the index containing the vector.\n * @param id - The ID of the vector to delete.\n * @returns A promise that resolves when the deletion is complete.\n * @throws Will throw an error if the deletion operation fails.\n */\n async deleteVector({ indexName, id }: DeleteVectorParams): Promise<void> {\n try {\n // Parse the ID - Qdrant supports both string and numeric IDs\n const pointId = this.parsePointId(id);\n\n // Use the Qdrant client to delete the point from the collection\n await this.client.delete(indexName, {\n points: [pointId],\n });\n } catch (error) {\n throw new MastraError(\n {\n id: 'STORAGE_QDRANT_VECTOR_DELETE_VECTOR_FAILED',\n domain: ErrorDomain.STORAGE,\n category: ErrorCategory.THIRD_PARTY,\n details: {\n indexName,\n ...(id && { id }),\n },\n },\n error,\n );\n }\n }\n\n /**\n * Parses and converts a string ID to the appropriate type (string or number) for Qdrant point operations.\n *\n * Qdrant supports both numeric and string IDs. This helper method ensures IDs are in the correct format\n * before sending them to the Qdrant client API.\n *\n * @param id - The ID string to parse\n * @returns The parsed ID as either a number (if string contains only digits) or the original string\n *\n * @example\n * // Numeric ID strings are converted to numbers\n * parsePointId(\"123\") => 123\n * parsePointId(\"42\") => 42\n * parsePointId(\"0\") => 0\n *\n * // String IDs containing any non-digit characters remain as strings\n * parsePointId(\"doc-123\") => \"doc-123\"\n * parsePointId(\"user_42\") => \"user_42\"\n * parsePointId(\"abc123\") => \"abc123\"\n * parsePointId(\"123abc\") => \"123abc\"\n * parsePointId(\"\") => \"\"\n * parsePointId(\"uuid-5678-xyz\") => \"uuid-5678-xyz\"\n *\n * @remarks\n * - This conversion is important because Qdrant treats numeric and string IDs differently\n * - Only positive integers are converted to numbers (negative numbers with minus signs remain strings)\n * - The method uses base-10 parsing, so leading zeros will be dropped in numeric conversions\n * - reference: https://qdrant.tech/documentation/concepts/points/?q=qdrant+point+id#point-ids\n */\n private parsePointId(id: string): string | number {\n // Try to parse as number if it looks like one\n if (/^\\d+$/.test(id)) {\n return parseInt(id, 10);\n }\n return id;\n }\n\n /**\n * Deletes multiple vectors by IDs or filter.\n * @param indexName - The name of the index containing the vectors.\n * @param ids - Array of vector IDs to delete (mutually exclusive with filter).\n * @param filter - Filter to match vectors to delete (mutually exclusive with ids).\n * @returns A promise that resolves when the deletion is complete.\n * @throws Will throw an error if both ids and filter are provided, or if neither is provided.\n */\n async deleteVectors({ indexName, filter, ids }: DeleteVectorsParams<QdrantVectorFilter>): Promise<void> {\n // Validate mutually exclusive parameters\n if (ids && filter) {\n throw new MastraError({\n id: 'STORAGE_QDRANT_VECTOR_DELETE_VECTORS_MUTUALLY_EXCLUSIVE',\n text: 'Cannot specify both ids and filter - they are mutually exclusive',\n domain: ErrorDomain.STORAGE,\n category: ErrorCategory.USER,\n details: { indexName },\n });\n }\n\n if (!ids && !filter) {\n throw new MastraError({\n id: 'STORAGE_QDRANT_VECTOR_DELETE_VECTORS_NO_TARGET',\n text: 'Either filter or ids must be provided',\n domain: ErrorDomain.STORAGE,\n category: ErrorCategory.USER,\n details: { indexName },\n });\n }\n\n // Validate ids array is not empty\n if (ids && ids.length === 0) {\n throw new MastraError({\n id: 'STORAGE_QDRANT_VECTOR_DELETE_VECTORS_EMPTY_IDS',\n text: 'Cannot delete with empty ids array',\n domain: ErrorDomain.STORAGE,\n category: ErrorCategory.USER,\n details: { indexName },\n });\n }\n\n // Validate filter is not empty\n if (filter && Object.keys(filter).length === 0) {\n throw new MastraError({\n id: 'STORAGE_QDRANT_VECTOR_DELETE_VECTORS_EMPTY_FILTER',\n text: 'Cannot delete with empty filter object',\n domain: ErrorDomain.STORAGE,\n category: ErrorCategory.USER,\n details: { indexName },\n });\n }\n\n try {\n if (ids) {\n // Delete by IDs - parse all IDs to support both string and numeric formats\n const pointIds = ids.map(id => this.parsePointId(id));\n try {\n await this.client.delete(indexName, {\n points: pointIds,\n wait: true,\n });\n } catch (error: any) {\n // Qdrant throws \"Bad Request\" when trying to delete non-existent IDs\n // This is expected behavior and should be handled gracefully\n const message = error?.message || error?.toString() || '';\n if (message.toLowerCase().includes('bad request')) {\n // Silently ignore - deleting non-existent IDs is not an error\n return;\n }\n throw error;\n }\n } else if (filter) {\n // Delete by filter\n const translatedFilter = this.transformFilter(filter) ?? {};\n await this.client.delete(indexName, {\n filter: translatedFilter as any,\n wait: true,\n });\n }\n } catch (error) {\n if (error instanceof MastraError) throw error;\n throw new MastraError(\n {\n id: 'STORAGE_QDRANT_VECTOR_DELETE_VECTORS_FAILED',\n domain: ErrorDomain.STORAGE,\n category: ErrorCategory.THIRD_PARTY,\n details: {\n indexName,\n ...(filter && { filter: JSON.stringify(filter) }),\n ...(ids && { idsCount: ids.length }),\n },\n },\n error,\n );\n }\n }\n}\n","/**\n * Vector store specific prompt that details supported operators and examples.\n * This prompt helps users construct valid filters for Qdrant Vector.\n */\nexport const QDRANT_PROMPT = `When querying Qdrant, you can ONLY use the operators listed below. Any other operators will be rejected.\nImportant: Don't explain how to construct the filter - use the specified operators and fields to search the content and return relevant results.\nIf a user tries to give an explicit operator that is not supported, reject the filter entirely and let them know that the operator is not supported.\n\nBasic Comparison Operators:\n- $eq: Exact match (default when using field: value)\n Example: { \"category\": \"electronics\" }\n- $ne: Not equal\n Example: { \"category\": { \"$ne\": \"electronics\" } }\n- $gt: Greater than\n Example: { \"price\": { \"$gt\": 100 } }\n- $gte: Greater than or equal\n Example: { \"price\": { \"$gte\": 100 } }\n- $lt: Less than\n Example: { \"price\": { \"$lt\": 100 } }\n- $lte: Less than or equal\n Example: { \"price\": { \"$lte\": 100 } }\n\nArray Operators:\n- $in: Match any value in array\n Example: { \"category\": { \"$in\": [\"electronics\", \"books\"] } }\n- $nin: Does not match any value in array\n Example: { \"category\": { \"$nin\": [\"electronics\", \"books\"] } }\n\nLogical Operators:\n- $and: Logical AND (can be implicit or explicit)\n Implicit Example: { \"price\": { \"$gt\": 100 }, \"category\": \"electronics\" }\n Explicit Example: { \"$and\": [{ \"price\": { \"$gt\": 100 } }, { \"category\": \"electronics\" }] }\n- $or: Logical OR\n Example: { \"$or\": [{ \"price\": { \"$lt\": 50 } }, { \"category\": \"books\" }] }\n- $not: Logical NOT\n Example: { \"$not\": { \"category\": \"electronics\" } }\n\nElement Operators:\n- $exists: Check if field exists\n Example: { \"rating\": { \"$exists\": true } }\n- $match: Match text using full-text search\n Example: { \"description\": { \"$match\": \"gaming laptop\" } }\n- $null: Check if field is null\n Example: { \"rating\": { \"$null\": true } }\n\nRestrictions:\n- Regex patterns are not supported\n- Only $and, $or, and $not logical operators are supported at the top level\n- Empty arrays in $in/$nin will return no results\n- Nested fields are supported using dot notation\n- Multiple conditions on the same field are supported with both implicit and explicit $and\n- At least one key-value pair is required in filter object\n- Empty objects and undefined values are treated as no filter\n- Invalid types in comparison operators will throw errors\n- All non-logical operators must be used within a field condition\n Valid: { \"field\": { \"$gt\": 100 } }\n Valid: { \"$and\": [...] }\n Invalid: { \"$gt\": 100 }\n- Logical operators must contain field conditions, not direct operators\n Valid: { \"$and\": [{ \"field\": { \"$gt\": 100 } }] }\n Invalid: { \"$and\": [{ \"$gt\": 100 }] }\n- Logical operators ($and, $or, $not):\n - Can only be used at top level or nested within other logical operators\n - Can not be used on a field level, or be nested inside a field\n - Can not be used inside an operator\n - Valid: { \"$and\": [{ \"field\": { \"$gt\": 100 } }] }\n - Valid: { \"$or\": [{ \"$and\": [{ \"field\": { \"$gt\": 100 } }] }] }\n - Invalid: { \"field\": { \"$and\": [{ \"$gt\": 100 }] } }\n - Invalid: { \"field\": { \"$or\": [{ \"$gt\": 100 }] } }\n - Invalid: { \"field\": { \"$gt\": { \"$and\": [{...}] } } }\n\nExample Complex Query:\n{\n \"$and\": [\n { \"category\": { \"$in\": [\"electronics\", \"computers\"] } },\n { \"price\": { \"$gte\": 100, \"$lte\": 1000 } },\n { \"description\": { \"$match\": \"gaming laptop\" } },\n { \"rating\": { \"$exists\": true, \"$gt\": 4 } },\n { \"$or\": [\n { \"stock\": { \"$gt\": 0 } },\n { \"preorder\": { \"$null\": false } }\n ]},\n { \"$not\": { \"status\": \"discontinued\" } }\n ]\n}`;\n"]}
|
package/dist/vector/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { MastraVector } from '@mastra/core/vector';
|
|
2
|
-
import type { QueryResult, IndexStats, CreateIndexParams, UpsertVectorParams, QueryVectorParams, DescribeIndexParams, DeleteIndexParams, DeleteVectorParams, UpdateVectorParams } from '@mastra/core/vector';
|
|
2
|
+
import type { QueryResult, IndexStats, CreateIndexParams, UpsertVectorParams, QueryVectorParams, DescribeIndexParams, DeleteIndexParams, DeleteVectorParams, UpdateVectorParams, DeleteVectorsParams } from '@mastra/core/vector';
|
|
3
3
|
import type { QdrantClientParams } from '@qdrant/js-client-rest';
|
|
4
4
|
import type { QdrantVectorFilter } from './filter.js';
|
|
5
5
|
type QdrantQueryVectorParams = QueryVectorParams<QdrantVectorFilter>;
|
|
@@ -29,16 +29,17 @@ export declare class QdrantVector extends MastraVector {
|
|
|
29
29
|
describeIndex({ indexName }: DescribeIndexParams): Promise<IndexStats>;
|
|
30
30
|
deleteIndex({ indexName }: DeleteIndexParams): Promise<void>;
|
|
31
31
|
/**
|
|
32
|
-
* Updates a vector by its ID
|
|
33
|
-
* @param indexName - The name of the index containing the vector.
|
|
34
|
-
* @param id - The ID of the vector to update.
|
|
32
|
+
* Updates a vector by its ID or multiple vectors matching a filter.
|
|
33
|
+
* @param indexName - The name of the index containing the vector(s).
|
|
34
|
+
* @param id - The ID of the vector to update (mutually exclusive with filter).
|
|
35
|
+
* @param filter - Filter to match multiple vectors to update (mutually exclusive with id).
|
|
35
36
|
* @param update - An object containing the vector and/or metadata to update.
|
|
36
37
|
* @param update.vector - An optional array of numbers representing the new vector.
|
|
37
38
|
* @param update.metadata - An optional record containing the new metadata.
|
|
38
39
|
* @returns A promise that resolves when the update is complete.
|
|
39
40
|
* @throws Will throw an error if no updates are provided or if the update operation fails.
|
|
40
41
|
*/
|
|
41
|
-
updateVector({ indexName, id, update }: UpdateVectorParams): Promise<void>;
|
|
42
|
+
updateVector({ indexName, id, filter, update }: UpdateVectorParams<QdrantVectorFilter>): Promise<void>;
|
|
42
43
|
/**
|
|
43
44
|
* Deletes a vector by its ID.
|
|
44
45
|
* @param indexName - The name of the index containing the vector.
|
|
@@ -77,6 +78,15 @@ export declare class QdrantVector extends MastraVector {
|
|
|
77
78
|
* - reference: https://qdrant.tech/documentation/concepts/points/?q=qdrant+point+id#point-ids
|
|
78
79
|
*/
|
|
79
80
|
private parsePointId;
|
|
81
|
+
/**
|
|
82
|
+
* Deletes multiple vectors by IDs or filter.
|
|
83
|
+
* @param indexName - The name of the index containing the vectors.
|
|
84
|
+
* @param ids - Array of vector IDs to delete (mutually exclusive with filter).
|
|
85
|
+
* @param filter - Filter to match vectors to delete (mutually exclusive with ids).
|
|
86
|
+
* @returns A promise that resolves when the deletion is complete.
|
|
87
|
+
* @throws Will throw an error if both ids and filter are provided, or if neither is provided.
|
|
88
|
+
*/
|
|
89
|
+
deleteVectors({ indexName, filter, ids }: DeleteVectorsParams<QdrantVectorFilter>): Promise<void>;
|
|
80
90
|
}
|
|
81
91
|
export {};
|
|
82
92
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/vector/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACnD,OAAO,KAAK,EACV,WAAW,EACX,UAAU,EACV,iBAAiB,EACjB,kBAAkB,EAClB,iBAAiB,EACjB,mBAAmB,EACnB,iBAAiB,EACjB,kBAAkB,EAClB,kBAAkB,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/vector/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACnD,OAAO,KAAK,EACV,WAAW,EACX,UAAU,EACV,iBAAiB,EACjB,kBAAkB,EAClB,iBAAiB,EACjB,mBAAmB,EACnB,iBAAiB,EACjB,kBAAkB,EAClB,kBAAkB,EAClB,mBAAmB,EACpB,MAAM,qBAAqB,CAAC;AAE7B,OAAO,KAAK,EAAE,kBAAkB,EAAW,MAAM,wBAAwB,CAAC;AAG1E,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,UAAU,CAAC;AASnD,KAAK,uBAAuB,GAAG,iBAAiB,CAAC,kBAAkB,CAAC,CAAC;AAErE,qBAAa,YAAa,SAAQ,YAAY;IAC5C,OAAO,CAAC,MAAM,CAAe;IAE7B;;;;;;OAMG;gBACS,EAAE,EAAE,EAAE,GAAG,YAAY,EAAE,EAAE,kBAAkB,GAAG;QAA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
|
2
2
|
"name": "@mastra/qdrant",
|
|
3
|
-
"version": "1.0.0-beta.
|
|
3
|
+
"version": "1.0.0-beta.1",
|
|
4
4
|
"description": "Qdrant vector store provider for Mastra",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -24,15 +24,17 @@
|
|
|
24
24
|
},
|
|
25
25
|
"devDependencies": {
|
|
26
26
|
"@microsoft/api-extractor": "^7.52.8",
|
|
27
|
-
"@types/node": "
|
|
27
|
+
"@types/node": "22.13.17",
|
|
28
|
+
"@vitest/coverage-v8": "4.0.12",
|
|
29
|
+
"@vitest/ui": "4.0.12",
|
|
28
30
|
"eslint": "^9.37.0",
|
|
29
31
|
"tsup": "^8.5.0",
|
|
30
32
|
"typescript": "^5.8.3",
|
|
31
|
-
"vitest": "
|
|
33
|
+
"vitest": "4.0.12",
|
|
32
34
|
"@internal/lint": "0.0.53",
|
|
33
|
-
"@
|
|
35
|
+
"@internal/storage-test-utils": "0.0.49",
|
|
34
36
|
"@internal/types-builder": "0.0.28",
|
|
35
|
-
"@
|
|
37
|
+
"@mastra/core": "1.0.0-beta.5"
|
|
36
38
|
},
|
|
37
39
|
"peerDependencies": {
|
|
38
40
|
"@mastra/core": ">=1.0.0-0 <2.0.0-0"
|
|
@@ -56,6 +58,8 @@
|
|
|
56
58
|
"scripts": {
|
|
57
59
|
"build": "tsup --silent --config tsup.config.ts",
|
|
58
60
|
"build:watch": "tsup --watch --silent --config tsup.config.ts",
|
|
61
|
+
"pretest": "docker compose up -d",
|
|
62
|
+
"posttest": "docker compose down -v",
|
|
59
63
|
"test": "vitest run",
|
|
60
64
|
"lint": "eslint ."
|
|
61
65
|
}
|