@mastra/qdrant 0.2.14 → 0.3.0-alpha.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/.turbo/turbo-build.log +7 -7
- package/CHANGELOG.md +35 -0
- package/dist/_tsup-dts-rollup.d.cts +25 -35
- package/dist/_tsup-dts-rollup.d.ts +25 -35
- package/dist/index.cjs +26 -51
- package/dist/index.js +26 -51
- package/package.json +7 -4
- package/src/vector/index.test.ts +26 -119
- package/src/vector/index.ts +30 -73
package/.turbo/turbo-build.log
CHANGED
|
@@ -1,23 +1,23 @@
|
|
|
1
1
|
|
|
2
|
-
> @mastra/qdrant@0.
|
|
2
|
+
> @mastra/qdrant@0.3.0-alpha.1 build /home/runner/work/mastra/mastra/stores/qdrant
|
|
3
3
|
> tsup src/index.ts --format esm,cjs --experimental-dts --clean --treeshake=smallest --splitting
|
|
4
4
|
|
|
5
5
|
[34mCLI[39m Building entry: src/index.ts
|
|
6
6
|
[34mCLI[39m Using tsconfig: tsconfig.json
|
|
7
7
|
[34mCLI[39m tsup v8.4.0
|
|
8
8
|
[34mTSC[39m Build start
|
|
9
|
-
[32mTSC[39m ⚡️ Build success in
|
|
9
|
+
[32mTSC[39m ⚡️ Build success in 7797ms
|
|
10
10
|
[34mDTS[39m Build start
|
|
11
11
|
[34mCLI[39m Target: es2022
|
|
12
12
|
Analysis will use the bundled TypeScript version 5.8.3
|
|
13
13
|
[36mWriting package typings: /home/runner/work/mastra/mastra/stores/qdrant/dist/_tsup-dts-rollup.d.ts[39m
|
|
14
14
|
Analysis will use the bundled TypeScript version 5.8.3
|
|
15
15
|
[36mWriting package typings: /home/runner/work/mastra/mastra/stores/qdrant/dist/_tsup-dts-rollup.d.cts[39m
|
|
16
|
-
[32mDTS[39m ⚡️ Build success in
|
|
16
|
+
[32mDTS[39m ⚡️ Build success in 8110ms
|
|
17
17
|
[34mCLI[39m Cleaning output folder
|
|
18
18
|
[34mESM[39m Build start
|
|
19
19
|
[34mCJS[39m Build start
|
|
20
|
-
[32mESM[39m [1mdist/index.js [22m[
|
|
21
|
-
[32mESM[39m ⚡️ Build success in
|
|
22
|
-
[32mCJS[39m [1mdist/index.cjs [22m[
|
|
23
|
-
[32mCJS[39m ⚡️ Build success in
|
|
20
|
+
[32mESM[39m [1mdist/index.js [22m[32m18.24 KB[39m
|
|
21
|
+
[32mESM[39m ⚡️ Build success in 782ms
|
|
22
|
+
[32mCJS[39m [1mdist/index.cjs [22m[32m18.30 KB[39m
|
|
23
|
+
[32mCJS[39m ⚡️ Build success in 783ms
|
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,40 @@
|
|
|
1
1
|
# @mastra/qdrant
|
|
2
2
|
|
|
3
|
+
## 0.3.0-alpha.1
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 83da932: Move @mastra/core to peerdeps
|
|
8
|
+
|
|
9
|
+
### Patch Changes
|
|
10
|
+
|
|
11
|
+
- a7292b0: BREAKING(@mastra/core, all vector stores): Vector store breaking changes (remove deprecated functions and positional arguments)
|
|
12
|
+
- Updated dependencies [b3a3d63]
|
|
13
|
+
- Updated dependencies [344f453]
|
|
14
|
+
- Updated dependencies [0a3ae6d]
|
|
15
|
+
- Updated dependencies [95911be]
|
|
16
|
+
- Updated dependencies [5eb5a99]
|
|
17
|
+
- Updated dependencies [7e632c5]
|
|
18
|
+
- Updated dependencies [1e9fbfa]
|
|
19
|
+
- Updated dependencies [b2ae5aa]
|
|
20
|
+
- Updated dependencies [a7292b0]
|
|
21
|
+
- Updated dependencies [0dcb9f0]
|
|
22
|
+
- @mastra/core@0.10.0-alpha.1
|
|
23
|
+
|
|
24
|
+
## 0.2.15-alpha.0
|
|
25
|
+
|
|
26
|
+
### Patch Changes
|
|
27
|
+
|
|
28
|
+
- d0ee3c6: Change all public functions and constructors in vector stores to use named args and prepare to phase out positional args
|
|
29
|
+
- Updated dependencies [f53a6ac]
|
|
30
|
+
- Updated dependencies [eabdcd9]
|
|
31
|
+
- Updated dependencies [90be034]
|
|
32
|
+
- Updated dependencies [99f050a]
|
|
33
|
+
- Updated dependencies [d0ee3c6]
|
|
34
|
+
- Updated dependencies [23f258c]
|
|
35
|
+
- Updated dependencies [2672a05]
|
|
36
|
+
- @mastra/core@0.9.5-alpha.0
|
|
37
|
+
|
|
3
38
|
## 0.2.14
|
|
4
39
|
|
|
5
40
|
### Patch Changes
|
|
@@ -1,12 +1,15 @@
|
|
|
1
1
|
import { BaseFilterTranslator } from '@mastra/core/vector/filter';
|
|
2
2
|
import type { CreateIndexParams } from '@mastra/core/vector';
|
|
3
|
+
import type { DeleteIndexParams } from '@mastra/core/vector';
|
|
4
|
+
import type { DeleteVectorParams } from '@mastra/core/vector';
|
|
5
|
+
import type { DescribeIndexParams } from '@mastra/core/vector';
|
|
3
6
|
import type { IndexStats } from '@mastra/core/vector';
|
|
4
7
|
import type { LogicalOperator } from '@mastra/core/vector/filter';
|
|
5
8
|
import { MastraVector } from '@mastra/core/vector';
|
|
6
9
|
import type { OperatorSupport } from '@mastra/core/vector/filter';
|
|
7
|
-
import type { ParamsToArgs } from '@mastra/core/vector';
|
|
8
10
|
import type { QueryResult } from '@mastra/core/vector';
|
|
9
11
|
import type { QueryVectorParams } from '@mastra/core/vector';
|
|
12
|
+
import type { UpdateVectorParams } from '@mastra/core/vector';
|
|
10
13
|
import type { UpsertVectorParams } from '@mastra/core/vector';
|
|
11
14
|
import type { VectorFilter } from '@mastra/core/vector/filter';
|
|
12
15
|
|
|
@@ -55,30 +58,30 @@ export declare class QdrantFilterTranslator extends BaseFilterTranslator {
|
|
|
55
58
|
|
|
56
59
|
declare class QdrantVector extends MastraVector {
|
|
57
60
|
private client;
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
+
/**
|
|
62
|
+
* Creates a new QdrantVector client.
|
|
63
|
+
* @param url - The URL of the Qdrant server.
|
|
64
|
+
* @param apiKey - The API key for Qdrant.
|
|
65
|
+
* @param https - Whether to use HTTPS.
|
|
66
|
+
*/
|
|
67
|
+
constructor({ url, apiKey, https }: {
|
|
68
|
+
url: string;
|
|
69
|
+
apiKey?: string;
|
|
70
|
+
https?: boolean;
|
|
71
|
+
});
|
|
72
|
+
upsert({ indexName, vectors, metadata, ids }: UpsertVectorParams): Promise<string[]>;
|
|
73
|
+
createIndex({ indexName, dimension, metric }: CreateIndexParams): Promise<void>;
|
|
61
74
|
transformFilter(filter?: VectorFilter): VectorFilter;
|
|
62
|
-
query(
|
|
75
|
+
query({ indexName, queryVector, topK, filter, includeVector, }: QueryVectorParams): Promise<QueryResult[]>;
|
|
63
76
|
listIndexes(): Promise<string[]>;
|
|
64
|
-
describeIndex(indexName: string): Promise<IndexStats>;
|
|
65
|
-
deleteIndex(indexName: string): Promise<void>;
|
|
66
77
|
/**
|
|
67
|
-
*
|
|
78
|
+
* Retrieves statistics about a vector index.
|
|
68
79
|
*
|
|
69
|
-
*
|
|
70
|
-
* @
|
|
71
|
-
* @param id - The ID of the vector to update.
|
|
72
|
-
* @param update - An object containing the vector and/or metadata to update.
|
|
73
|
-
* @param update.vector - An optional array of numbers representing the new vector.
|
|
74
|
-
* @param update.metadata - An optional record containing the new metadata.
|
|
75
|
-
* @returns A promise that resolves when the update is complete.
|
|
76
|
-
* @throws Will throw an error if no updates are provided or if the update operation fails.
|
|
80
|
+
* @param {string} indexName - The name of the index to describe
|
|
81
|
+
* @returns A promise that resolves to the index statistics including dimension, count and metric
|
|
77
82
|
*/
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
metadata?: Record<string, any>;
|
|
81
|
-
}): Promise<void>;
|
|
83
|
+
describeIndex({ indexName }: DescribeIndexParams): Promise<IndexStats>;
|
|
84
|
+
deleteIndex({ indexName }: DeleteIndexParams): Promise<void>;
|
|
82
85
|
/**
|
|
83
86
|
* Updates a vector by its ID with the provided vector and/or metadata.
|
|
84
87
|
* @param indexName - The name of the index containing the vector.
|
|
@@ -89,20 +92,7 @@ declare class QdrantVector extends MastraVector {
|
|
|
89
92
|
* @returns A promise that resolves when the update is complete.
|
|
90
93
|
* @throws Will throw an error if no updates are provided or if the update operation fails.
|
|
91
94
|
*/
|
|
92
|
-
updateVector(indexName
|
|
93
|
-
vector?: number[];
|
|
94
|
-
metadata?: Record<string, any>;
|
|
95
|
-
}): Promise<void>;
|
|
96
|
-
/**
|
|
97
|
-
* @deprecated Use {@link deleteVector} instead. This method will be removed on May 20th, 2025.
|
|
98
|
-
*
|
|
99
|
-
* Deletes a vector by its ID.
|
|
100
|
-
* @param indexName - The name of the index containing the vector.
|
|
101
|
-
* @param id - The ID of the vector to delete.
|
|
102
|
-
* @returns A promise that resolves when the deletion is complete.
|
|
103
|
-
* @throws Will throw an error if the deletion operation fails.
|
|
104
|
-
*/
|
|
105
|
-
deleteIndexById(indexName: string, id: string): Promise<void>;
|
|
95
|
+
updateVector({ indexName, id, update }: UpdateVectorParams): Promise<void>;
|
|
106
96
|
/**
|
|
107
97
|
* Deletes a vector by its ID.
|
|
108
98
|
* @param indexName - The name of the index containing the vector.
|
|
@@ -110,7 +100,7 @@ declare class QdrantVector extends MastraVector {
|
|
|
110
100
|
* @returns A promise that resolves when the deletion is complete.
|
|
111
101
|
* @throws Will throw an error if the deletion operation fails.
|
|
112
102
|
*/
|
|
113
|
-
deleteVector(indexName
|
|
103
|
+
deleteVector({ indexName, id }: DeleteVectorParams): Promise<void>;
|
|
114
104
|
/**
|
|
115
105
|
* Parses and converts a string ID to the appropriate type (string or number) for Qdrant point operations.
|
|
116
106
|
*
|
|
@@ -1,12 +1,15 @@
|
|
|
1
1
|
import { BaseFilterTranslator } from '@mastra/core/vector/filter';
|
|
2
2
|
import type { CreateIndexParams } from '@mastra/core/vector';
|
|
3
|
+
import type { DeleteIndexParams } from '@mastra/core/vector';
|
|
4
|
+
import type { DeleteVectorParams } from '@mastra/core/vector';
|
|
5
|
+
import type { DescribeIndexParams } from '@mastra/core/vector';
|
|
3
6
|
import type { IndexStats } from '@mastra/core/vector';
|
|
4
7
|
import type { LogicalOperator } from '@mastra/core/vector/filter';
|
|
5
8
|
import { MastraVector } from '@mastra/core/vector';
|
|
6
9
|
import type { OperatorSupport } from '@mastra/core/vector/filter';
|
|
7
|
-
import type { ParamsToArgs } from '@mastra/core/vector';
|
|
8
10
|
import type { QueryResult } from '@mastra/core/vector';
|
|
9
11
|
import type { QueryVectorParams } from '@mastra/core/vector';
|
|
12
|
+
import type { UpdateVectorParams } from '@mastra/core/vector';
|
|
10
13
|
import type { UpsertVectorParams } from '@mastra/core/vector';
|
|
11
14
|
import type { VectorFilter } from '@mastra/core/vector/filter';
|
|
12
15
|
|
|
@@ -55,30 +58,30 @@ export declare class QdrantFilterTranslator extends BaseFilterTranslator {
|
|
|
55
58
|
|
|
56
59
|
declare class QdrantVector extends MastraVector {
|
|
57
60
|
private client;
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
+
/**
|
|
62
|
+
* Creates a new QdrantVector client.
|
|
63
|
+
* @param url - The URL of the Qdrant server.
|
|
64
|
+
* @param apiKey - The API key for Qdrant.
|
|
65
|
+
* @param https - Whether to use HTTPS.
|
|
66
|
+
*/
|
|
67
|
+
constructor({ url, apiKey, https }: {
|
|
68
|
+
url: string;
|
|
69
|
+
apiKey?: string;
|
|
70
|
+
https?: boolean;
|
|
71
|
+
});
|
|
72
|
+
upsert({ indexName, vectors, metadata, ids }: UpsertVectorParams): Promise<string[]>;
|
|
73
|
+
createIndex({ indexName, dimension, metric }: CreateIndexParams): Promise<void>;
|
|
61
74
|
transformFilter(filter?: VectorFilter): VectorFilter;
|
|
62
|
-
query(
|
|
75
|
+
query({ indexName, queryVector, topK, filter, includeVector, }: QueryVectorParams): Promise<QueryResult[]>;
|
|
63
76
|
listIndexes(): Promise<string[]>;
|
|
64
|
-
describeIndex(indexName: string): Promise<IndexStats>;
|
|
65
|
-
deleteIndex(indexName: string): Promise<void>;
|
|
66
77
|
/**
|
|
67
|
-
*
|
|
78
|
+
* Retrieves statistics about a vector index.
|
|
68
79
|
*
|
|
69
|
-
*
|
|
70
|
-
* @
|
|
71
|
-
* @param id - The ID of the vector to update.
|
|
72
|
-
* @param update - An object containing the vector and/or metadata to update.
|
|
73
|
-
* @param update.vector - An optional array of numbers representing the new vector.
|
|
74
|
-
* @param update.metadata - An optional record containing the new metadata.
|
|
75
|
-
* @returns A promise that resolves when the update is complete.
|
|
76
|
-
* @throws Will throw an error if no updates are provided or if the update operation fails.
|
|
80
|
+
* @param {string} indexName - The name of the index to describe
|
|
81
|
+
* @returns A promise that resolves to the index statistics including dimension, count and metric
|
|
77
82
|
*/
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
metadata?: Record<string, any>;
|
|
81
|
-
}): Promise<void>;
|
|
83
|
+
describeIndex({ indexName }: DescribeIndexParams): Promise<IndexStats>;
|
|
84
|
+
deleteIndex({ indexName }: DeleteIndexParams): Promise<void>;
|
|
82
85
|
/**
|
|
83
86
|
* Updates a vector by its ID with the provided vector and/or metadata.
|
|
84
87
|
* @param indexName - The name of the index containing the vector.
|
|
@@ -89,20 +92,7 @@ declare class QdrantVector extends MastraVector {
|
|
|
89
92
|
* @returns A promise that resolves when the update is complete.
|
|
90
93
|
* @throws Will throw an error if no updates are provided or if the update operation fails.
|
|
91
94
|
*/
|
|
92
|
-
updateVector(indexName
|
|
93
|
-
vector?: number[];
|
|
94
|
-
metadata?: Record<string, any>;
|
|
95
|
-
}): Promise<void>;
|
|
96
|
-
/**
|
|
97
|
-
* @deprecated Use {@link deleteVector} instead. This method will be removed on May 20th, 2025.
|
|
98
|
-
*
|
|
99
|
-
* Deletes a vector by its ID.
|
|
100
|
-
* @param indexName - The name of the index containing the vector.
|
|
101
|
-
* @param id - The ID of the vector to delete.
|
|
102
|
-
* @returns A promise that resolves when the deletion is complete.
|
|
103
|
-
* @throws Will throw an error if the deletion operation fails.
|
|
104
|
-
*/
|
|
105
|
-
deleteIndexById(indexName: string, id: string): Promise<void>;
|
|
95
|
+
updateVector({ indexName, id, update }: UpdateVectorParams): Promise<void>;
|
|
106
96
|
/**
|
|
107
97
|
* Deletes a vector by its ID.
|
|
108
98
|
* @param indexName - The name of the index containing the vector.
|
|
@@ -110,7 +100,7 @@ declare class QdrantVector extends MastraVector {
|
|
|
110
100
|
* @returns A promise that resolves when the deletion is complete.
|
|
111
101
|
* @throws Will throw an error if the deletion operation fails.
|
|
112
102
|
*/
|
|
113
|
-
deleteVector(indexName
|
|
103
|
+
deleteVector({ indexName, id }: DeleteVectorParams): Promise<void>;
|
|
114
104
|
/**
|
|
115
105
|
* Parses and converts a string ID to the appropriate type (string or number) for Qdrant point operations.
|
|
116
106
|
*
|
package/dist/index.cjs
CHANGED
|
@@ -239,7 +239,13 @@ var DISTANCE_MAPPING = {
|
|
|
239
239
|
};
|
|
240
240
|
var QdrantVector = class extends vector.MastraVector {
|
|
241
241
|
client;
|
|
242
|
-
|
|
242
|
+
/**
|
|
243
|
+
* Creates a new QdrantVector client.
|
|
244
|
+
* @param url - The URL of the Qdrant server.
|
|
245
|
+
* @param apiKey - The API key for Qdrant.
|
|
246
|
+
* @param https - Whether to use HTTPS.
|
|
247
|
+
*/
|
|
248
|
+
constructor({ url, apiKey, https }) {
|
|
243
249
|
super();
|
|
244
250
|
const baseClient = new jsClientRest.QdrantClient({
|
|
245
251
|
url,
|
|
@@ -254,9 +260,7 @@ var QdrantVector = class extends vector.MastraVector {
|
|
|
254
260
|
}
|
|
255
261
|
}) ?? baseClient;
|
|
256
262
|
}
|
|
257
|
-
async upsert(
|
|
258
|
-
const params = this.normalizeArgs("upsert", args);
|
|
259
|
-
const { indexName, vectors, metadata, ids } = params;
|
|
263
|
+
async upsert({ indexName, vectors, metadata, ids }) {
|
|
260
264
|
const pointIds = ids || vectors.map(() => crypto.randomUUID());
|
|
261
265
|
const records = vectors.map((vector, i) => ({
|
|
262
266
|
id: pointIds[i],
|
|
@@ -273,9 +277,7 @@ var QdrantVector = class extends vector.MastraVector {
|
|
|
273
277
|
}
|
|
274
278
|
return pointIds;
|
|
275
279
|
}
|
|
276
|
-
async createIndex(
|
|
277
|
-
const params = this.normalizeArgs("createIndex", args);
|
|
278
|
-
const { indexName, dimension, metric = "cosine" } = params;
|
|
280
|
+
async createIndex({ indexName, dimension, metric = "cosine" }) {
|
|
279
281
|
if (!Number.isInteger(dimension) || dimension <= 0) {
|
|
280
282
|
throw new Error("Dimension must be a positive integer");
|
|
281
283
|
}
|
|
@@ -301,9 +303,13 @@ var QdrantVector = class extends vector.MastraVector {
|
|
|
301
303
|
const translator = new QdrantFilterTranslator();
|
|
302
304
|
return translator.translate(filter);
|
|
303
305
|
}
|
|
304
|
-
async query(
|
|
305
|
-
|
|
306
|
-
|
|
306
|
+
async query({
|
|
307
|
+
indexName,
|
|
308
|
+
queryVector,
|
|
309
|
+
topK = 10,
|
|
310
|
+
filter,
|
|
311
|
+
includeVector = false
|
|
312
|
+
}) {
|
|
307
313
|
const translatedFilter = this.transformFilter(filter) ?? {};
|
|
308
314
|
const results = (await this.client.query(indexName, {
|
|
309
315
|
query: queryVector,
|
|
@@ -333,7 +339,13 @@ var QdrantVector = class extends vector.MastraVector {
|
|
|
333
339
|
const response = await this.client.getCollections();
|
|
334
340
|
return response.collections.map((collection) => collection.name) || [];
|
|
335
341
|
}
|
|
336
|
-
|
|
342
|
+
/**
|
|
343
|
+
* Retrieves statistics about a vector index.
|
|
344
|
+
*
|
|
345
|
+
* @param {string} indexName - The name of the index to describe
|
|
346
|
+
* @returns A promise that resolves to the index statistics including dimension, count and metric
|
|
347
|
+
*/
|
|
348
|
+
async describeIndex({ indexName }) {
|
|
337
349
|
const { config, points_count } = await this.client.getCollection(indexName);
|
|
338
350
|
const distance = config.params.vectors?.distance;
|
|
339
351
|
return {
|
|
@@ -343,29 +355,9 @@ var QdrantVector = class extends vector.MastraVector {
|
|
|
343
355
|
metric: Object.keys(DISTANCE_MAPPING).find((key) => DISTANCE_MAPPING[key] === distance)
|
|
344
356
|
};
|
|
345
357
|
}
|
|
346
|
-
async deleteIndex(indexName) {
|
|
358
|
+
async deleteIndex({ indexName }) {
|
|
347
359
|
await this.client.deleteCollection(indexName);
|
|
348
360
|
}
|
|
349
|
-
/**
|
|
350
|
-
* @deprecated Use {@link updateVector} instead. This method will be removed on May 20th, 2025.
|
|
351
|
-
*
|
|
352
|
-
* Updates a vector by its ID with the provided vector and/or metadata.
|
|
353
|
-
* @param indexName - The name of the index containing the vector.
|
|
354
|
-
* @param id - The ID of the vector to update.
|
|
355
|
-
* @param update - An object containing the vector and/or metadata to update.
|
|
356
|
-
* @param update.vector - An optional array of numbers representing the new vector.
|
|
357
|
-
* @param update.metadata - An optional record containing the new metadata.
|
|
358
|
-
* @returns A promise that resolves when the update is complete.
|
|
359
|
-
* @throws Will throw an error if no updates are provided or if the update operation fails.
|
|
360
|
-
*/
|
|
361
|
-
async updateIndexById(indexName, id, update) {
|
|
362
|
-
this.logger.warn(
|
|
363
|
-
`Deprecation Warning: updateIndexById() is deprecated.
|
|
364
|
-
Please use updateVector() instead.
|
|
365
|
-
updateIndexById() will be removed on May 20th, 2025.`
|
|
366
|
-
);
|
|
367
|
-
await this.updateVector(indexName, id, update);
|
|
368
|
-
}
|
|
369
361
|
/**
|
|
370
362
|
* Updates a vector by its ID with the provided vector and/or metadata.
|
|
371
363
|
* @param indexName - The name of the index containing the vector.
|
|
@@ -376,7 +368,7 @@ var QdrantVector = class extends vector.MastraVector {
|
|
|
376
368
|
* @returns A promise that resolves when the update is complete.
|
|
377
369
|
* @throws Will throw an error if no updates are provided or if the update operation fails.
|
|
378
370
|
*/
|
|
379
|
-
async updateVector(indexName, id, update) {
|
|
371
|
+
async updateVector({ indexName, id, update }) {
|
|
380
372
|
if (!update.vector && !update.metadata) {
|
|
381
373
|
throw new Error("No updates provided");
|
|
382
374
|
}
|
|
@@ -413,23 +405,6 @@ var QdrantVector = class extends vector.MastraVector {
|
|
|
413
405
|
throw error;
|
|
414
406
|
}
|
|
415
407
|
}
|
|
416
|
-
/**
|
|
417
|
-
* @deprecated Use {@link deleteVector} instead. This method will be removed on May 20th, 2025.
|
|
418
|
-
*
|
|
419
|
-
* Deletes a vector by its ID.
|
|
420
|
-
* @param indexName - The name of the index containing the vector.
|
|
421
|
-
* @param id - The ID of the vector to delete.
|
|
422
|
-
* @returns A promise that resolves when the deletion is complete.
|
|
423
|
-
* @throws Will throw an error if the deletion operation fails.
|
|
424
|
-
*/
|
|
425
|
-
async deleteIndexById(indexName, id) {
|
|
426
|
-
this.logger.warn(
|
|
427
|
-
`Deprecation Warning: deleteIndexById() is deprecated.
|
|
428
|
-
Please use deleteVector() instead.
|
|
429
|
-
deleteIndexById() will be removed on May 20th, 2025.`
|
|
430
|
-
);
|
|
431
|
-
await this.deleteVector(indexName, id);
|
|
432
|
-
}
|
|
433
408
|
/**
|
|
434
409
|
* Deletes a vector by its ID.
|
|
435
410
|
* @param indexName - The name of the index containing the vector.
|
|
@@ -437,7 +412,7 @@ var QdrantVector = class extends vector.MastraVector {
|
|
|
437
412
|
* @returns A promise that resolves when the deletion is complete.
|
|
438
413
|
* @throws Will throw an error if the deletion operation fails.
|
|
439
414
|
*/
|
|
440
|
-
async deleteVector(indexName, id) {
|
|
415
|
+
async deleteVector({ indexName, id }) {
|
|
441
416
|
try {
|
|
442
417
|
const pointId = this.parsePointId(id);
|
|
443
418
|
await this.client.delete(indexName, {
|
package/dist/index.js
CHANGED
|
@@ -237,7 +237,13 @@ var DISTANCE_MAPPING = {
|
|
|
237
237
|
};
|
|
238
238
|
var QdrantVector = class extends MastraVector {
|
|
239
239
|
client;
|
|
240
|
-
|
|
240
|
+
/**
|
|
241
|
+
* Creates a new QdrantVector client.
|
|
242
|
+
* @param url - The URL of the Qdrant server.
|
|
243
|
+
* @param apiKey - The API key for Qdrant.
|
|
244
|
+
* @param https - Whether to use HTTPS.
|
|
245
|
+
*/
|
|
246
|
+
constructor({ url, apiKey, https }) {
|
|
241
247
|
super();
|
|
242
248
|
const baseClient = new QdrantClient({
|
|
243
249
|
url,
|
|
@@ -252,9 +258,7 @@ var QdrantVector = class extends MastraVector {
|
|
|
252
258
|
}
|
|
253
259
|
}) ?? baseClient;
|
|
254
260
|
}
|
|
255
|
-
async upsert(
|
|
256
|
-
const params = this.normalizeArgs("upsert", args);
|
|
257
|
-
const { indexName, vectors, metadata, ids } = params;
|
|
261
|
+
async upsert({ indexName, vectors, metadata, ids }) {
|
|
258
262
|
const pointIds = ids || vectors.map(() => crypto.randomUUID());
|
|
259
263
|
const records = vectors.map((vector, i) => ({
|
|
260
264
|
id: pointIds[i],
|
|
@@ -271,9 +275,7 @@ var QdrantVector = class extends MastraVector {
|
|
|
271
275
|
}
|
|
272
276
|
return pointIds;
|
|
273
277
|
}
|
|
274
|
-
async createIndex(
|
|
275
|
-
const params = this.normalizeArgs("createIndex", args);
|
|
276
|
-
const { indexName, dimension, metric = "cosine" } = params;
|
|
278
|
+
async createIndex({ indexName, dimension, metric = "cosine" }) {
|
|
277
279
|
if (!Number.isInteger(dimension) || dimension <= 0) {
|
|
278
280
|
throw new Error("Dimension must be a positive integer");
|
|
279
281
|
}
|
|
@@ -299,9 +301,13 @@ var QdrantVector = class extends MastraVector {
|
|
|
299
301
|
const translator = new QdrantFilterTranslator();
|
|
300
302
|
return translator.translate(filter);
|
|
301
303
|
}
|
|
302
|
-
async query(
|
|
303
|
-
|
|
304
|
-
|
|
304
|
+
async query({
|
|
305
|
+
indexName,
|
|
306
|
+
queryVector,
|
|
307
|
+
topK = 10,
|
|
308
|
+
filter,
|
|
309
|
+
includeVector = false
|
|
310
|
+
}) {
|
|
305
311
|
const translatedFilter = this.transformFilter(filter) ?? {};
|
|
306
312
|
const results = (await this.client.query(indexName, {
|
|
307
313
|
query: queryVector,
|
|
@@ -331,7 +337,13 @@ var QdrantVector = class extends MastraVector {
|
|
|
331
337
|
const response = await this.client.getCollections();
|
|
332
338
|
return response.collections.map((collection) => collection.name) || [];
|
|
333
339
|
}
|
|
334
|
-
|
|
340
|
+
/**
|
|
341
|
+
* Retrieves statistics about a vector index.
|
|
342
|
+
*
|
|
343
|
+
* @param {string} indexName - The name of the index to describe
|
|
344
|
+
* @returns A promise that resolves to the index statistics including dimension, count and metric
|
|
345
|
+
*/
|
|
346
|
+
async describeIndex({ indexName }) {
|
|
335
347
|
const { config, points_count } = await this.client.getCollection(indexName);
|
|
336
348
|
const distance = config.params.vectors?.distance;
|
|
337
349
|
return {
|
|
@@ -341,29 +353,9 @@ var QdrantVector = class extends MastraVector {
|
|
|
341
353
|
metric: Object.keys(DISTANCE_MAPPING).find((key) => DISTANCE_MAPPING[key] === distance)
|
|
342
354
|
};
|
|
343
355
|
}
|
|
344
|
-
async deleteIndex(indexName) {
|
|
356
|
+
async deleteIndex({ indexName }) {
|
|
345
357
|
await this.client.deleteCollection(indexName);
|
|
346
358
|
}
|
|
347
|
-
/**
|
|
348
|
-
* @deprecated Use {@link updateVector} instead. This method will be removed on May 20th, 2025.
|
|
349
|
-
*
|
|
350
|
-
* Updates a vector by its ID with the provided vector and/or metadata.
|
|
351
|
-
* @param indexName - The name of the index containing the vector.
|
|
352
|
-
* @param id - The ID of the vector to update.
|
|
353
|
-
* @param update - An object containing the vector and/or metadata to update.
|
|
354
|
-
* @param update.vector - An optional array of numbers representing the new vector.
|
|
355
|
-
* @param update.metadata - An optional record containing the new metadata.
|
|
356
|
-
* @returns A promise that resolves when the update is complete.
|
|
357
|
-
* @throws Will throw an error if no updates are provided or if the update operation fails.
|
|
358
|
-
*/
|
|
359
|
-
async updateIndexById(indexName, id, update) {
|
|
360
|
-
this.logger.warn(
|
|
361
|
-
`Deprecation Warning: updateIndexById() is deprecated.
|
|
362
|
-
Please use updateVector() instead.
|
|
363
|
-
updateIndexById() will be removed on May 20th, 2025.`
|
|
364
|
-
);
|
|
365
|
-
await this.updateVector(indexName, id, update);
|
|
366
|
-
}
|
|
367
359
|
/**
|
|
368
360
|
* Updates a vector by its ID with the provided vector and/or metadata.
|
|
369
361
|
* @param indexName - The name of the index containing the vector.
|
|
@@ -374,7 +366,7 @@ var QdrantVector = class extends MastraVector {
|
|
|
374
366
|
* @returns A promise that resolves when the update is complete.
|
|
375
367
|
* @throws Will throw an error if no updates are provided or if the update operation fails.
|
|
376
368
|
*/
|
|
377
|
-
async updateVector(indexName, id, update) {
|
|
369
|
+
async updateVector({ indexName, id, update }) {
|
|
378
370
|
if (!update.vector && !update.metadata) {
|
|
379
371
|
throw new Error("No updates provided");
|
|
380
372
|
}
|
|
@@ -411,23 +403,6 @@ var QdrantVector = class extends MastraVector {
|
|
|
411
403
|
throw error;
|
|
412
404
|
}
|
|
413
405
|
}
|
|
414
|
-
/**
|
|
415
|
-
* @deprecated Use {@link deleteVector} instead. This method will be removed on May 20th, 2025.
|
|
416
|
-
*
|
|
417
|
-
* Deletes a vector by its ID.
|
|
418
|
-
* @param indexName - The name of the index containing the vector.
|
|
419
|
-
* @param id - The ID of the vector to delete.
|
|
420
|
-
* @returns A promise that resolves when the deletion is complete.
|
|
421
|
-
* @throws Will throw an error if the deletion operation fails.
|
|
422
|
-
*/
|
|
423
|
-
async deleteIndexById(indexName, id) {
|
|
424
|
-
this.logger.warn(
|
|
425
|
-
`Deprecation Warning: deleteIndexById() is deprecated.
|
|
426
|
-
Please use deleteVector() instead.
|
|
427
|
-
deleteIndexById() will be removed on May 20th, 2025.`
|
|
428
|
-
);
|
|
429
|
-
await this.deleteVector(indexName, id);
|
|
430
|
-
}
|
|
431
406
|
/**
|
|
432
407
|
* Deletes a vector by its ID.
|
|
433
408
|
* @param indexName - The name of the index containing the vector.
|
|
@@ -435,7 +410,7 @@ var QdrantVector = class extends MastraVector {
|
|
|
435
410
|
* @returns A promise that resolves when the deletion is complete.
|
|
436
411
|
* @throws Will throw an error if the deletion operation fails.
|
|
437
412
|
*/
|
|
438
|
-
async deleteVector(indexName, id) {
|
|
413
|
+
async deleteVector({ indexName, id }) {
|
|
439
414
|
try {
|
|
440
415
|
const pointId = this.parsePointId(id);
|
|
441
416
|
await this.client.delete(indexName, {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mastra/qdrant",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0-alpha.1",
|
|
4
4
|
"description": "Qdrant vector store provider for Mastra",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -20,8 +20,7 @@
|
|
|
20
20
|
},
|
|
21
21
|
"license": "MIT",
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@qdrant/js-client-rest": "^1.13.0"
|
|
24
|
-
"@mastra/core": "^0.9.4"
|
|
23
|
+
"@qdrant/js-client-rest": "^1.13.0"
|
|
25
24
|
},
|
|
26
25
|
"devDependencies": {
|
|
27
26
|
"@microsoft/api-extractor": "^7.52.5",
|
|
@@ -30,7 +29,11 @@
|
|
|
30
29
|
"tsup": "^8.4.0",
|
|
31
30
|
"typescript": "^5.8.2",
|
|
32
31
|
"vitest": "^3.1.2",
|
|
33
|
-
"@internal/lint": "0.0.5"
|
|
32
|
+
"@internal/lint": "0.0.5",
|
|
33
|
+
"@mastra/core": "0.10.0-alpha.1"
|
|
34
|
+
},
|
|
35
|
+
"peerDependencies": {
|
|
36
|
+
"@mastra/core": "^0.9.4"
|
|
34
37
|
},
|
|
35
38
|
"scripts": {
|
|
36
39
|
"build": "tsup src/index.ts --format esm,cjs --experimental-dts --clean --treeshake=smallest --splitting",
|
package/src/vector/index.test.ts
CHANGED
|
@@ -13,12 +13,12 @@ describe('QdrantVector', () => {
|
|
|
13
13
|
|
|
14
14
|
describe('Index Operations', () => {
|
|
15
15
|
beforeAll(async () => {
|
|
16
|
-
qdrant = new QdrantVector('http://localhost:6333/');
|
|
16
|
+
qdrant = new QdrantVector({ url: 'http://localhost:6333/' });
|
|
17
17
|
await qdrant.createIndex({ indexName: testCollectionName, dimension });
|
|
18
18
|
});
|
|
19
19
|
|
|
20
20
|
afterAll(async () => {
|
|
21
|
-
await qdrant.deleteIndex(testCollectionName);
|
|
21
|
+
await qdrant.deleteIndex({ indexName: testCollectionName });
|
|
22
22
|
}, 50000);
|
|
23
23
|
|
|
24
24
|
it('should list collections including ours', async () => {
|
|
@@ -27,7 +27,7 @@ describe('QdrantVector', () => {
|
|
|
27
27
|
}, 50000);
|
|
28
28
|
|
|
29
29
|
it('should describe index with correct properties', async () => {
|
|
30
|
-
const stats = await qdrant.describeIndex(testCollectionName);
|
|
30
|
+
const stats = await qdrant.describeIndex({ indexName: testCollectionName });
|
|
31
31
|
expect(stats.dimension).toBe(dimension);
|
|
32
32
|
expect(stats.metric).toBe('cosine');
|
|
33
33
|
expect(typeof stats.count).toBe('number');
|
|
@@ -36,12 +36,12 @@ describe('QdrantVector', () => {
|
|
|
36
36
|
|
|
37
37
|
describe('Vector Operations', () => {
|
|
38
38
|
beforeAll(async () => {
|
|
39
|
-
qdrant = new QdrantVector('http://localhost:6333/');
|
|
39
|
+
qdrant = new QdrantVector({ url: 'http://localhost:6333/' });
|
|
40
40
|
await qdrant.createIndex({ indexName: testCollectionName, dimension });
|
|
41
41
|
});
|
|
42
42
|
|
|
43
43
|
afterAll(async () => {
|
|
44
|
-
await qdrant.deleteIndex(testCollectionName);
|
|
44
|
+
await qdrant.deleteIndex({ indexName: testCollectionName });
|
|
45
45
|
}, 50000);
|
|
46
46
|
|
|
47
47
|
const testVectors = [
|
|
@@ -100,7 +100,7 @@ describe('QdrantVector', () => {
|
|
|
100
100
|
});
|
|
101
101
|
|
|
102
102
|
afterEach(async () => {
|
|
103
|
-
await qdrant.deleteIndex(testCollectionName);
|
|
103
|
+
await qdrant.deleteIndex({ indexName: testCollectionName });
|
|
104
104
|
});
|
|
105
105
|
|
|
106
106
|
it('should update the vector by id', async () => {
|
|
@@ -118,7 +118,7 @@ describe('QdrantVector', () => {
|
|
|
118
118
|
metadata: newMetaData,
|
|
119
119
|
};
|
|
120
120
|
|
|
121
|
-
await qdrant.updateVector(testCollectionName, idToBeUpdated, update);
|
|
121
|
+
await qdrant.updateVector({ indexName: testCollectionName, id: idToBeUpdated, update });
|
|
122
122
|
|
|
123
123
|
const results: QueryResult[] = await qdrant.query({
|
|
124
124
|
indexName: testCollectionName,
|
|
@@ -146,7 +146,7 @@ describe('QdrantVector', () => {
|
|
|
146
146
|
metadata: newMetaData,
|
|
147
147
|
};
|
|
148
148
|
|
|
149
|
-
await qdrant.updateVector(testCollectionName, idToBeUpdated, update);
|
|
149
|
+
await qdrant.updateVector({ indexName: testCollectionName, id: idToBeUpdated, update });
|
|
150
150
|
|
|
151
151
|
const results: QueryResult[] = await qdrant.query({
|
|
152
152
|
indexName: testCollectionName,
|
|
@@ -171,7 +171,7 @@ describe('QdrantVector', () => {
|
|
|
171
171
|
vector: newVector,
|
|
172
172
|
};
|
|
173
173
|
|
|
174
|
-
await qdrant.updateVector(testCollectionName, idToBeUpdated, update);
|
|
174
|
+
await qdrant.updateVector({ indexName: testCollectionName, id: idToBeUpdated, update });
|
|
175
175
|
|
|
176
176
|
const results: QueryResult[] = await qdrant.query({
|
|
177
177
|
indexName: testCollectionName,
|
|
@@ -185,12 +185,16 @@ describe('QdrantVector', () => {
|
|
|
185
185
|
});
|
|
186
186
|
|
|
187
187
|
it('should throw exception when no updates are given', async () => {
|
|
188
|
-
await expect(qdrant.updateVector(testCollectionName, 'id', {})).rejects.toThrow(
|
|
188
|
+
await expect(qdrant.updateVector({ indexName: testCollectionName, id: 'id', update: {} })).rejects.toThrow(
|
|
189
|
+
'No updates provided',
|
|
190
|
+
);
|
|
189
191
|
});
|
|
190
192
|
|
|
191
193
|
it('should throw error for non-existent index', async () => {
|
|
192
194
|
const nonExistentIndex = 'non-existent-index';
|
|
193
|
-
await expect(
|
|
195
|
+
await expect(
|
|
196
|
+
qdrant.updateVector({ indexName: nonExistentIndex, id: 'test-id', update: { vector: [1, 2, 3] } }),
|
|
197
|
+
).rejects.toThrow();
|
|
194
198
|
});
|
|
195
199
|
|
|
196
200
|
it('should throw error for invalid vector dimension', async () => {
|
|
@@ -201,7 +205,7 @@ describe('QdrantVector', () => {
|
|
|
201
205
|
});
|
|
202
206
|
|
|
203
207
|
await expect(
|
|
204
|
-
qdrant.updateVector(testCollectionName, id, { vector: [1, 2] }), // Wrong dimension
|
|
208
|
+
qdrant.updateVector({ indexName: testCollectionName, id, update: { vector: [1, 2] } }), // Wrong dimension
|
|
205
209
|
).rejects.toThrow();
|
|
206
210
|
});
|
|
207
211
|
});
|
|
@@ -218,7 +222,7 @@ describe('QdrantVector', () => {
|
|
|
218
222
|
});
|
|
219
223
|
|
|
220
224
|
afterEach(async () => {
|
|
221
|
-
await qdrant.deleteIndex(testCollectionName);
|
|
225
|
+
await qdrant.deleteIndex({ indexName: testCollectionName });
|
|
222
226
|
});
|
|
223
227
|
|
|
224
228
|
it('should delete the vector by id', async () => {
|
|
@@ -226,7 +230,7 @@ describe('QdrantVector', () => {
|
|
|
226
230
|
expect(ids).toHaveLength(3);
|
|
227
231
|
const idToBeDeleted = ids[0];
|
|
228
232
|
|
|
229
|
-
await qdrant.deleteVector(testCollectionName, idToBeDeleted);
|
|
233
|
+
await qdrant.deleteVector({ indexName: testCollectionName, id: idToBeDeleted });
|
|
230
234
|
|
|
231
235
|
const results: QueryResult[] = await qdrant.query({
|
|
232
236
|
indexName: testCollectionName,
|
|
@@ -335,13 +339,13 @@ describe('QdrantVector', () => {
|
|
|
335
339
|
];
|
|
336
340
|
|
|
337
341
|
beforeAll(async () => {
|
|
338
|
-
qdrant = new QdrantVector('http://localhost:6333/');
|
|
342
|
+
qdrant = new QdrantVector({ url: 'http://localhost:6333/' });
|
|
339
343
|
await qdrant.createIndex({ indexName: testCollectionName, dimension });
|
|
340
344
|
await qdrant.upsert({ indexName: testCollectionName, vectors: filterTestVectors, metadata: filterTestMetadata });
|
|
341
345
|
});
|
|
342
346
|
|
|
343
347
|
afterAll(async () => {
|
|
344
|
-
await qdrant.deleteIndex(testCollectionName);
|
|
348
|
+
await qdrant.deleteIndex({ indexName: testCollectionName });
|
|
345
349
|
}, 50000);
|
|
346
350
|
|
|
347
351
|
describe('Basic Operators', () => {
|
|
@@ -761,7 +765,7 @@ describe('QdrantVector', () => {
|
|
|
761
765
|
});
|
|
762
766
|
|
|
763
767
|
afterAll(async () => {
|
|
764
|
-
await qdrant.deleteIndex(testIndexName);
|
|
768
|
+
await qdrant.deleteIndex({ indexName: testIndexName });
|
|
765
769
|
});
|
|
766
770
|
|
|
767
771
|
it('should handle non-existent index query gracefully', async () => {
|
|
@@ -829,7 +833,7 @@ describe('QdrantVector', () => {
|
|
|
829
833
|
infoSpy.mockRestore();
|
|
830
834
|
warnSpy.mockRestore();
|
|
831
835
|
// Cleanup
|
|
832
|
-
await qdrant.deleteIndex(duplicateIndexName);
|
|
836
|
+
await qdrant.deleteIndex({ indexName: duplicateIndexName });
|
|
833
837
|
}
|
|
834
838
|
});
|
|
835
839
|
});
|
|
@@ -870,13 +874,13 @@ describe('QdrantVector', () => {
|
|
|
870
874
|
];
|
|
871
875
|
|
|
872
876
|
beforeAll(async () => {
|
|
873
|
-
qdrant = new QdrantVector('http://localhost:6333/');
|
|
877
|
+
qdrant = new QdrantVector({ url: 'http://localhost:6333/' });
|
|
874
878
|
await qdrant.createIndex({ indexName: testCollectionName, dimension });
|
|
875
879
|
await qdrant.upsert({ indexName: testCollectionName, vectors: filterTestVectors, metadata: filterTestMetadata });
|
|
876
880
|
});
|
|
877
881
|
|
|
878
882
|
afterAll(async () => {
|
|
879
|
-
await qdrant.deleteIndex(testCollectionName);
|
|
883
|
+
await qdrant.deleteIndex({ indexName: testCollectionName });
|
|
880
884
|
}, 50000);
|
|
881
885
|
it('should handle undefined filter', async () => {
|
|
882
886
|
const results1 = await qdrant.query({ indexName: testCollectionName, queryVector: [1, 0, 0], filter: undefined });
|
|
@@ -902,12 +906,12 @@ describe('QdrantVector', () => {
|
|
|
902
906
|
|
|
903
907
|
describe('Performance Tests', () => {
|
|
904
908
|
beforeAll(async () => {
|
|
905
|
-
qdrant = new QdrantVector('http://localhost:6333/');
|
|
909
|
+
qdrant = new QdrantVector({ url: 'http://localhost:6333/' });
|
|
906
910
|
await qdrant.createIndex({ indexName: testCollectionName, dimension });
|
|
907
911
|
});
|
|
908
912
|
|
|
909
913
|
afterAll(async () => {
|
|
910
|
-
await qdrant.deleteIndex(testCollectionName);
|
|
914
|
+
await qdrant.deleteIndex({ indexName: testCollectionName });
|
|
911
915
|
}, 50000);
|
|
912
916
|
|
|
913
917
|
it('should handle batch upsert of 1000 vectors', async () => {
|
|
@@ -945,101 +949,4 @@ describe('QdrantVector', () => {
|
|
|
945
949
|
console.log(`${numQueries} concurrent queries took ${duration}ms`);
|
|
946
950
|
}, 50000);
|
|
947
951
|
});
|
|
948
|
-
describe('Deprecation Warnings', () => {
|
|
949
|
-
const indexName = 'testdeprecationwarnings';
|
|
950
|
-
|
|
951
|
-
const indexName2 = 'testdeprecationwarnings2';
|
|
952
|
-
|
|
953
|
-
let warnSpy;
|
|
954
|
-
|
|
955
|
-
beforeAll(async () => {
|
|
956
|
-
await qdrant.createIndex({ indexName: indexName, dimension: 3 });
|
|
957
|
-
});
|
|
958
|
-
|
|
959
|
-
afterAll(async () => {
|
|
960
|
-
await qdrant.deleteIndex(indexName);
|
|
961
|
-
await qdrant.deleteIndex(indexName2);
|
|
962
|
-
});
|
|
963
|
-
|
|
964
|
-
beforeEach(async () => {
|
|
965
|
-
warnSpy = vi.spyOn(qdrant['logger'], 'warn');
|
|
966
|
-
});
|
|
967
|
-
|
|
968
|
-
afterEach(async () => {
|
|
969
|
-
warnSpy.mockRestore();
|
|
970
|
-
await qdrant.deleteIndex(indexName2);
|
|
971
|
-
});
|
|
972
|
-
|
|
973
|
-
it('should show deprecation warning when using individual args for createIndex', async () => {
|
|
974
|
-
await qdrant.createIndex(indexName2, 3, 'cosine');
|
|
975
|
-
|
|
976
|
-
expect(warnSpy).toHaveBeenCalledWith(
|
|
977
|
-
expect.stringContaining('Deprecation Warning: Passing individual arguments to createIndex() is deprecated'),
|
|
978
|
-
);
|
|
979
|
-
});
|
|
980
|
-
|
|
981
|
-
it('should show deprecation warning when using individual args for upsert', async () => {
|
|
982
|
-
await qdrant.upsert(indexName, [[1, 2, 3]], [{ test: 'data' }]);
|
|
983
|
-
|
|
984
|
-
expect(warnSpy).toHaveBeenCalledWith(
|
|
985
|
-
expect.stringContaining('Deprecation Warning: Passing individual arguments to upsert() is deprecated'),
|
|
986
|
-
);
|
|
987
|
-
});
|
|
988
|
-
|
|
989
|
-
it('should show deprecation warning when using individual args for query', async () => {
|
|
990
|
-
await qdrant.query(indexName, [1, 2, 3], 5);
|
|
991
|
-
|
|
992
|
-
expect(warnSpy).toHaveBeenCalledWith(
|
|
993
|
-
expect.stringContaining('Deprecation Warning: Passing individual arguments to query() is deprecated'),
|
|
994
|
-
);
|
|
995
|
-
});
|
|
996
|
-
|
|
997
|
-
it('should not show deprecation warning when using object param for query', async () => {
|
|
998
|
-
await qdrant.query({
|
|
999
|
-
indexName,
|
|
1000
|
-
queryVector: [1, 2, 3],
|
|
1001
|
-
topK: 5,
|
|
1002
|
-
});
|
|
1003
|
-
|
|
1004
|
-
expect(warnSpy).not.toHaveBeenCalled();
|
|
1005
|
-
});
|
|
1006
|
-
|
|
1007
|
-
it('should not show deprecation warning when using object param for createIndex', async () => {
|
|
1008
|
-
await qdrant.createIndex({
|
|
1009
|
-
indexName: indexName2,
|
|
1010
|
-
dimension: 3,
|
|
1011
|
-
metric: 'cosine',
|
|
1012
|
-
});
|
|
1013
|
-
|
|
1014
|
-
expect(warnSpy).not.toHaveBeenCalled();
|
|
1015
|
-
});
|
|
1016
|
-
|
|
1017
|
-
it('should not show deprecation warning when using object param for upsert', async () => {
|
|
1018
|
-
await qdrant.upsert({
|
|
1019
|
-
indexName,
|
|
1020
|
-
vectors: [[1, 2, 3]],
|
|
1021
|
-
metadata: [{ test: 'data' }],
|
|
1022
|
-
});
|
|
1023
|
-
|
|
1024
|
-
expect(warnSpy).not.toHaveBeenCalled();
|
|
1025
|
-
});
|
|
1026
|
-
|
|
1027
|
-
it('should maintain backward compatibility with individual args', async () => {
|
|
1028
|
-
// Query
|
|
1029
|
-
const queryResults = await qdrant.query(indexName, [1, 2, 3], 5);
|
|
1030
|
-
expect(Array.isArray(queryResults)).toBe(true);
|
|
1031
|
-
|
|
1032
|
-
// CreateIndex
|
|
1033
|
-
await expect(qdrant.createIndex(indexName2, 3, 'cosine')).resolves.not.toThrow();
|
|
1034
|
-
|
|
1035
|
-
// Upsert
|
|
1036
|
-
const upsertResults = await qdrant.upsert({
|
|
1037
|
-
indexName,
|
|
1038
|
-
vectors: [[1, 2, 3]],
|
|
1039
|
-
metadata: [{ test: 'data' }],
|
|
1040
|
-
});
|
|
1041
|
-
expect(Array.isArray(upsertResults)).toBe(true);
|
|
1042
|
-
expect(upsertResults).toHaveLength(1);
|
|
1043
|
-
});
|
|
1044
|
-
});
|
|
1045
952
|
});
|
package/src/vector/index.ts
CHANGED
|
@@ -5,7 +5,10 @@ import type {
|
|
|
5
5
|
CreateIndexParams,
|
|
6
6
|
UpsertVectorParams,
|
|
7
7
|
QueryVectorParams,
|
|
8
|
-
|
|
8
|
+
DescribeIndexParams,
|
|
9
|
+
DeleteIndexParams,
|
|
10
|
+
DeleteVectorParams,
|
|
11
|
+
UpdateVectorParams,
|
|
9
12
|
} from '@mastra/core/vector';
|
|
10
13
|
import type { VectorFilter } from '@mastra/core/vector/filter';
|
|
11
14
|
import { QdrantClient } from '@qdrant/js-client-rest';
|
|
@@ -23,15 +26,19 @@ const DISTANCE_MAPPING: Record<string, Schemas['Distance']> = {
|
|
|
23
26
|
export class QdrantVector extends MastraVector {
|
|
24
27
|
private client: QdrantClient;
|
|
25
28
|
|
|
26
|
-
|
|
29
|
+
/**
|
|
30
|
+
* Creates a new QdrantVector client.
|
|
31
|
+
* @param url - The URL of the Qdrant server.
|
|
32
|
+
* @param apiKey - The API key for Qdrant.
|
|
33
|
+
* @param https - Whether to use HTTPS.
|
|
34
|
+
*/
|
|
35
|
+
constructor({ url, apiKey, https }: { url: string; apiKey?: string; https?: boolean }) {
|
|
27
36
|
super();
|
|
28
|
-
|
|
29
37
|
const baseClient = new QdrantClient({
|
|
30
38
|
url,
|
|
31
39
|
apiKey,
|
|
32
40
|
https,
|
|
33
41
|
});
|
|
34
|
-
|
|
35
42
|
const telemetry = this.__getTelemetry();
|
|
36
43
|
this.client =
|
|
37
44
|
telemetry?.traceClass(baseClient, {
|
|
@@ -42,11 +49,7 @@ export class QdrantVector extends MastraVector {
|
|
|
42
49
|
}) ?? baseClient;
|
|
43
50
|
}
|
|
44
51
|
|
|
45
|
-
async upsert(
|
|
46
|
-
const params = this.normalizeArgs<UpsertVectorParams>('upsert', args);
|
|
47
|
-
|
|
48
|
-
const { indexName, vectors, metadata, ids } = params;
|
|
49
|
-
|
|
52
|
+
async upsert({ indexName, vectors, metadata, ids }: UpsertVectorParams): Promise<string[]> {
|
|
50
53
|
const pointIds = ids || vectors.map(() => crypto.randomUUID());
|
|
51
54
|
|
|
52
55
|
const records = vectors.map((vector, i) => ({
|
|
@@ -67,11 +70,7 @@ export class QdrantVector extends MastraVector {
|
|
|
67
70
|
return pointIds;
|
|
68
71
|
}
|
|
69
72
|
|
|
70
|
-
async createIndex(
|
|
71
|
-
const params = this.normalizeArgs<CreateIndexParams>('createIndex', args);
|
|
72
|
-
|
|
73
|
-
const { indexName, dimension, metric = 'cosine' } = params;
|
|
74
|
-
|
|
73
|
+
async createIndex({ indexName, dimension, metric = 'cosine' }: CreateIndexParams): Promise<void> {
|
|
75
74
|
if (!Number.isInteger(dimension) || dimension <= 0) {
|
|
76
75
|
throw new Error('Dimension must be a positive integer');
|
|
77
76
|
}
|
|
@@ -101,11 +100,13 @@ export class QdrantVector extends MastraVector {
|
|
|
101
100
|
return translator.translate(filter);
|
|
102
101
|
}
|
|
103
102
|
|
|
104
|
-
async query(
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
103
|
+
async query({
|
|
104
|
+
indexName,
|
|
105
|
+
queryVector,
|
|
106
|
+
topK = 10,
|
|
107
|
+
filter,
|
|
108
|
+
includeVector = false,
|
|
109
|
+
}: QueryVectorParams): Promise<QueryResult[]> {
|
|
109
110
|
const translatedFilter = this.transformFilter(filter) ?? {};
|
|
110
111
|
|
|
111
112
|
const results = (
|
|
@@ -144,7 +145,13 @@ export class QdrantVector extends MastraVector {
|
|
|
144
145
|
return response.collections.map(collection => collection.name) || [];
|
|
145
146
|
}
|
|
146
147
|
|
|
147
|
-
|
|
148
|
+
/**
|
|
149
|
+
* Retrieves statistics about a vector index.
|
|
150
|
+
*
|
|
151
|
+
* @param {string} indexName - The name of the index to describe
|
|
152
|
+
* @returns A promise that resolves to the index statistics including dimension, count and metric
|
|
153
|
+
*/
|
|
154
|
+
async describeIndex({ indexName }: DescribeIndexParams): Promise<IndexStats> {
|
|
148
155
|
const { config, points_count } = await this.client.getCollection(indexName);
|
|
149
156
|
|
|
150
157
|
const distance = config.params.vectors?.distance as Schemas['Distance'];
|
|
@@ -156,35 +163,10 @@ export class QdrantVector extends MastraVector {
|
|
|
156
163
|
};
|
|
157
164
|
}
|
|
158
165
|
|
|
159
|
-
async deleteIndex(indexName:
|
|
166
|
+
async deleteIndex({ indexName }: DeleteIndexParams): Promise<void> {
|
|
160
167
|
await this.client.deleteCollection(indexName);
|
|
161
168
|
}
|
|
162
169
|
|
|
163
|
-
/**
|
|
164
|
-
* @deprecated Use {@link updateVector} instead. This method will be removed on May 20th, 2025.
|
|
165
|
-
*
|
|
166
|
-
* Updates a vector by its ID with the provided vector and/or metadata.
|
|
167
|
-
* @param indexName - The name of the index containing the vector.
|
|
168
|
-
* @param id - The ID of the vector to update.
|
|
169
|
-
* @param update - An object containing the vector and/or metadata to update.
|
|
170
|
-
* @param update.vector - An optional array of numbers representing the new vector.
|
|
171
|
-
* @param update.metadata - An optional record containing the new metadata.
|
|
172
|
-
* @returns A promise that resolves when the update is complete.
|
|
173
|
-
* @throws Will throw an error if no updates are provided or if the update operation fails.
|
|
174
|
-
*/
|
|
175
|
-
async updateIndexById(
|
|
176
|
-
indexName: string,
|
|
177
|
-
id: string,
|
|
178
|
-
update: { vector?: number[]; metadata?: Record<string, any> },
|
|
179
|
-
): Promise<void> {
|
|
180
|
-
this.logger.warn(
|
|
181
|
-
`Deprecation Warning: updateIndexById() is deprecated.
|
|
182
|
-
Please use updateVector() instead.
|
|
183
|
-
updateIndexById() will be removed on May 20th, 2025.`,
|
|
184
|
-
);
|
|
185
|
-
await this.updateVector(indexName, id, update);
|
|
186
|
-
}
|
|
187
|
-
|
|
188
170
|
/**
|
|
189
171
|
* Updates a vector by its ID with the provided vector and/or metadata.
|
|
190
172
|
* @param indexName - The name of the index containing the vector.
|
|
@@ -195,14 +177,7 @@ export class QdrantVector extends MastraVector {
|
|
|
195
177
|
* @returns A promise that resolves when the update is complete.
|
|
196
178
|
* @throws Will throw an error if no updates are provided or if the update operation fails.
|
|
197
179
|
*/
|
|
198
|
-
async updateVector(
|
|
199
|
-
indexName: string,
|
|
200
|
-
id: string,
|
|
201
|
-
update: {
|
|
202
|
-
vector?: number[];
|
|
203
|
-
metadata?: Record<string, any>;
|
|
204
|
-
},
|
|
205
|
-
): Promise<void> {
|
|
180
|
+
async updateVector({ indexName, id, update }: UpdateVectorParams): Promise<void> {
|
|
206
181
|
if (!update.vector && !update.metadata) {
|
|
207
182
|
throw new Error('No updates provided');
|
|
208
183
|
}
|
|
@@ -249,24 +224,6 @@ export class QdrantVector extends MastraVector {
|
|
|
249
224
|
}
|
|
250
225
|
}
|
|
251
226
|
|
|
252
|
-
/**
|
|
253
|
-
* @deprecated Use {@link deleteVector} instead. This method will be removed on May 20th, 2025.
|
|
254
|
-
*
|
|
255
|
-
* Deletes a vector by its ID.
|
|
256
|
-
* @param indexName - The name of the index containing the vector.
|
|
257
|
-
* @param id - The ID of the vector to delete.
|
|
258
|
-
* @returns A promise that resolves when the deletion is complete.
|
|
259
|
-
* @throws Will throw an error if the deletion operation fails.
|
|
260
|
-
*/
|
|
261
|
-
async deleteIndexById(indexName: string, id: string): Promise<void> {
|
|
262
|
-
this.logger.warn(
|
|
263
|
-
`Deprecation Warning: deleteIndexById() is deprecated.
|
|
264
|
-
Please use deleteVector() instead.
|
|
265
|
-
deleteIndexById() will be removed on May 20th, 2025.`,
|
|
266
|
-
);
|
|
267
|
-
await this.deleteVector(indexName, id);
|
|
268
|
-
}
|
|
269
|
-
|
|
270
227
|
/**
|
|
271
228
|
* Deletes a vector by its ID.
|
|
272
229
|
* @param indexName - The name of the index containing the vector.
|
|
@@ -274,7 +231,7 @@ export class QdrantVector extends MastraVector {
|
|
|
274
231
|
* @returns A promise that resolves when the deletion is complete.
|
|
275
232
|
* @throws Will throw an error if the deletion operation fails.
|
|
276
233
|
*/
|
|
277
|
-
async deleteVector(indexName
|
|
234
|
+
async deleteVector({ indexName, id }: DeleteVectorParams): Promise<void> {
|
|
278
235
|
try {
|
|
279
236
|
// Parse the ID - Qdrant supports both string and numeric IDs
|
|
280
237
|
const pointId = this.parsePointId(id);
|