@mastra/pinecone 0.2.14-alpha.0 → 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 +21 -0
- package/dist/_tsup-dts-rollup.d.cts +11 -57
- package/dist/_tsup-dts-rollup.d.ts +11 -57
- package/dist/index.cjs +31 -92
- package/dist/index.js +31 -92
- package/package.json +7 -4
- package/src/vector/index.test.ts +0 -140
- package/src/vector/index.ts +28 -122
package/.turbo/turbo-build.log
CHANGED
|
@@ -1,23 +1,23 @@
|
|
|
1
1
|
|
|
2
|
-
> @mastra/pinecone@0.
|
|
2
|
+
> @mastra/pinecone@0.3.0-alpha.1 build /home/runner/work/mastra/mastra/stores/pinecone
|
|
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 8231ms
|
|
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/pinecone/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/pinecone/dist/_tsup-dts-rollup.d.cts[39m
|
|
16
|
-
[32mDTS[39m ⚡️ Build success in
|
|
16
|
+
[32mDTS[39m ⚡️ Build success in 10007ms
|
|
17
17
|
[34mCLI[39m Cleaning output folder
|
|
18
18
|
[34mESM[39m Build start
|
|
19
19
|
[34mCJS[39m Build start
|
|
20
|
-
[
|
|
21
|
-
[
|
|
22
|
-
[
|
|
23
|
-
[
|
|
20
|
+
[32mESM[39m [1mdist/index.js [22m[32m12.38 KB[39m
|
|
21
|
+
[32mESM[39m ⚡️ Build success in 683ms
|
|
22
|
+
[32mCJS[39m [1mdist/index.cjs [22m[32m12.45 KB[39m
|
|
23
|
+
[32mCJS[39m ⚡️ Build success in 682ms
|
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,26 @@
|
|
|
1
1
|
# @mastra/pinecone
|
|
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
|
+
|
|
3
24
|
## 0.2.14-alpha.0
|
|
4
25
|
|
|
5
26
|
### Patch Changes
|
|
@@ -1,21 +1,16 @@
|
|
|
1
1
|
import { BaseFilterTranslator } from '@mastra/core/vector/filter';
|
|
2
2
|
import type { CreateIndexParams } from '@mastra/core/vector';
|
|
3
3
|
import type { DeleteIndexParams } from '@mastra/core/vector';
|
|
4
|
-
import type { DeleteVectorArgs } from '@mastra/core/vector';
|
|
5
4
|
import type { DeleteVectorParams } from '@mastra/core/vector';
|
|
6
5
|
import type { DescribeIndexParams } from '@mastra/core/vector';
|
|
7
6
|
import type { IndexStats } from '@mastra/core/vector';
|
|
8
7
|
import type { IndexStatsDescription } from '@pinecone-database/pinecone';
|
|
9
8
|
import { MastraVector } from '@mastra/core/vector';
|
|
10
9
|
import type { OperatorSupport } from '@mastra/core/vector/filter';
|
|
11
|
-
import type { ParamsToArgs } from '@mastra/core/vector';
|
|
12
10
|
import type { QueryResult } from '@mastra/core/vector';
|
|
13
|
-
import type { QueryVectorArgs } from '@mastra/core/vector';
|
|
14
11
|
import type { QueryVectorParams } from '@mastra/core/vector';
|
|
15
12
|
import type { RecordSparseValues } from '@pinecone-database/pinecone';
|
|
16
|
-
import type { UpdateVectorArgs } from '@mastra/core/vector';
|
|
17
13
|
import type { UpdateVectorParams } from '@mastra/core/vector';
|
|
18
|
-
import type { UpsertVectorArgs } from '@mastra/core/vector';
|
|
19
14
|
import type { UpsertVectorParams } from '@mastra/core/vector';
|
|
20
15
|
import type { VectorFilter } from '@mastra/core/vector/filter';
|
|
21
16
|
|
|
@@ -27,8 +22,6 @@ declare const PINECONE_PROMPT = "When querying Pinecone, you can ONLY use the op
|
|
|
27
22
|
export { PINECONE_PROMPT }
|
|
28
23
|
export { PINECONE_PROMPT as PINECONE_PROMPT_alias_1 }
|
|
29
24
|
|
|
30
|
-
declare type PineconeDeleteVectorArgs = [...DeleteVectorArgs, string?];
|
|
31
|
-
|
|
32
25
|
declare interface PineconeDeleteVectorParams extends DeleteVectorParams {
|
|
33
26
|
namespace?: string;
|
|
34
27
|
}
|
|
@@ -44,21 +37,15 @@ declare interface PineconeIndexStats extends IndexStats {
|
|
|
44
37
|
namespaces?: IndexStatsDescription['namespaces'];
|
|
45
38
|
}
|
|
46
39
|
|
|
47
|
-
declare type PineconeQueryVectorArgs = [...QueryVectorArgs, string?, RecordSparseValues?];
|
|
48
|
-
|
|
49
40
|
declare interface PineconeQueryVectorParams extends QueryVectorParams {
|
|
50
41
|
namespace?: string;
|
|
51
42
|
sparseVector?: RecordSparseValues;
|
|
52
43
|
}
|
|
53
44
|
|
|
54
|
-
declare type PineconeUpdateVectorArgs = [...UpdateVectorArgs, string?];
|
|
55
|
-
|
|
56
45
|
declare interface PineconeUpdateVectorParams extends UpdateVectorParams {
|
|
57
46
|
namespace?: string;
|
|
58
47
|
}
|
|
59
48
|
|
|
60
|
-
declare type PineconeUpsertVectorArgs = [...UpsertVectorArgs, string?, RecordSparseValues[]?];
|
|
61
|
-
|
|
62
49
|
declare interface PineconeUpsertVectorParams extends UpsertVectorParams {
|
|
63
50
|
namespace?: string;
|
|
64
51
|
sparseVectors?: RecordSparseValues[];
|
|
@@ -66,37 +53,30 @@ declare interface PineconeUpsertVectorParams extends UpsertVectorParams {
|
|
|
66
53
|
|
|
67
54
|
declare class PineconeVector extends MastraVector {
|
|
68
55
|
private client;
|
|
69
|
-
/**
|
|
70
|
-
* @deprecated Passing apiKey and environment as positional arguments is deprecated.
|
|
71
|
-
* Use the object parameter instead. This signature will be removed on May 20th, 2025.
|
|
72
|
-
*/
|
|
73
|
-
constructor(apiKey: string, environment?: string);
|
|
74
56
|
/**
|
|
75
57
|
* Creates a new PineconeVector client.
|
|
76
|
-
* @param
|
|
58
|
+
* @param apiKey - The API key for Pinecone.
|
|
59
|
+
* @param environment - The environment for Pinecone.
|
|
77
60
|
*/
|
|
78
|
-
constructor(
|
|
61
|
+
constructor({ apiKey, environment }: {
|
|
79
62
|
apiKey: string;
|
|
80
63
|
environment?: string;
|
|
81
64
|
});
|
|
82
65
|
get indexSeparator(): string;
|
|
83
|
-
createIndex(
|
|
84
|
-
upsert(
|
|
66
|
+
createIndex({ indexName, dimension, metric }: CreateIndexParams): Promise<void>;
|
|
67
|
+
upsert({ indexName, vectors, metadata, ids, namespace, sparseVectors, }: PineconeUpsertVectorParams): Promise<string[]>;
|
|
85
68
|
transformFilter(filter?: VectorFilter): VectorFilter;
|
|
86
|
-
query(
|
|
69
|
+
query({ indexName, queryVector, topK, filter, includeVector, namespace, sparseVector, }: PineconeQueryVectorParams): Promise<QueryResult[]>;
|
|
87
70
|
listIndexes(): Promise<string[]>;
|
|
88
71
|
/**
|
|
89
72
|
* Retrieves statistics about a vector index.
|
|
90
73
|
*
|
|
91
|
-
* @param
|
|
92
|
-
* @param params.indexName - The name of the index to describe
|
|
74
|
+
* @param {string} indexName - The name of the index to describe
|
|
93
75
|
* @returns A promise that resolves to the index statistics including dimension, count and metric
|
|
94
76
|
*/
|
|
95
|
-
describeIndex(
|
|
96
|
-
deleteIndex(
|
|
77
|
+
describeIndex({ indexName }: DescribeIndexParams): Promise<PineconeIndexStats>;
|
|
78
|
+
deleteIndex({ indexName }: DeleteIndexParams): Promise<void>;
|
|
97
79
|
/**
|
|
98
|
-
* @deprecated Use {@link updateVector} instead. This method will be removed on May 20th, 2025.
|
|
99
|
-
*
|
|
100
80
|
* Updates a vector by its ID with the provided vector and/or metadata.
|
|
101
81
|
* @param indexName - The name of the index containing the vector.
|
|
102
82
|
* @param id - The ID of the vector to update.
|
|
@@ -107,33 +87,7 @@ declare class PineconeVector extends MastraVector {
|
|
|
107
87
|
* @returns A promise that resolves when the update is complete.
|
|
108
88
|
* @throws Will throw an error if no updates are provided or if the update operation fails.
|
|
109
89
|
*/
|
|
110
|
-
|
|
111
|
-
vector?: number[];
|
|
112
|
-
metadata?: Record<string, any>;
|
|
113
|
-
}, namespace?: string): Promise<void>;
|
|
114
|
-
/**
|
|
115
|
-
* Updates a vector by its ID with the provided vector and/or metadata.
|
|
116
|
-
* @param indexName - The name of the index containing the vector.
|
|
117
|
-
* @param id - The ID of the vector to update.
|
|
118
|
-
* @param update - An object containing the vector and/or metadata to update.
|
|
119
|
-
* @param update.vector - An optional array of numbers representing the new vector.
|
|
120
|
-
* @param update.metadata - An optional record containing the new metadata.
|
|
121
|
-
* @param namespace - The namespace of the index (optional).
|
|
122
|
-
* @returns A promise that resolves when the update is complete.
|
|
123
|
-
* @throws Will throw an error if no updates are provided or if the update operation fails.
|
|
124
|
-
*/
|
|
125
|
-
updateVector(...args: ParamsToArgs<PineconeUpdateVectorParams> | PineconeUpdateVectorArgs): Promise<void>;
|
|
126
|
-
/**
|
|
127
|
-
* @deprecated Use {@link deleteVector} instead. This method will be removed on May 20th, 2025.
|
|
128
|
-
*
|
|
129
|
-
* Deletes a vector by its ID.
|
|
130
|
-
* @param indexName - The name of the index containing the vector.
|
|
131
|
-
* @param id - The ID of the vector to delete.
|
|
132
|
-
* @param namespace - The namespace of the index (optional).
|
|
133
|
-
* @returns A promise that resolves when the deletion is complete.
|
|
134
|
-
* @throws Will throw an error if the deletion operation fails.
|
|
135
|
-
*/
|
|
136
|
-
deleteIndexById(indexName: string, id: string, namespace?: string): Promise<void>;
|
|
90
|
+
updateVector({ indexName, id, update, namespace }: PineconeUpdateVectorParams): Promise<void>;
|
|
137
91
|
/**
|
|
138
92
|
* Deletes a vector by its ID.
|
|
139
93
|
* @param indexName - The name of the index containing the vector.
|
|
@@ -142,7 +96,7 @@ declare class PineconeVector extends MastraVector {
|
|
|
142
96
|
* @returns A promise that resolves when the deletion is complete.
|
|
143
97
|
* @throws Will throw an error if the deletion operation fails.
|
|
144
98
|
*/
|
|
145
|
-
deleteVector(
|
|
99
|
+
deleteVector({ indexName, id, namespace }: PineconeDeleteVectorParams): Promise<void>;
|
|
146
100
|
}
|
|
147
101
|
export { PineconeVector }
|
|
148
102
|
export { PineconeVector as PineconeVector_alias_1 }
|
|
@@ -1,21 +1,16 @@
|
|
|
1
1
|
import { BaseFilterTranslator } from '@mastra/core/vector/filter';
|
|
2
2
|
import type { CreateIndexParams } from '@mastra/core/vector';
|
|
3
3
|
import type { DeleteIndexParams } from '@mastra/core/vector';
|
|
4
|
-
import type { DeleteVectorArgs } from '@mastra/core/vector';
|
|
5
4
|
import type { DeleteVectorParams } from '@mastra/core/vector';
|
|
6
5
|
import type { DescribeIndexParams } from '@mastra/core/vector';
|
|
7
6
|
import type { IndexStats } from '@mastra/core/vector';
|
|
8
7
|
import type { IndexStatsDescription } from '@pinecone-database/pinecone';
|
|
9
8
|
import { MastraVector } from '@mastra/core/vector';
|
|
10
9
|
import type { OperatorSupport } from '@mastra/core/vector/filter';
|
|
11
|
-
import type { ParamsToArgs } from '@mastra/core/vector';
|
|
12
10
|
import type { QueryResult } from '@mastra/core/vector';
|
|
13
|
-
import type { QueryVectorArgs } from '@mastra/core/vector';
|
|
14
11
|
import type { QueryVectorParams } from '@mastra/core/vector';
|
|
15
12
|
import type { RecordSparseValues } from '@pinecone-database/pinecone';
|
|
16
|
-
import type { UpdateVectorArgs } from '@mastra/core/vector';
|
|
17
13
|
import type { UpdateVectorParams } from '@mastra/core/vector';
|
|
18
|
-
import type { UpsertVectorArgs } from '@mastra/core/vector';
|
|
19
14
|
import type { UpsertVectorParams } from '@mastra/core/vector';
|
|
20
15
|
import type { VectorFilter } from '@mastra/core/vector/filter';
|
|
21
16
|
|
|
@@ -27,8 +22,6 @@ declare const PINECONE_PROMPT = "When querying Pinecone, you can ONLY use the op
|
|
|
27
22
|
export { PINECONE_PROMPT }
|
|
28
23
|
export { PINECONE_PROMPT as PINECONE_PROMPT_alias_1 }
|
|
29
24
|
|
|
30
|
-
declare type PineconeDeleteVectorArgs = [...DeleteVectorArgs, string?];
|
|
31
|
-
|
|
32
25
|
declare interface PineconeDeleteVectorParams extends DeleteVectorParams {
|
|
33
26
|
namespace?: string;
|
|
34
27
|
}
|
|
@@ -44,21 +37,15 @@ declare interface PineconeIndexStats extends IndexStats {
|
|
|
44
37
|
namespaces?: IndexStatsDescription['namespaces'];
|
|
45
38
|
}
|
|
46
39
|
|
|
47
|
-
declare type PineconeQueryVectorArgs = [...QueryVectorArgs, string?, RecordSparseValues?];
|
|
48
|
-
|
|
49
40
|
declare interface PineconeQueryVectorParams extends QueryVectorParams {
|
|
50
41
|
namespace?: string;
|
|
51
42
|
sparseVector?: RecordSparseValues;
|
|
52
43
|
}
|
|
53
44
|
|
|
54
|
-
declare type PineconeUpdateVectorArgs = [...UpdateVectorArgs, string?];
|
|
55
|
-
|
|
56
45
|
declare interface PineconeUpdateVectorParams extends UpdateVectorParams {
|
|
57
46
|
namespace?: string;
|
|
58
47
|
}
|
|
59
48
|
|
|
60
|
-
declare type PineconeUpsertVectorArgs = [...UpsertVectorArgs, string?, RecordSparseValues[]?];
|
|
61
|
-
|
|
62
49
|
declare interface PineconeUpsertVectorParams extends UpsertVectorParams {
|
|
63
50
|
namespace?: string;
|
|
64
51
|
sparseVectors?: RecordSparseValues[];
|
|
@@ -66,37 +53,30 @@ declare interface PineconeUpsertVectorParams extends UpsertVectorParams {
|
|
|
66
53
|
|
|
67
54
|
declare class PineconeVector extends MastraVector {
|
|
68
55
|
private client;
|
|
69
|
-
/**
|
|
70
|
-
* @deprecated Passing apiKey and environment as positional arguments is deprecated.
|
|
71
|
-
* Use the object parameter instead. This signature will be removed on May 20th, 2025.
|
|
72
|
-
*/
|
|
73
|
-
constructor(apiKey: string, environment?: string);
|
|
74
56
|
/**
|
|
75
57
|
* Creates a new PineconeVector client.
|
|
76
|
-
* @param
|
|
58
|
+
* @param apiKey - The API key for Pinecone.
|
|
59
|
+
* @param environment - The environment for Pinecone.
|
|
77
60
|
*/
|
|
78
|
-
constructor(
|
|
61
|
+
constructor({ apiKey, environment }: {
|
|
79
62
|
apiKey: string;
|
|
80
63
|
environment?: string;
|
|
81
64
|
});
|
|
82
65
|
get indexSeparator(): string;
|
|
83
|
-
createIndex(
|
|
84
|
-
upsert(
|
|
66
|
+
createIndex({ indexName, dimension, metric }: CreateIndexParams): Promise<void>;
|
|
67
|
+
upsert({ indexName, vectors, metadata, ids, namespace, sparseVectors, }: PineconeUpsertVectorParams): Promise<string[]>;
|
|
85
68
|
transformFilter(filter?: VectorFilter): VectorFilter;
|
|
86
|
-
query(
|
|
69
|
+
query({ indexName, queryVector, topK, filter, includeVector, namespace, sparseVector, }: PineconeQueryVectorParams): Promise<QueryResult[]>;
|
|
87
70
|
listIndexes(): Promise<string[]>;
|
|
88
71
|
/**
|
|
89
72
|
* Retrieves statistics about a vector index.
|
|
90
73
|
*
|
|
91
|
-
* @param
|
|
92
|
-
* @param params.indexName - The name of the index to describe
|
|
74
|
+
* @param {string} indexName - The name of the index to describe
|
|
93
75
|
* @returns A promise that resolves to the index statistics including dimension, count and metric
|
|
94
76
|
*/
|
|
95
|
-
describeIndex(
|
|
96
|
-
deleteIndex(
|
|
77
|
+
describeIndex({ indexName }: DescribeIndexParams): Promise<PineconeIndexStats>;
|
|
78
|
+
deleteIndex({ indexName }: DeleteIndexParams): Promise<void>;
|
|
97
79
|
/**
|
|
98
|
-
* @deprecated Use {@link updateVector} instead. This method will be removed on May 20th, 2025.
|
|
99
|
-
*
|
|
100
80
|
* Updates a vector by its ID with the provided vector and/or metadata.
|
|
101
81
|
* @param indexName - The name of the index containing the vector.
|
|
102
82
|
* @param id - The ID of the vector to update.
|
|
@@ -107,33 +87,7 @@ declare class PineconeVector extends MastraVector {
|
|
|
107
87
|
* @returns A promise that resolves when the update is complete.
|
|
108
88
|
* @throws Will throw an error if no updates are provided or if the update operation fails.
|
|
109
89
|
*/
|
|
110
|
-
|
|
111
|
-
vector?: number[];
|
|
112
|
-
metadata?: Record<string, any>;
|
|
113
|
-
}, namespace?: string): Promise<void>;
|
|
114
|
-
/**
|
|
115
|
-
* Updates a vector by its ID with the provided vector and/or metadata.
|
|
116
|
-
* @param indexName - The name of the index containing the vector.
|
|
117
|
-
* @param id - The ID of the vector to update.
|
|
118
|
-
* @param update - An object containing the vector and/or metadata to update.
|
|
119
|
-
* @param update.vector - An optional array of numbers representing the new vector.
|
|
120
|
-
* @param update.metadata - An optional record containing the new metadata.
|
|
121
|
-
* @param namespace - The namespace of the index (optional).
|
|
122
|
-
* @returns A promise that resolves when the update is complete.
|
|
123
|
-
* @throws Will throw an error if no updates are provided or if the update operation fails.
|
|
124
|
-
*/
|
|
125
|
-
updateVector(...args: ParamsToArgs<PineconeUpdateVectorParams> | PineconeUpdateVectorArgs): Promise<void>;
|
|
126
|
-
/**
|
|
127
|
-
* @deprecated Use {@link deleteVector} instead. This method will be removed on May 20th, 2025.
|
|
128
|
-
*
|
|
129
|
-
* Deletes a vector by its ID.
|
|
130
|
-
* @param indexName - The name of the index containing the vector.
|
|
131
|
-
* @param id - The ID of the vector to delete.
|
|
132
|
-
* @param namespace - The namespace of the index (optional).
|
|
133
|
-
* @returns A promise that resolves when the deletion is complete.
|
|
134
|
-
* @throws Will throw an error if the deletion operation fails.
|
|
135
|
-
*/
|
|
136
|
-
deleteIndexById(indexName: string, id: string, namespace?: string): Promise<void>;
|
|
90
|
+
updateVector({ indexName, id, update, namespace }: PineconeUpdateVectorParams): Promise<void>;
|
|
137
91
|
/**
|
|
138
92
|
* Deletes a vector by its ID.
|
|
139
93
|
* @param indexName - The name of the index containing the vector.
|
|
@@ -142,7 +96,7 @@ declare class PineconeVector extends MastraVector {
|
|
|
142
96
|
* @returns A promise that resolves when the deletion is complete.
|
|
143
97
|
* @throws Will throw an error if the deletion operation fails.
|
|
144
98
|
*/
|
|
145
|
-
deleteVector(
|
|
99
|
+
deleteVector({ indexName, id, namespace }: PineconeDeleteVectorParams): Promise<void>;
|
|
146
100
|
}
|
|
147
101
|
export { PineconeVector }
|
|
148
102
|
export { PineconeVector as PineconeVector_alias_1 }
|
package/dist/index.cjs
CHANGED
|
@@ -85,28 +85,16 @@ var PineconeFilterTranslator = class extends filter.BaseFilterTranslator {
|
|
|
85
85
|
// src/vector/index.ts
|
|
86
86
|
var PineconeVector = class extends vector.MastraVector {
|
|
87
87
|
client;
|
|
88
|
-
|
|
88
|
+
/**
|
|
89
|
+
* Creates a new PineconeVector client.
|
|
90
|
+
* @param apiKey - The API key for Pinecone.
|
|
91
|
+
* @param environment - The environment for Pinecone.
|
|
92
|
+
*/
|
|
93
|
+
constructor({ apiKey, environment }) {
|
|
89
94
|
super();
|
|
90
|
-
let apiKey;
|
|
91
|
-
let env;
|
|
92
|
-
if (typeof paramsOrApiKey === "string") {
|
|
93
|
-
if (typeof console !== "undefined" && console.warn) {
|
|
94
|
-
console.warn(
|
|
95
|
-
`Deprecation Warning: Passing apiKey and environment as positional arguments to PineconeVector constructor is deprecated.
|
|
96
|
-
Please use an object parameter instead:
|
|
97
|
-
new PineconeVector({ apiKey, environment })
|
|
98
|
-
This signature will be removed on May 20th, 2025.`
|
|
99
|
-
);
|
|
100
|
-
}
|
|
101
|
-
apiKey = paramsOrApiKey;
|
|
102
|
-
env = environment;
|
|
103
|
-
} else {
|
|
104
|
-
apiKey = paramsOrApiKey.apiKey;
|
|
105
|
-
env = paramsOrApiKey.environment;
|
|
106
|
-
}
|
|
107
95
|
const opts = { apiKey };
|
|
108
|
-
if (
|
|
109
|
-
opts["controllerHostUrl"] =
|
|
96
|
+
if (environment) {
|
|
97
|
+
opts["controllerHostUrl"] = environment;
|
|
110
98
|
}
|
|
111
99
|
const baseClient = new pinecone.Pinecone(opts);
|
|
112
100
|
const telemetry = this.__getTelemetry();
|
|
@@ -120,9 +108,7 @@ This signature will be removed on May 20th, 2025.`
|
|
|
120
108
|
get indexSeparator() {
|
|
121
109
|
return "-";
|
|
122
110
|
}
|
|
123
|
-
async createIndex(
|
|
124
|
-
const params = this.normalizeArgs("createIndex", args);
|
|
125
|
-
const { indexName, dimension, metric = "cosine" } = params;
|
|
111
|
+
async createIndex({ indexName, dimension, metric = "cosine" }) {
|
|
126
112
|
if (!Number.isInteger(dimension) || dimension <= 0) {
|
|
127
113
|
throw new Error("Dimension must be a positive integer");
|
|
128
114
|
}
|
|
@@ -150,12 +136,14 @@ This signature will be removed on May 20th, 2025.`
|
|
|
150
136
|
throw error;
|
|
151
137
|
}
|
|
152
138
|
}
|
|
153
|
-
async upsert(
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
139
|
+
async upsert({
|
|
140
|
+
indexName,
|
|
141
|
+
vectors,
|
|
142
|
+
metadata,
|
|
143
|
+
ids,
|
|
144
|
+
namespace,
|
|
145
|
+
sparseVectors
|
|
146
|
+
}) {
|
|
159
147
|
const index = this.client.Index(indexName).namespace(namespace || "");
|
|
160
148
|
const vectorIds = ids || vectors.map(() => crypto.randomUUID());
|
|
161
149
|
const records = vectors.map((vector, i) => ({
|
|
@@ -175,12 +163,15 @@ This signature will be removed on May 20th, 2025.`
|
|
|
175
163
|
const translator = new PineconeFilterTranslator();
|
|
176
164
|
return translator.translate(filter);
|
|
177
165
|
}
|
|
178
|
-
async query(
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
166
|
+
async query({
|
|
167
|
+
indexName,
|
|
168
|
+
queryVector,
|
|
169
|
+
topK = 10,
|
|
170
|
+
filter,
|
|
171
|
+
includeVector = false,
|
|
172
|
+
namespace,
|
|
173
|
+
sparseVector
|
|
174
|
+
}) {
|
|
184
175
|
const index = this.client.Index(indexName).namespace(namespace || "");
|
|
185
176
|
const translatedFilter = this.transformFilter(filter) ?? void 0;
|
|
186
177
|
const queryParams = {
|
|
@@ -208,13 +199,10 @@ This signature will be removed on May 20th, 2025.`
|
|
|
208
199
|
/**
|
|
209
200
|
* Retrieves statistics about a vector index.
|
|
210
201
|
*
|
|
211
|
-
* @param
|
|
212
|
-
* @param params.indexName - The name of the index to describe
|
|
202
|
+
* @param {string} indexName - The name of the index to describe
|
|
213
203
|
* @returns A promise that resolves to the index statistics including dimension, count and metric
|
|
214
204
|
*/
|
|
215
|
-
async describeIndex(
|
|
216
|
-
const params = this.normalizeArgs("describeIndex", args);
|
|
217
|
-
const { indexName } = params;
|
|
205
|
+
async describeIndex({ indexName }) {
|
|
218
206
|
const index = this.client.Index(indexName);
|
|
219
207
|
const stats = await index.describeIndexStats();
|
|
220
208
|
const description = await this.client.describeIndex(indexName);
|
|
@@ -225,9 +213,7 @@ This signature will be removed on May 20th, 2025.`
|
|
|
225
213
|
namespaces: stats.namespaces
|
|
226
214
|
};
|
|
227
215
|
}
|
|
228
|
-
async deleteIndex(
|
|
229
|
-
const params = this.normalizeArgs("deleteIndex", args);
|
|
230
|
-
const { indexName } = params;
|
|
216
|
+
async deleteIndex({ indexName }) {
|
|
231
217
|
try {
|
|
232
218
|
await this.client.deleteIndex(indexName);
|
|
233
219
|
} catch (error) {
|
|
@@ -235,8 +221,6 @@ This signature will be removed on May 20th, 2025.`
|
|
|
235
221
|
}
|
|
236
222
|
}
|
|
237
223
|
/**
|
|
238
|
-
* @deprecated Use {@link updateVector} instead. This method will be removed on May 20th, 2025.
|
|
239
|
-
*
|
|
240
224
|
* Updates a vector by its ID with the provided vector and/or metadata.
|
|
241
225
|
* @param indexName - The name of the index containing the vector.
|
|
242
226
|
* @param id - The ID of the vector to update.
|
|
@@ -247,30 +231,7 @@ This signature will be removed on May 20th, 2025.`
|
|
|
247
231
|
* @returns A promise that resolves when the update is complete.
|
|
248
232
|
* @throws Will throw an error if no updates are provided or if the update operation fails.
|
|
249
233
|
*/
|
|
250
|
-
async
|
|
251
|
-
this.logger.warn(
|
|
252
|
-
`Deprecation Warning: updateIndexById() is deprecated.
|
|
253
|
-
Please use updateVector() instead.
|
|
254
|
-
updateIndexById() will be removed on May 20th, 2025.`
|
|
255
|
-
);
|
|
256
|
-
await this.updateVector({ indexName, id, update, namespace });
|
|
257
|
-
}
|
|
258
|
-
/**
|
|
259
|
-
* Updates a vector by its ID with the provided vector and/or metadata.
|
|
260
|
-
* @param indexName - The name of the index containing the vector.
|
|
261
|
-
* @param id - The ID of the vector to update.
|
|
262
|
-
* @param update - An object containing the vector and/or metadata to update.
|
|
263
|
-
* @param update.vector - An optional array of numbers representing the new vector.
|
|
264
|
-
* @param update.metadata - An optional record containing the new metadata.
|
|
265
|
-
* @param namespace - The namespace of the index (optional).
|
|
266
|
-
* @returns A promise that resolves when the update is complete.
|
|
267
|
-
* @throws Will throw an error if no updates are provided or if the update operation fails.
|
|
268
|
-
*/
|
|
269
|
-
async updateVector(...args) {
|
|
270
|
-
const params = this.normalizeArgs("updateVector", args, [
|
|
271
|
-
"namespace"
|
|
272
|
-
]);
|
|
273
|
-
const { indexName, id, update, namespace } = params;
|
|
234
|
+
async updateVector({ indexName, id, update, namespace }) {
|
|
274
235
|
try {
|
|
275
236
|
if (!update.vector && !update.metadata) {
|
|
276
237
|
throw new Error("No updates provided");
|
|
@@ -288,24 +249,6 @@ This signature will be removed on May 20th, 2025.`
|
|
|
288
249
|
throw new Error(`Failed to update vector by id: ${id} for index name: ${indexName}: ${error.message}`);
|
|
289
250
|
}
|
|
290
251
|
}
|
|
291
|
-
/**
|
|
292
|
-
* @deprecated Use {@link deleteVector} instead. This method will be removed on May 20th, 2025.
|
|
293
|
-
*
|
|
294
|
-
* Deletes a vector by its ID.
|
|
295
|
-
* @param indexName - The name of the index containing the vector.
|
|
296
|
-
* @param id - The ID of the vector to delete.
|
|
297
|
-
* @param namespace - The namespace of the index (optional).
|
|
298
|
-
* @returns A promise that resolves when the deletion is complete.
|
|
299
|
-
* @throws Will throw an error if the deletion operation fails.
|
|
300
|
-
*/
|
|
301
|
-
async deleteIndexById(indexName, id, namespace) {
|
|
302
|
-
this.logger.warn(
|
|
303
|
-
`Deprecation Warning: deleteIndexById() is deprecated.
|
|
304
|
-
Please use deleteVector() instead.
|
|
305
|
-
deleteIndexById() will be removed on May 20th, 2025.`
|
|
306
|
-
);
|
|
307
|
-
await this.deleteVector({ indexName, id, namespace });
|
|
308
|
-
}
|
|
309
252
|
/**
|
|
310
253
|
* Deletes a vector by its ID.
|
|
311
254
|
* @param indexName - The name of the index containing the vector.
|
|
@@ -314,11 +257,7 @@ This signature will be removed on May 20th, 2025.`
|
|
|
314
257
|
* @returns A promise that resolves when the deletion is complete.
|
|
315
258
|
* @throws Will throw an error if the deletion operation fails.
|
|
316
259
|
*/
|
|
317
|
-
async deleteVector(
|
|
318
|
-
const params = this.normalizeArgs("deleteVector", args, [
|
|
319
|
-
"namespace"
|
|
320
|
-
]);
|
|
321
|
-
const { indexName, id, namespace } = params;
|
|
260
|
+
async deleteVector({ indexName, id, namespace }) {
|
|
322
261
|
try {
|
|
323
262
|
const index = this.client.Index(indexName).namespace(namespace || "");
|
|
324
263
|
await index.deleteOne(id);
|
package/dist/index.js
CHANGED
|
@@ -83,28 +83,16 @@ var PineconeFilterTranslator = class extends BaseFilterTranslator {
|
|
|
83
83
|
// src/vector/index.ts
|
|
84
84
|
var PineconeVector = class extends MastraVector {
|
|
85
85
|
client;
|
|
86
|
-
|
|
86
|
+
/**
|
|
87
|
+
* Creates a new PineconeVector client.
|
|
88
|
+
* @param apiKey - The API key for Pinecone.
|
|
89
|
+
* @param environment - The environment for Pinecone.
|
|
90
|
+
*/
|
|
91
|
+
constructor({ apiKey, environment }) {
|
|
87
92
|
super();
|
|
88
|
-
let apiKey;
|
|
89
|
-
let env;
|
|
90
|
-
if (typeof paramsOrApiKey === "string") {
|
|
91
|
-
if (typeof console !== "undefined" && console.warn) {
|
|
92
|
-
console.warn(
|
|
93
|
-
`Deprecation Warning: Passing apiKey and environment as positional arguments to PineconeVector constructor is deprecated.
|
|
94
|
-
Please use an object parameter instead:
|
|
95
|
-
new PineconeVector({ apiKey, environment })
|
|
96
|
-
This signature will be removed on May 20th, 2025.`
|
|
97
|
-
);
|
|
98
|
-
}
|
|
99
|
-
apiKey = paramsOrApiKey;
|
|
100
|
-
env = environment;
|
|
101
|
-
} else {
|
|
102
|
-
apiKey = paramsOrApiKey.apiKey;
|
|
103
|
-
env = paramsOrApiKey.environment;
|
|
104
|
-
}
|
|
105
93
|
const opts = { apiKey };
|
|
106
|
-
if (
|
|
107
|
-
opts["controllerHostUrl"] =
|
|
94
|
+
if (environment) {
|
|
95
|
+
opts["controllerHostUrl"] = environment;
|
|
108
96
|
}
|
|
109
97
|
const baseClient = new Pinecone(opts);
|
|
110
98
|
const telemetry = this.__getTelemetry();
|
|
@@ -118,9 +106,7 @@ This signature will be removed on May 20th, 2025.`
|
|
|
118
106
|
get indexSeparator() {
|
|
119
107
|
return "-";
|
|
120
108
|
}
|
|
121
|
-
async createIndex(
|
|
122
|
-
const params = this.normalizeArgs("createIndex", args);
|
|
123
|
-
const { indexName, dimension, metric = "cosine" } = params;
|
|
109
|
+
async createIndex({ indexName, dimension, metric = "cosine" }) {
|
|
124
110
|
if (!Number.isInteger(dimension) || dimension <= 0) {
|
|
125
111
|
throw new Error("Dimension must be a positive integer");
|
|
126
112
|
}
|
|
@@ -148,12 +134,14 @@ This signature will be removed on May 20th, 2025.`
|
|
|
148
134
|
throw error;
|
|
149
135
|
}
|
|
150
136
|
}
|
|
151
|
-
async upsert(
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
137
|
+
async upsert({
|
|
138
|
+
indexName,
|
|
139
|
+
vectors,
|
|
140
|
+
metadata,
|
|
141
|
+
ids,
|
|
142
|
+
namespace,
|
|
143
|
+
sparseVectors
|
|
144
|
+
}) {
|
|
157
145
|
const index = this.client.Index(indexName).namespace(namespace || "");
|
|
158
146
|
const vectorIds = ids || vectors.map(() => crypto.randomUUID());
|
|
159
147
|
const records = vectors.map((vector, i) => ({
|
|
@@ -173,12 +161,15 @@ This signature will be removed on May 20th, 2025.`
|
|
|
173
161
|
const translator = new PineconeFilterTranslator();
|
|
174
162
|
return translator.translate(filter);
|
|
175
163
|
}
|
|
176
|
-
async query(
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
164
|
+
async query({
|
|
165
|
+
indexName,
|
|
166
|
+
queryVector,
|
|
167
|
+
topK = 10,
|
|
168
|
+
filter,
|
|
169
|
+
includeVector = false,
|
|
170
|
+
namespace,
|
|
171
|
+
sparseVector
|
|
172
|
+
}) {
|
|
182
173
|
const index = this.client.Index(indexName).namespace(namespace || "");
|
|
183
174
|
const translatedFilter = this.transformFilter(filter) ?? void 0;
|
|
184
175
|
const queryParams = {
|
|
@@ -206,13 +197,10 @@ This signature will be removed on May 20th, 2025.`
|
|
|
206
197
|
/**
|
|
207
198
|
* Retrieves statistics about a vector index.
|
|
208
199
|
*
|
|
209
|
-
* @param
|
|
210
|
-
* @param params.indexName - The name of the index to describe
|
|
200
|
+
* @param {string} indexName - The name of the index to describe
|
|
211
201
|
* @returns A promise that resolves to the index statistics including dimension, count and metric
|
|
212
202
|
*/
|
|
213
|
-
async describeIndex(
|
|
214
|
-
const params = this.normalizeArgs("describeIndex", args);
|
|
215
|
-
const { indexName } = params;
|
|
203
|
+
async describeIndex({ indexName }) {
|
|
216
204
|
const index = this.client.Index(indexName);
|
|
217
205
|
const stats = await index.describeIndexStats();
|
|
218
206
|
const description = await this.client.describeIndex(indexName);
|
|
@@ -223,9 +211,7 @@ This signature will be removed on May 20th, 2025.`
|
|
|
223
211
|
namespaces: stats.namespaces
|
|
224
212
|
};
|
|
225
213
|
}
|
|
226
|
-
async deleteIndex(
|
|
227
|
-
const params = this.normalizeArgs("deleteIndex", args);
|
|
228
|
-
const { indexName } = params;
|
|
214
|
+
async deleteIndex({ indexName }) {
|
|
229
215
|
try {
|
|
230
216
|
await this.client.deleteIndex(indexName);
|
|
231
217
|
} catch (error) {
|
|
@@ -233,8 +219,6 @@ This signature will be removed on May 20th, 2025.`
|
|
|
233
219
|
}
|
|
234
220
|
}
|
|
235
221
|
/**
|
|
236
|
-
* @deprecated Use {@link updateVector} instead. This method will be removed on May 20th, 2025.
|
|
237
|
-
*
|
|
238
222
|
* Updates a vector by its ID with the provided vector and/or metadata.
|
|
239
223
|
* @param indexName - The name of the index containing the vector.
|
|
240
224
|
* @param id - The ID of the vector to update.
|
|
@@ -245,30 +229,7 @@ This signature will be removed on May 20th, 2025.`
|
|
|
245
229
|
* @returns A promise that resolves when the update is complete.
|
|
246
230
|
* @throws Will throw an error if no updates are provided or if the update operation fails.
|
|
247
231
|
*/
|
|
248
|
-
async
|
|
249
|
-
this.logger.warn(
|
|
250
|
-
`Deprecation Warning: updateIndexById() is deprecated.
|
|
251
|
-
Please use updateVector() instead.
|
|
252
|
-
updateIndexById() will be removed on May 20th, 2025.`
|
|
253
|
-
);
|
|
254
|
-
await this.updateVector({ indexName, id, update, namespace });
|
|
255
|
-
}
|
|
256
|
-
/**
|
|
257
|
-
* Updates a vector by its ID with the provided vector and/or metadata.
|
|
258
|
-
* @param indexName - The name of the index containing the vector.
|
|
259
|
-
* @param id - The ID of the vector to update.
|
|
260
|
-
* @param update - An object containing the vector and/or metadata to update.
|
|
261
|
-
* @param update.vector - An optional array of numbers representing the new vector.
|
|
262
|
-
* @param update.metadata - An optional record containing the new metadata.
|
|
263
|
-
* @param namespace - The namespace of the index (optional).
|
|
264
|
-
* @returns A promise that resolves when the update is complete.
|
|
265
|
-
* @throws Will throw an error if no updates are provided or if the update operation fails.
|
|
266
|
-
*/
|
|
267
|
-
async updateVector(...args) {
|
|
268
|
-
const params = this.normalizeArgs("updateVector", args, [
|
|
269
|
-
"namespace"
|
|
270
|
-
]);
|
|
271
|
-
const { indexName, id, update, namespace } = params;
|
|
232
|
+
async updateVector({ indexName, id, update, namespace }) {
|
|
272
233
|
try {
|
|
273
234
|
if (!update.vector && !update.metadata) {
|
|
274
235
|
throw new Error("No updates provided");
|
|
@@ -286,24 +247,6 @@ This signature will be removed on May 20th, 2025.`
|
|
|
286
247
|
throw new Error(`Failed to update vector by id: ${id} for index name: ${indexName}: ${error.message}`);
|
|
287
248
|
}
|
|
288
249
|
}
|
|
289
|
-
/**
|
|
290
|
-
* @deprecated Use {@link deleteVector} instead. This method will be removed on May 20th, 2025.
|
|
291
|
-
*
|
|
292
|
-
* Deletes a vector by its ID.
|
|
293
|
-
* @param indexName - The name of the index containing the vector.
|
|
294
|
-
* @param id - The ID of the vector to delete.
|
|
295
|
-
* @param namespace - The namespace of the index (optional).
|
|
296
|
-
* @returns A promise that resolves when the deletion is complete.
|
|
297
|
-
* @throws Will throw an error if the deletion operation fails.
|
|
298
|
-
*/
|
|
299
|
-
async deleteIndexById(indexName, id, namespace) {
|
|
300
|
-
this.logger.warn(
|
|
301
|
-
`Deprecation Warning: deleteIndexById() is deprecated.
|
|
302
|
-
Please use deleteVector() instead.
|
|
303
|
-
deleteIndexById() will be removed on May 20th, 2025.`
|
|
304
|
-
);
|
|
305
|
-
await this.deleteVector({ indexName, id, namespace });
|
|
306
|
-
}
|
|
307
250
|
/**
|
|
308
251
|
* Deletes a vector by its ID.
|
|
309
252
|
* @param indexName - The name of the index containing the vector.
|
|
@@ -312,11 +255,7 @@ This signature will be removed on May 20th, 2025.`
|
|
|
312
255
|
* @returns A promise that resolves when the deletion is complete.
|
|
313
256
|
* @throws Will throw an error if the deletion operation fails.
|
|
314
257
|
*/
|
|
315
|
-
async deleteVector(
|
|
316
|
-
const params = this.normalizeArgs("deleteVector", args, [
|
|
317
|
-
"namespace"
|
|
318
|
-
]);
|
|
319
|
-
const { indexName, id, namespace } = params;
|
|
258
|
+
async deleteVector({ indexName, id, namespace }) {
|
|
320
259
|
try {
|
|
321
260
|
const index = this.client.Index(indexName).namespace(namespace || "");
|
|
322
261
|
await index.deleteOne(id);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mastra/pinecone",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0-alpha.1",
|
|
4
4
|
"description": "Pinecone 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
|
-
"@pinecone-database/pinecone": "^3.0.3"
|
|
24
|
-
"@mastra/core": "^0.9.5-alpha.0"
|
|
23
|
+
"@pinecone-database/pinecone": "^3.0.3"
|
|
25
24
|
},
|
|
26
25
|
"devDependencies": {
|
|
27
26
|
"@microsoft/api-extractor": "^7.52.5",
|
|
@@ -31,7 +30,11 @@
|
|
|
31
30
|
"tsup": "^8.4.0",
|
|
32
31
|
"typescript": "^5.8.2",
|
|
33
32
|
"vitest": "^3.1.2",
|
|
34
|
-
"@internal/lint": "0.0.5"
|
|
33
|
+
"@internal/lint": "0.0.5",
|
|
34
|
+
"@mastra/core": "0.10.0-alpha.1"
|
|
35
|
+
},
|
|
36
|
+
"peerDependencies": {
|
|
37
|
+
"@mastra/core": "^0.9.4"
|
|
35
38
|
},
|
|
36
39
|
"scripts": {
|
|
37
40
|
"build": "tsup src/index.ts --format esm,cjs --experimental-dts --clean --treeshake=smallest --splitting",
|
package/src/vector/index.test.ts
CHANGED
|
@@ -1478,144 +1478,4 @@ describe.skip('PineconeVector Integration Tests', () => {
|
|
|
1478
1478
|
expect(hybridResults).toHaveLength(1);
|
|
1479
1479
|
});
|
|
1480
1480
|
});
|
|
1481
|
-
|
|
1482
|
-
describe('Deprecation Warnings', () => {
|
|
1483
|
-
const indexName = 'testdeprecationwarnings';
|
|
1484
|
-
|
|
1485
|
-
const indexName2 = 'testdeprecationwarnings2';
|
|
1486
|
-
|
|
1487
|
-
const indexName3 = 'testdeprecationwarnings3';
|
|
1488
|
-
|
|
1489
|
-
const indexName4 = 'testdeprecationwarnings4';
|
|
1490
|
-
|
|
1491
|
-
let warnSpy;
|
|
1492
|
-
|
|
1493
|
-
beforeAll(async () => {
|
|
1494
|
-
try {
|
|
1495
|
-
await vectorDB.deleteIndex({ indexName });
|
|
1496
|
-
} catch {
|
|
1497
|
-
// Ignore errors if index doesn't exist
|
|
1498
|
-
}
|
|
1499
|
-
try {
|
|
1500
|
-
await vectorDB.deleteIndex({ indexName: indexName2 });
|
|
1501
|
-
} catch {
|
|
1502
|
-
// Ignore errors if index doesn't exist
|
|
1503
|
-
}
|
|
1504
|
-
try {
|
|
1505
|
-
await vectorDB.deleteIndex({ indexName: indexName3 });
|
|
1506
|
-
} catch {
|
|
1507
|
-
// Ignore errors if index doesn't exist
|
|
1508
|
-
}
|
|
1509
|
-
try {
|
|
1510
|
-
await vectorDB.deleteIndex({ indexName: indexName4 });
|
|
1511
|
-
} catch {
|
|
1512
|
-
// Ignore errors if index doesn't exist
|
|
1513
|
-
}
|
|
1514
|
-
await vectorDB.createIndex({ indexName: indexName, dimension: 3 });
|
|
1515
|
-
await waitUntilReady(vectorDB, indexName);
|
|
1516
|
-
});
|
|
1517
|
-
|
|
1518
|
-
afterAll(async () => {
|
|
1519
|
-
try {
|
|
1520
|
-
await vectorDB.deleteIndex({ indexName });
|
|
1521
|
-
} catch {
|
|
1522
|
-
// Ignore errors if index doesn't exist
|
|
1523
|
-
}
|
|
1524
|
-
try {
|
|
1525
|
-
await vectorDB.deleteIndex({ indexName: indexName2 });
|
|
1526
|
-
} catch {
|
|
1527
|
-
// Ignore errors if index doesn't exist
|
|
1528
|
-
}
|
|
1529
|
-
try {
|
|
1530
|
-
await vectorDB.deleteIndex({ indexName: indexName3 });
|
|
1531
|
-
} catch {
|
|
1532
|
-
// Ignore errors if index doesn't exist
|
|
1533
|
-
}
|
|
1534
|
-
try {
|
|
1535
|
-
await vectorDB.deleteIndex({ indexName: indexName4 });
|
|
1536
|
-
} catch {
|
|
1537
|
-
// Ignore errors if index doesn't exist
|
|
1538
|
-
}
|
|
1539
|
-
});
|
|
1540
|
-
|
|
1541
|
-
beforeEach(async () => {
|
|
1542
|
-
warnSpy = vi.spyOn(vectorDB['logger'], 'warn');
|
|
1543
|
-
});
|
|
1544
|
-
|
|
1545
|
-
afterEach(async () => {
|
|
1546
|
-
warnSpy.mockRestore();
|
|
1547
|
-
});
|
|
1548
|
-
|
|
1549
|
-
it('should show deprecation warning when using individual args for createIndex', async () => {
|
|
1550
|
-
await vectorDB.createIndex(indexName2, 3, 'cosine');
|
|
1551
|
-
await waitUntilReady(vectorDB, indexName2);
|
|
1552
|
-
expect(warnSpy).toHaveBeenCalledWith(
|
|
1553
|
-
expect.stringContaining('Deprecation Warning: Passing individual arguments to createIndex() is deprecated'),
|
|
1554
|
-
);
|
|
1555
|
-
});
|
|
1556
|
-
|
|
1557
|
-
it('should show deprecation warning when using individual args for upsert', async () => {
|
|
1558
|
-
await vectorDB.upsert(indexName, [[1, 2, 3]], [{ test: 'data' }]);
|
|
1559
|
-
|
|
1560
|
-
expect(warnSpy).toHaveBeenCalledWith(
|
|
1561
|
-
expect.stringContaining('Deprecation Warning: Passing individual arguments to upsert() is deprecated'),
|
|
1562
|
-
);
|
|
1563
|
-
});
|
|
1564
|
-
|
|
1565
|
-
it('should show deprecation warning when using individual args for query', async () => {
|
|
1566
|
-
await vectorDB.query(indexName, [1, 2, 3], 5);
|
|
1567
|
-
|
|
1568
|
-
expect(warnSpy).toHaveBeenCalledWith(
|
|
1569
|
-
expect.stringContaining('Deprecation Warning: Passing individual arguments to query() is deprecated'),
|
|
1570
|
-
);
|
|
1571
|
-
});
|
|
1572
|
-
|
|
1573
|
-
it('should not show deprecation warning when using object param for query', async () => {
|
|
1574
|
-
await vectorDB.query({
|
|
1575
|
-
indexName,
|
|
1576
|
-
queryVector: [1, 2, 3],
|
|
1577
|
-
topK: 5,
|
|
1578
|
-
});
|
|
1579
|
-
|
|
1580
|
-
expect(warnSpy).not.toHaveBeenCalled();
|
|
1581
|
-
});
|
|
1582
|
-
|
|
1583
|
-
it('should not show deprecation warning when using object param for createIndex', async () => {
|
|
1584
|
-
await vectorDB.createIndex({
|
|
1585
|
-
indexName: indexName3,
|
|
1586
|
-
dimension: 3,
|
|
1587
|
-
metric: 'cosine',
|
|
1588
|
-
});
|
|
1589
|
-
|
|
1590
|
-
expect(warnSpy).not.toHaveBeenCalled();
|
|
1591
|
-
});
|
|
1592
|
-
|
|
1593
|
-
it('should not show deprecation warning when using object param for upsert', async () => {
|
|
1594
|
-
await vectorDB.upsert({
|
|
1595
|
-
indexName,
|
|
1596
|
-
vectors: [[1, 2, 3]],
|
|
1597
|
-
metadata: [{ test: 'data' }],
|
|
1598
|
-
});
|
|
1599
|
-
|
|
1600
|
-
expect(warnSpy).not.toHaveBeenCalled();
|
|
1601
|
-
});
|
|
1602
|
-
|
|
1603
|
-
it('should maintain backward compatibility with individual args', async () => {
|
|
1604
|
-
// Query
|
|
1605
|
-
const queryResults = await vectorDB.query(indexName, [1, 2, 3], 5);
|
|
1606
|
-
expect(Array.isArray(queryResults)).toBe(true);
|
|
1607
|
-
|
|
1608
|
-
// CreateIndex
|
|
1609
|
-
await expect(vectorDB.createIndex(indexName4, 3, 'cosine')).resolves.not.toThrow();
|
|
1610
|
-
await waitUntilReady(vectorDB, indexName4);
|
|
1611
|
-
// Upsert
|
|
1612
|
-
const upsertResults = await vectorDB.upsert({
|
|
1613
|
-
indexName,
|
|
1614
|
-
vectors: [[1, 2, 3]],
|
|
1615
|
-
metadata: [{ test: 'data' }],
|
|
1616
|
-
});
|
|
1617
|
-
expect(Array.isArray(upsertResults)).toBe(true);
|
|
1618
|
-
expect(upsertResults).toHaveLength(1);
|
|
1619
|
-
});
|
|
1620
|
-
});
|
|
1621
1481
|
});
|
package/src/vector/index.ts
CHANGED
|
@@ -5,15 +5,10 @@ import type {
|
|
|
5
5
|
CreateIndexParams,
|
|
6
6
|
UpsertVectorParams,
|
|
7
7
|
QueryVectorParams,
|
|
8
|
-
ParamsToArgs,
|
|
9
|
-
QueryVectorArgs,
|
|
10
|
-
UpsertVectorArgs,
|
|
11
8
|
DescribeIndexParams,
|
|
12
9
|
DeleteIndexParams,
|
|
13
10
|
DeleteVectorParams,
|
|
14
|
-
DeleteVectorArgs,
|
|
15
11
|
UpdateVectorParams,
|
|
16
|
-
UpdateVectorArgs,
|
|
17
12
|
} from '@mastra/core/vector';
|
|
18
13
|
import type { VectorFilter } from '@mastra/core/vector/filter';
|
|
19
14
|
import { Pinecone } from '@pinecone-database/pinecone';
|
|
@@ -35,60 +30,32 @@ interface PineconeQueryVectorParams extends QueryVectorParams {
|
|
|
35
30
|
sparseVector?: RecordSparseValues;
|
|
36
31
|
}
|
|
37
32
|
|
|
38
|
-
type PineconeQueryVectorArgs = [...QueryVectorArgs, string?, RecordSparseValues?];
|
|
39
|
-
|
|
40
33
|
interface PineconeUpsertVectorParams extends UpsertVectorParams {
|
|
41
34
|
namespace?: string;
|
|
42
35
|
sparseVectors?: RecordSparseValues[];
|
|
43
36
|
}
|
|
44
37
|
|
|
45
|
-
type PineconeUpsertVectorArgs = [...UpsertVectorArgs, string?, RecordSparseValues[]?];
|
|
46
|
-
|
|
47
38
|
interface PineconeUpdateVectorParams extends UpdateVectorParams {
|
|
48
39
|
namespace?: string;
|
|
49
40
|
}
|
|
50
41
|
|
|
51
|
-
type PineconeUpdateVectorArgs = [...UpdateVectorArgs, string?];
|
|
52
|
-
|
|
53
42
|
interface PineconeDeleteVectorParams extends DeleteVectorParams {
|
|
54
43
|
namespace?: string;
|
|
55
44
|
}
|
|
56
45
|
|
|
57
|
-
type PineconeDeleteVectorArgs = [...DeleteVectorArgs, string?];
|
|
58
|
-
|
|
59
46
|
export class PineconeVector extends MastraVector {
|
|
60
47
|
private client: Pinecone;
|
|
61
48
|
|
|
62
|
-
/**
|
|
63
|
-
* @deprecated Passing apiKey and environment as positional arguments is deprecated.
|
|
64
|
-
* Use the object parameter instead. This signature will be removed on May 20th, 2025.
|
|
65
|
-
*/
|
|
66
|
-
constructor(apiKey: string, environment?: string);
|
|
67
49
|
/**
|
|
68
50
|
* Creates a new PineconeVector client.
|
|
69
|
-
* @param
|
|
51
|
+
* @param apiKey - The API key for Pinecone.
|
|
52
|
+
* @param environment - The environment for Pinecone.
|
|
70
53
|
*/
|
|
71
|
-
constructor(
|
|
72
|
-
constructor(paramsOrApiKey: { apiKey: string; environment?: string } | string, environment?: string) {
|
|
54
|
+
constructor({ apiKey, environment }: { apiKey: string; environment?: string }) {
|
|
73
55
|
super();
|
|
74
|
-
let apiKey: string;
|
|
75
|
-
let env: string | undefined;
|
|
76
|
-
if (typeof paramsOrApiKey === 'string') {
|
|
77
|
-
// DEPRECATION WARNING
|
|
78
|
-
if (typeof console !== 'undefined' && console.warn) {
|
|
79
|
-
console.warn(
|
|
80
|
-
`Deprecation Warning: Passing apiKey and environment as positional arguments to PineconeVector constructor is deprecated.\nPlease use an object parameter instead:\n new PineconeVector({ apiKey, environment })\nThis signature will be removed on May 20th, 2025.`,
|
|
81
|
-
);
|
|
82
|
-
}
|
|
83
|
-
apiKey = paramsOrApiKey;
|
|
84
|
-
env = environment;
|
|
85
|
-
} else {
|
|
86
|
-
apiKey = paramsOrApiKey.apiKey;
|
|
87
|
-
env = paramsOrApiKey.environment;
|
|
88
|
-
}
|
|
89
56
|
const opts: { apiKey: string; controllerHostUrl?: string } = { apiKey };
|
|
90
|
-
if (
|
|
91
|
-
opts['controllerHostUrl'] =
|
|
57
|
+
if (environment) {
|
|
58
|
+
opts['controllerHostUrl'] = environment;
|
|
92
59
|
}
|
|
93
60
|
const baseClient = new Pinecone(opts);
|
|
94
61
|
const telemetry = this.__getTelemetry();
|
|
@@ -105,11 +72,7 @@ export class PineconeVector extends MastraVector {
|
|
|
105
72
|
return '-';
|
|
106
73
|
}
|
|
107
74
|
|
|
108
|
-
async createIndex(
|
|
109
|
-
const params = this.normalizeArgs<CreateIndexParams>('createIndex', args);
|
|
110
|
-
|
|
111
|
-
const { indexName, dimension, metric = 'cosine' } = params;
|
|
112
|
-
|
|
75
|
+
async createIndex({ indexName, dimension, metric = 'cosine' }: CreateIndexParams): Promise<void> {
|
|
113
76
|
if (!Number.isInteger(dimension) || dimension <= 0) {
|
|
114
77
|
throw new Error('Dimension must be a positive integer');
|
|
115
78
|
}
|
|
@@ -145,14 +108,14 @@ export class PineconeVector extends MastraVector {
|
|
|
145
108
|
}
|
|
146
109
|
}
|
|
147
110
|
|
|
148
|
-
async upsert(
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
111
|
+
async upsert({
|
|
112
|
+
indexName,
|
|
113
|
+
vectors,
|
|
114
|
+
metadata,
|
|
115
|
+
ids,
|
|
116
|
+
namespace,
|
|
117
|
+
sparseVectors,
|
|
118
|
+
}: PineconeUpsertVectorParams): Promise<string[]> {
|
|
156
119
|
const index = this.client.Index(indexName).namespace(namespace || '');
|
|
157
120
|
|
|
158
121
|
// Generate IDs if not provided
|
|
@@ -180,14 +143,15 @@ export class PineconeVector extends MastraVector {
|
|
|
180
143
|
return translator.translate(filter);
|
|
181
144
|
}
|
|
182
145
|
|
|
183
|
-
async query(
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
146
|
+
async query({
|
|
147
|
+
indexName,
|
|
148
|
+
queryVector,
|
|
149
|
+
topK = 10,
|
|
150
|
+
filter,
|
|
151
|
+
includeVector = false,
|
|
152
|
+
namespace,
|
|
153
|
+
sparseVector,
|
|
154
|
+
}: PineconeQueryVectorParams): Promise<QueryResult[]> {
|
|
191
155
|
const index = this.client.Index(indexName).namespace(namespace || '');
|
|
192
156
|
|
|
193
157
|
const translatedFilter = this.transformFilter(filter) ?? undefined;
|
|
@@ -223,13 +187,10 @@ export class PineconeVector extends MastraVector {
|
|
|
223
187
|
/**
|
|
224
188
|
* Retrieves statistics about a vector index.
|
|
225
189
|
*
|
|
226
|
-
* @param
|
|
227
|
-
* @param params.indexName - The name of the index to describe
|
|
190
|
+
* @param {string} indexName - The name of the index to describe
|
|
228
191
|
* @returns A promise that resolves to the index statistics including dimension, count and metric
|
|
229
192
|
*/
|
|
230
|
-
async describeIndex(
|
|
231
|
-
const params = this.normalizeArgs<DescribeIndexParams>('describeIndex', args);
|
|
232
|
-
const { indexName } = params;
|
|
193
|
+
async describeIndex({ indexName }: DescribeIndexParams): Promise<PineconeIndexStats> {
|
|
233
194
|
const index = this.client.Index(indexName);
|
|
234
195
|
const stats = await index.describeIndexStats();
|
|
235
196
|
const description = await this.client.describeIndex(indexName);
|
|
@@ -242,41 +203,13 @@ export class PineconeVector extends MastraVector {
|
|
|
242
203
|
};
|
|
243
204
|
}
|
|
244
205
|
|
|
245
|
-
async deleteIndex(
|
|
246
|
-
const params = this.normalizeArgs<DeleteIndexParams>('deleteIndex', args);
|
|
247
|
-
const { indexName } = params;
|
|
206
|
+
async deleteIndex({ indexName }: DeleteIndexParams): Promise<void> {
|
|
248
207
|
try {
|
|
249
208
|
await this.client.deleteIndex(indexName);
|
|
250
209
|
} catch (error: any) {
|
|
251
210
|
throw new Error(`Failed to delete Pinecone index: ${error.message}`);
|
|
252
211
|
}
|
|
253
212
|
}
|
|
254
|
-
/**
|
|
255
|
-
* @deprecated Use {@link updateVector} instead. This method will be removed on May 20th, 2025.
|
|
256
|
-
*
|
|
257
|
-
* Updates a vector by its ID with the provided vector and/or metadata.
|
|
258
|
-
* @param indexName - The name of the index containing the vector.
|
|
259
|
-
* @param id - The ID of the vector to update.
|
|
260
|
-
* @param update - An object containing the vector and/or metadata to update.
|
|
261
|
-
* @param update.vector - An optional array of numbers representing the new vector.
|
|
262
|
-
* @param update.metadata - An optional record containing the new metadata.
|
|
263
|
-
* @param namespace - The namespace of the index (optional).
|
|
264
|
-
* @returns A promise that resolves when the update is complete.
|
|
265
|
-
* @throws Will throw an error if no updates are provided or if the update operation fails.
|
|
266
|
-
*/
|
|
267
|
-
async updateIndexById(
|
|
268
|
-
indexName: string,
|
|
269
|
-
id: string,
|
|
270
|
-
update: { vector?: number[]; metadata?: Record<string, any> },
|
|
271
|
-
namespace?: string,
|
|
272
|
-
): Promise<void> {
|
|
273
|
-
this.logger.warn(
|
|
274
|
-
`Deprecation Warning: updateIndexById() is deprecated.
|
|
275
|
-
Please use updateVector() instead.
|
|
276
|
-
updateIndexById() will be removed on May 20th, 2025.`,
|
|
277
|
-
);
|
|
278
|
-
await this.updateVector({ indexName, id, update, namespace });
|
|
279
|
-
}
|
|
280
213
|
|
|
281
214
|
/**
|
|
282
215
|
* Updates a vector by its ID with the provided vector and/or metadata.
|
|
@@ -289,11 +222,7 @@ export class PineconeVector extends MastraVector {
|
|
|
289
222
|
* @returns A promise that resolves when the update is complete.
|
|
290
223
|
* @throws Will throw an error if no updates are provided or if the update operation fails.
|
|
291
224
|
*/
|
|
292
|
-
async updateVector(
|
|
293
|
-
const params = this.normalizeArgs<PineconeUpdateVectorParams, PineconeUpdateVectorArgs>('updateVector', args, [
|
|
294
|
-
'namespace',
|
|
295
|
-
]);
|
|
296
|
-
const { indexName, id, update, namespace } = params;
|
|
225
|
+
async updateVector({ indexName, id, update, namespace }: PineconeUpdateVectorParams): Promise<void> {
|
|
297
226
|
try {
|
|
298
227
|
if (!update.vector && !update.metadata) {
|
|
299
228
|
throw new Error('No updates provided');
|
|
@@ -317,25 +246,6 @@ export class PineconeVector extends MastraVector {
|
|
|
317
246
|
}
|
|
318
247
|
}
|
|
319
248
|
|
|
320
|
-
/**
|
|
321
|
-
* @deprecated Use {@link deleteVector} instead. This method will be removed on May 20th, 2025.
|
|
322
|
-
*
|
|
323
|
-
* Deletes a vector by its ID.
|
|
324
|
-
* @param indexName - The name of the index containing the vector.
|
|
325
|
-
* @param id - The ID of the vector to delete.
|
|
326
|
-
* @param namespace - The namespace of the index (optional).
|
|
327
|
-
* @returns A promise that resolves when the deletion is complete.
|
|
328
|
-
* @throws Will throw an error if the deletion operation fails.
|
|
329
|
-
*/
|
|
330
|
-
async deleteIndexById(indexName: string, id: string, namespace?: string): Promise<void> {
|
|
331
|
-
this.logger.warn(
|
|
332
|
-
`Deprecation Warning: deleteIndexById() is deprecated.
|
|
333
|
-
Please use deleteVector() instead.
|
|
334
|
-
deleteIndexById() will be removed on May 20th, 2025.`,
|
|
335
|
-
);
|
|
336
|
-
await this.deleteVector({ indexName, id, namespace });
|
|
337
|
-
}
|
|
338
|
-
|
|
339
249
|
/**
|
|
340
250
|
* Deletes a vector by its ID.
|
|
341
251
|
* @param indexName - The name of the index containing the vector.
|
|
@@ -344,11 +254,7 @@ export class PineconeVector extends MastraVector {
|
|
|
344
254
|
* @returns A promise that resolves when the deletion is complete.
|
|
345
255
|
* @throws Will throw an error if the deletion operation fails.
|
|
346
256
|
*/
|
|
347
|
-
async deleteVector(
|
|
348
|
-
const params = this.normalizeArgs<PineconeDeleteVectorParams, PineconeDeleteVectorArgs>('deleteVector', args, [
|
|
349
|
-
'namespace',
|
|
350
|
-
]);
|
|
351
|
-
const { indexName, id, namespace } = params;
|
|
257
|
+
async deleteVector({ indexName, id, namespace }: PineconeDeleteVectorParams): Promise<void> {
|
|
352
258
|
try {
|
|
353
259
|
const index = this.client.Index(indexName).namespace(namespace || '');
|
|
354
260
|
await index.deleteOne(id);
|