@mastra/pinecone 0.1.0-alpha.29

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md ADDED
@@ -0,0 +1,267 @@
1
+ # @mastra/pinecone
2
+
3
+ ## 0.1.0-alpha.29
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies [5285356]
8
+ - @mastra/core@0.2.0-alpha.93
9
+
10
+ ## 0.1.0-alpha.28
11
+
12
+ ### Minor Changes
13
+
14
+ - c87eb4e: Move Pinecone package from `@mastra/vector-pinecone` to `@mastra/pinecone`.
15
+
16
+ - Move package to `stores/pinecone`
17
+ - Reorganize source files into `src/vector`
18
+ - Add deprecation notice to old package
19
+ - Update documentation and examples
20
+ - No breaking changes in functionality
21
+
22
+ ## 0.1.0-alpha.1
23
+
24
+ ### Major Changes
25
+
26
+ - Package renamed from @mastra/vector-pinecone to @mastra/pinecone
27
+ - Moved package to stores/ directory for better organization
28
+ - All functionality remains the same
29
+
30
+ ### Migration
31
+
32
+ To migrate from @mastra/vector-pinecone:
33
+
34
+ 1. Remove @mastra/vector-pinecone from dependencies
35
+ 2. Install @mastra/pinecone
36
+ 3. Update imports from '@mastra/vector-pinecone' to '@mastra/pinecone'
37
+
38
+ ### Previous History
39
+
40
+ This package was previously published as @mastra/vector-pinecone. Key changes from that history:
41
+
42
+ - Added Unified Filter API support for improved query filtering
43
+ - Updated operator validation and handling
44
+ - Implemented new filtering for vectorQueryTool
45
+ - Added comprehensive testing for Pinecone Unified Filter API
46
+ - Added automatic batching for large upserts
47
+ - Various dependency updates and bug fixes
48
+
49
+ ## 0.1.0-alpha.27
50
+
51
+ ### Patch Changes
52
+
53
+ - Updated dependencies [4d4f6b6]
54
+ - @mastra/core@0.2.0-alpha.92
55
+
56
+ ## 0.1.0-alpha.26
57
+
58
+ ### Patch Changes
59
+
60
+ - a10b7a3: Implemented new filtering for vectorQueryTool and updated docs
61
+ - Updated dependencies [d7d465a]
62
+ - Updated dependencies [d7d465a]
63
+ - Updated dependencies [2017553]
64
+ - Updated dependencies [a10b7a3]
65
+ - Updated dependencies [16e5b04]
66
+ - @mastra/core@0.2.0-alpha.91
67
+
68
+ ## 0.1.0-alpha.25
69
+
70
+ ### Patch Changes
71
+
72
+ - Updated dependencies [8151f44]
73
+ - Updated dependencies [e897f1c]
74
+ - Updated dependencies [3700be1]
75
+ - @mastra/core@0.2.0-alpha.90
76
+
77
+ ## 0.1.0-alpha.24
78
+
79
+ ### Patch Changes
80
+
81
+ - Updated dependencies [27275c9]
82
+ - @mastra/core@0.2.0-alpha.89
83
+
84
+ ## 0.1.0-alpha.23
85
+
86
+ ### Patch Changes
87
+
88
+ - ccbc581: Updated operator validation and handling for all vector stores
89
+ - Updated dependencies [ccbc581]
90
+ - @mastra/core@0.2.0-alpha.88
91
+
92
+ ## 0.1.0-alpha.22
93
+
94
+ ### Patch Changes
95
+
96
+ - Updated dependencies [7365b6c]
97
+ - @mastra/core@0.2.0-alpha.87
98
+
99
+ ## 0.1.0-alpha.21
100
+
101
+ ### Minor Changes
102
+
103
+ - 5916f9d: Update deps from fixed to ^
104
+
105
+ ### Patch Changes
106
+
107
+ - 7f24c29: Add Chroma Filter translator and updated vector store tests
108
+ - Updated dependencies [6fa4bd2]
109
+ - Updated dependencies [e2e76de]
110
+ - Updated dependencies [7f24c29]
111
+ - Updated dependencies [67637ba]
112
+ - Updated dependencies [04f3171]
113
+ - @mastra/core@0.2.0-alpha.86
114
+
115
+ ## 0.0.1-alpha.20
116
+
117
+ ### Patch Changes
118
+
119
+ - Updated dependencies [e9d1b47]
120
+ - @mastra/core@0.2.0-alpha.85
121
+
122
+ ## 0.0.1-alpha.19
123
+
124
+ ### Patch Changes
125
+
126
+ - Updated dependencies [2f17a5f]
127
+ - Updated dependencies [cb290ee]
128
+ - Updated dependencies [b4d7416]
129
+ - Updated dependencies [38b7f66]
130
+ - @mastra/core@0.2.0-alpha.84
131
+
132
+ ## 0.0.1-alpha.18
133
+
134
+ ### Patch Changes
135
+
136
+ - cf4c02c: Added testing for Pinecone Unified Filter API
137
+
138
+ ## 0.0.1-alpha.17
139
+
140
+ ### Patch Changes
141
+
142
+ - 78eec7c: Started implementation on Unified Filter API for several vector stores.
143
+ - 9625602: Use mastra core splitted bundles in other packages
144
+ - Updated dependencies [30322ce]
145
+ - Updated dependencies [78eec7c]
146
+ - Updated dependencies [9625602]
147
+ - Updated dependencies [8769a62]
148
+ - @mastra/core@0.2.0-alpha.83
149
+
150
+ ## 0.0.1-alpha.16
151
+
152
+ ### Patch Changes
153
+
154
+ - Updated dependencies [73d112c]
155
+ - @mastra/core@0.1.27-alpha.82
156
+
157
+ ## 0.0.1-alpha.15
158
+
159
+ ### Patch Changes
160
+
161
+ - Updated dependencies [9fb3039]
162
+ - @mastra/core@0.1.27-alpha.81
163
+
164
+ ## 0.0.1-alpha.14
165
+
166
+ ### Patch Changes
167
+
168
+ - b422ed3: Bundle vector provider packages with tsup
169
+
170
+ ## 0.0.1-alpha.13
171
+
172
+ ### Patch Changes
173
+
174
+ - Updated dependencies [327ece7]
175
+ - @mastra/core@0.1.27-alpha.80
176
+
177
+ ## 0.0.1-alpha.12
178
+
179
+ ### Patch Changes
180
+
181
+ - Updated dependencies [21fe536]
182
+ - @mastra/core@0.1.27-alpha.79
183
+
184
+ ## 0.0.1-alpha.11
185
+
186
+ ### Patch Changes
187
+
188
+ - Updated dependencies [685108a]
189
+ - Updated dependencies [685108a]
190
+ - @mastra/core@0.1.27-alpha.78
191
+
192
+ ## 0.0.1-alpha.10
193
+
194
+ ### Patch Changes
195
+
196
+ - Updated dependencies [8105fae]
197
+ - @mastra/core@0.1.27-alpha.77
198
+
199
+ ## 0.0.1-alpha.9
200
+
201
+ ### Patch Changes
202
+
203
+ - 7a469e7: Bump vectors
204
+
205
+ ## 0.0.1-alpha.8
206
+
207
+ ### Patch Changes
208
+
209
+ - Updated dependencies [ae7bf94]
210
+ - Updated dependencies [ae7bf94]
211
+ - @mastra/core@0.1.27-alpha.76
212
+
213
+ ## 0.0.1-alpha.7
214
+
215
+ ### Patch Changes
216
+
217
+ - Updated dependencies [23dcb23]
218
+ - @mastra/core@0.1.27-alpha.75
219
+
220
+ ## 0.0.1-alpha.6
221
+
222
+ ### Patch Changes
223
+
224
+ - Updated dependencies [7b87567]
225
+ - @mastra/core@0.1.27-alpha.74
226
+
227
+ ## 0.0.1-alpha.5
228
+
229
+ ### Patch Changes
230
+
231
+ - Updated dependencies [3427b95]
232
+ - @mastra/core@0.1.27-alpha.73
233
+
234
+ ## 0.0.1-alpha.4
235
+
236
+ ### Patch Changes
237
+
238
+ - Updated dependencies [e4d4ede]
239
+ - Updated dependencies [06b2c0a]
240
+ - @mastra/core@0.1.27-alpha.72
241
+
242
+ ## 0.0.1-alpha.3
243
+
244
+ ### Patch Changes
245
+
246
+ - Updated dependencies [d9c8dd0]
247
+ - @mastra/core@0.1.27-alpha.71
248
+
249
+ ## 0.0.1-alpha.2
250
+
251
+ ### Patch Changes
252
+
253
+ - bdaf834: publish packages
254
+
255
+ ## 0.0.1-alpha.1
256
+
257
+ ### Patch Changes
258
+
259
+ - Updated dependencies [dd6d87f]
260
+ - Updated dependencies [04434b6]
261
+ - @mastra/core@0.1.27-alpha.70
262
+
263
+ ## 0.0.1-alpha.0
264
+
265
+ ### Patch Changes
266
+
267
+ - 0d5a03d: Vector store modules
package/LICENSE ADDED
@@ -0,0 +1,44 @@
1
+ Elastic License 2.0 (ELv2)
2
+
3
+ **Acceptance**
4
+ By using the software, you agree to all of the terms and conditions below.
5
+
6
+ **Copyright License**
7
+ The licensor grants you a non-exclusive, royalty-free, worldwide, non-sublicensable, non-transferable license to use, copy, distribute, make available, and prepare derivative works of the software, in each case subject to the limitations and conditions below
8
+
9
+ **Limitations**
10
+ You may not provide the software to third parties as a hosted or managed service, where the service provides users with access to any substantial set of the features or functionality of the software.
11
+
12
+ You may not move, change, disable, or circumvent the license key functionality in the software, and you may not remove or obscure any functionality in the software that is protected by the license key.
13
+
14
+ You may not alter, remove, or obscure any licensing, copyright, or other notices of the licensor in the software. Any use of the licensor’s trademarks is subject to applicable law.
15
+
16
+ **Patents**
17
+ The licensor grants you a license, under any patent claims the licensor can license, or becomes able to license, to make, have made, use, sell, offer for sale, import and have imported the software, in each case subject to the limitations and conditions in this license. This license does not cover any patent claims that you cause to be infringed by modifications or additions to the software. If you or your company make any written claim that the software infringes or contributes to infringement of any patent, your patent license for the software granted under these terms ends immediately. If your company makes such a claim, your patent license ends immediately for work on behalf of your company.
18
+
19
+ **Notices**
20
+ You must ensure that anyone who gets a copy of any part of the software from you also gets a copy of these terms.
21
+
22
+ If you modify the software, you must include in any modified copies of the software prominent notices stating that you have modified the software.
23
+
24
+ **No Other Rights**
25
+ These terms do not imply any licenses other than those expressly granted in these terms.
26
+
27
+ **Termination**
28
+ If you use the software in violation of these terms, such use is not licensed, and your licenses will automatically terminate. If the licensor provides you with a notice of your violation, and you cease all violation of this license no later than 30 days after you receive that notice, your licenses will be reinstated retroactively. However, if you violate these terms after such reinstatement, any additional violation of these terms will cause your licenses to terminate automatically and permanently.
29
+
30
+ **No Liability**
31
+ As far as the law allows, the software comes as is, without any warranty or condition, and the licensor will not be liable to you for any damages arising out of these terms or the use or nature of the software, under any kind of legal claim.
32
+
33
+ **Definitions**
34
+ The _licensor_ is the entity offering these terms, and the _software_ is the software the licensor makes available under these terms, including any portion of it.
35
+
36
+ _you_ refers to the individual or entity agreeing to these terms.
37
+
38
+ _your company_ is any legal entity, sole proprietorship, or other kind of organization that you work for, plus all organizations that have control over, are under the control of, or are under common control with that organization. _control_ means ownership of substantially all the assets of an entity, or the power to direct its management and policies by vote, contract, or otherwise. Control can be direct or indirect.
39
+
40
+ _your licenses_ are all the licenses granted to you for the software under these terms.
41
+
42
+ _use_ means anything you do with the software requiring one of your licenses.
43
+
44
+ _trademark_ means trademarks, service marks, and similar rights.
package/README.md ADDED
@@ -0,0 +1,72 @@
1
+ # @mastra/pinecone
2
+
3
+ Vector store implementation for Pinecone, using the official @pinecone-database/pinecone SDK with added telemetry support.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ pnpm add @mastra/pinecone
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ ```typescript
14
+ import { PineconeVector } from '@mastra/pinecone';
15
+
16
+ const vectorStore = new PineconeVector(
17
+ 'your-api-key',
18
+ 'optional-environment-url'
19
+ );
20
+
21
+ // Create a new index
22
+ await vectorStore.createIndex('my-index', 1536, 'cosine');
23
+
24
+ // Add vectors
25
+ const vectors = [[0.1, 0.2, ...], [0.3, 0.4, ...]];
26
+ const metadata = [{ text: 'doc1' }, { text: 'doc2' }];
27
+ const ids = await vectorStore.upsert('my-index', vectors, metadata);
28
+
29
+ // Query vectors
30
+ const results = await vectorStore.query(
31
+ 'my-index',
32
+ [0.1, 0.2, ...],
33
+ 10, // topK
34
+ { text: { $eq: 'doc1' } }, // optional filter
35
+ false // includeValues
36
+ );
37
+ ```
38
+
39
+ ## Configuration
40
+
41
+ Required:
42
+
43
+ - `apiKey`: Your Pinecone API key
44
+
45
+ Optional:
46
+
47
+ - `environment`: Your Pinecone environment URL (controller host URL)
48
+
49
+ ## Features
50
+
51
+ - Serverless deployment on AWS (us-east-1)
52
+ - Vector similarity search with cosine, euclidean, and dot product metrics
53
+ - Automatic batching for large upserts (100 vectors per request)
54
+ - Built-in telemetry support
55
+ - Metadata filtering
56
+ - Optional vector inclusion in query results
57
+ - Automatic UUID generation for vectors
58
+ - Built on top of @pinecone-database/pinecone SDK
59
+
60
+ ## Methods
61
+
62
+ - `createIndex(indexName, dimension, metric?)`: Create a new index
63
+ - `upsert(indexName, vectors, metadata?, ids?)`: Add or update vectors
64
+ - `query(indexName, queryVector, topK?, filter?, includeVector?)`: Search for similar vectors
65
+ - `listIndexes()`: List all indexes
66
+ - `describeIndex(indexName)`: Get index statistics
67
+ - `deleteIndex(indexName)`: Delete an index
68
+
69
+ ## Related Links
70
+
71
+ - [Pinecone Documentation](https://docs.pinecone.io/)
72
+ - [Pinecone Node.js SDK](https://github.com/pinecone-io/pinecone-ts-client)
@@ -0,0 +1,16 @@
1
+ import { Filter } from '@mastra/core/filter';
2
+ import { MastraVector, QueryResult, IndexStats } from '@mastra/core/vector';
3
+
4
+ declare class PineconeVector extends MastraVector {
5
+ private client;
6
+ constructor(apiKey: string, environment?: string);
7
+ createIndex(indexName: string, dimension: number, metric?: 'cosine' | 'euclidean' | 'dotproduct'): Promise<void>;
8
+ upsert(indexName: string, vectors: number[][], metadata?: Record<string, any>[], ids?: string[]): Promise<string[]>;
9
+ transformFilter(filter?: Filter): Filter | undefined;
10
+ query(indexName: string, queryVector: number[], topK?: number, filter?: Filter, includeVector?: boolean): Promise<QueryResult[]>;
11
+ listIndexes(): Promise<string[]>;
12
+ describeIndex(indexName: string): Promise<IndexStats>;
13
+ deleteIndex(indexName: string): Promise<void>;
14
+ }
15
+
16
+ export { PineconeVector };
package/dist/index.js ADDED
@@ -0,0 +1,176 @@
1
+ import { MastraVector } from '@mastra/core/vector';
2
+ import { Pinecone } from '@pinecone-database/pinecone';
3
+ import { BaseFilterTranslator } from '@mastra/core/filter';
4
+
5
+ // src/vector/index.ts
6
+ var PineconeFilterTranslator = class extends BaseFilterTranslator {
7
+ getSupportedOperators() {
8
+ return {
9
+ ...BaseFilterTranslator.DEFAULT_OPERATORS,
10
+ logical: ["$and", "$or"],
11
+ array: ["$in", "$all", "$nin"],
12
+ element: ["$exists"],
13
+ regex: [],
14
+ custom: []
15
+ };
16
+ }
17
+ translate(filter) {
18
+ if (this.isEmpty(filter)) return filter;
19
+ this.validateFilter(filter);
20
+ return this.translateNode(filter);
21
+ }
22
+ translateNode(node, currentPath = "") {
23
+ if (this.isRegex(node)) {
24
+ throw new Error("Regex is not supported in Pinecone");
25
+ }
26
+ if (this.isPrimitive(node)) return this.normalizeComparisonValue(node);
27
+ if (Array.isArray(node)) return { $in: this.normalizeArrayValues(node) };
28
+ const entries = Object.entries(node);
29
+ const firstEntry = entries[0];
30
+ if (entries.length === 1 && firstEntry && this.isOperator(firstEntry[0])) {
31
+ const [operator, value] = firstEntry;
32
+ const translated = this.translateOperator(operator, value, currentPath);
33
+ return this.isLogicalOperator(operator) ? { [operator]: translated } : translated;
34
+ }
35
+ const result = {};
36
+ for (const [key, value] of entries) {
37
+ const newPath = currentPath ? `${currentPath}.${key}` : key;
38
+ if (this.isOperator(key)) {
39
+ result[key] = this.translateOperator(key, value, currentPath);
40
+ continue;
41
+ }
42
+ if (typeof value === "object" && value !== null && !Array.isArray(value)) {
43
+ if (Object.keys(value).length === 1 && "$all" in value) {
44
+ const translated = this.translateNode(value, key);
45
+ if (translated.$and) {
46
+ return translated;
47
+ }
48
+ }
49
+ if (Object.keys(value).length === 0) {
50
+ result[newPath] = this.translateNode(value);
51
+ } else {
52
+ const hasOperators = Object.keys(value).some((k) => this.isOperator(k));
53
+ if (hasOperators) {
54
+ const normalizedValue = {};
55
+ for (const [op, opValue] of Object.entries(value)) {
56
+ normalizedValue[op] = this.isOperator(op) ? this.translateOperator(op, opValue) : opValue;
57
+ }
58
+ result[newPath] = normalizedValue;
59
+ } else {
60
+ Object.assign(result, this.translateNode(value, newPath));
61
+ }
62
+ }
63
+ } else {
64
+ result[newPath] = this.translateNode(value);
65
+ }
66
+ }
67
+ return result;
68
+ }
69
+ translateOperator(operator, value, currentPath = "") {
70
+ if (operator === "$all") {
71
+ if (!Array.isArray(value) || value.length === 0) {
72
+ throw new Error("A non-empty array is required for the $all operator");
73
+ }
74
+ return this.simulateAllOperator(currentPath, value);
75
+ }
76
+ if (this.isLogicalOperator(operator)) {
77
+ return Array.isArray(value) ? value.map((item) => this.translateNode(item)) : this.translateNode(value);
78
+ }
79
+ return this.normalizeComparisonValue(value);
80
+ }
81
+ };
82
+
83
+ // src/vector/index.ts
84
+ var PineconeVector = class extends MastraVector {
85
+ constructor(apiKey, environment) {
86
+ super();
87
+ const opts = { apiKey };
88
+ if (environment) {
89
+ opts["controllerHostUrl"] = environment;
90
+ }
91
+ const baseClient = new Pinecone(opts);
92
+ const telemetry = this.__getTelemetry();
93
+ this.client = telemetry?.traceClass(baseClient, {
94
+ spanNamePrefix: "pinecone-vector",
95
+ attributes: {
96
+ "vector.type": "pinecone"
97
+ }
98
+ }) ?? baseClient;
99
+ }
100
+ async createIndex(indexName, dimension, metric = "cosine") {
101
+ if (!Number.isInteger(dimension) || dimension <= 0) {
102
+ throw new Error("Dimension must be a positive integer");
103
+ }
104
+ await this.client.createIndex({
105
+ name: indexName,
106
+ dimension,
107
+ metric,
108
+ spec: {
109
+ serverless: {
110
+ cloud: "aws",
111
+ region: "us-east-1"
112
+ }
113
+ }
114
+ });
115
+ }
116
+ async upsert(indexName, vectors, metadata, ids) {
117
+ const index = this.client.Index(indexName);
118
+ const vectorIds = ids || vectors.map(() => crypto.randomUUID());
119
+ const records = vectors.map((vector, i) => ({
120
+ id: vectorIds[i],
121
+ values: vector,
122
+ metadata: metadata?.[i] || {}
123
+ }));
124
+ const batchSize = 100;
125
+ for (let i = 0; i < records.length; i += batchSize) {
126
+ const batch = records.slice(i, i + batchSize);
127
+ await index.upsert(batch);
128
+ }
129
+ return vectorIds;
130
+ }
131
+ transformFilter(filter) {
132
+ const pineconeFilter = new PineconeFilterTranslator();
133
+ const translatedFilter = pineconeFilter.translate(filter);
134
+ return translatedFilter;
135
+ }
136
+ async query(indexName, queryVector, topK = 10, filter, includeVector = false) {
137
+ const index = this.client.Index(indexName);
138
+ const translatedFilter = this.transformFilter(filter);
139
+ const results = await index.query({
140
+ vector: queryVector,
141
+ topK,
142
+ filter: translatedFilter,
143
+ includeMetadata: true,
144
+ includeValues: includeVector
145
+ });
146
+ return results.matches.map((match) => ({
147
+ id: match.id,
148
+ score: match.score || 0,
149
+ metadata: match.metadata,
150
+ ...includeVector && { vector: match.values || [] }
151
+ }));
152
+ }
153
+ async listIndexes() {
154
+ const indexesResult = await this.client.listIndexes();
155
+ return indexesResult?.indexes?.map((index) => index.name) || [];
156
+ }
157
+ async describeIndex(indexName) {
158
+ const index = this.client.Index(indexName);
159
+ const stats = await index.describeIndexStats();
160
+ const description = await this.client.describeIndex(indexName);
161
+ return {
162
+ dimension: description.dimension,
163
+ count: stats.totalRecordCount || 0,
164
+ metric: description.metric
165
+ };
166
+ }
167
+ async deleteIndex(indexName) {
168
+ try {
169
+ await this.client.deleteIndex(indexName);
170
+ } catch (error) {
171
+ throw new Error(`Failed to delete Pinecone index: ${error.message}`);
172
+ }
173
+ }
174
+ };
175
+
176
+ export { PineconeVector };
package/package.json ADDED
@@ -0,0 +1,32 @@
1
+ {
2
+ "name": "@mastra/pinecone",
3
+ "version": "0.1.0-alpha.29",
4
+ "description": "Pinecone vector store provider for Mastra",
5
+ "type": "module",
6
+ "main": "dist/index.js",
7
+ "types": "dist/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "import": {
11
+ "types": "./dist/index.d.ts",
12
+ "default": "./dist/index.js"
13
+ }
14
+ },
15
+ "./package.json": "./package.json"
16
+ },
17
+ "dependencies": {
18
+ "@pinecone-database/pinecone": "^3.0.3",
19
+ "@mastra/core": "^0.2.0-alpha.93"
20
+ },
21
+ "devDependencies": {
22
+ "@tsconfig/recommended": "^1.0.7",
23
+ "@types/node": "^22.9.0",
24
+ "tsup": "^8.0.1",
25
+ "vitest": "^3.0.4"
26
+ },
27
+ "scripts": {
28
+ "build": "tsup-node src/index.ts --format esm --dts --clean --treeshake",
29
+ "dev": "tsup-node src/index.ts --format esm --dts --clean --treeshake --watch",
30
+ "test": "vitest run"
31
+ }
32
+ }
package/src/index.ts ADDED
@@ -0,0 +1 @@
1
+ export * from './vector/index';