@mastra/pinecone 0.0.0-error-handler-fix-20251020202607 → 0.0.0-execa-dynamic-import-20260304221256
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 +286 -3
- package/LICENSE.md +15 -0
- package/README.md +14 -8
- package/dist/docs/SKILL.md +29 -0
- package/dist/docs/assets/SOURCE_MAP.json +6 -0
- package/dist/docs/references/docs-memory-memory-processors.md +314 -0
- package/dist/docs/references/docs-memory-storage.md +261 -0
- package/dist/docs/references/docs-rag-retrieval.md +515 -0
- package/dist/docs/references/docs-rag-vector-databases.md +645 -0
- package/dist/docs/references/reference-vectors-pinecone.md +168 -0
- package/dist/index.cjs +199 -45
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +199 -45
- package/dist/index.js.map +1 -1
- package/dist/vector/index.d.ts +85 -17
- package/dist/vector/index.d.ts.map +1 -1
- package/package.json +17 -12
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
# Pinecone Vector Store
|
|
2
|
+
|
|
3
|
+
The PineconeVector class provides an interface to [Pinecone](https://www.pinecone.io/)'s vector database. It provides real-time vector search, with features like hybrid search, metadata filtering, and namespace management.
|
|
4
|
+
|
|
5
|
+
## Constructor Options
|
|
6
|
+
|
|
7
|
+
The constructor accepts all [Pinecone configuration options](https://docs.pinecone.io/reference/typescript-sdk) plus Mastra-specific fields.
|
|
8
|
+
|
|
9
|
+
**id:** (`string`): Unique identifier for this vector store instance
|
|
10
|
+
|
|
11
|
+
**apiKey:** (`string`): Pinecone API key
|
|
12
|
+
|
|
13
|
+
**controllerHostUrl?:** (`string`): Custom Pinecone controller host URL
|
|
14
|
+
|
|
15
|
+
**additionalHeaders?:** (`Record<string, string>`): Additional HTTP headers to include in requests
|
|
16
|
+
|
|
17
|
+
**sourceTag?:** (`string`): Source tag for request tracking
|
|
18
|
+
|
|
19
|
+
**cloud?:** (`'aws' | 'gcp' | 'azure'`): Cloud provider for new index creation (Default: `aws`)
|
|
20
|
+
|
|
21
|
+
**region?:** (`string`): Region for new index creation (Default: `us-east-1`)
|
|
22
|
+
|
|
23
|
+
## Methods
|
|
24
|
+
|
|
25
|
+
### createIndex()
|
|
26
|
+
|
|
27
|
+
**indexName:** (`string`): Name of the index to create
|
|
28
|
+
|
|
29
|
+
**dimension:** (`number`): Vector dimension (must match your embedding model)
|
|
30
|
+
|
|
31
|
+
**metric?:** (`'cosine' | 'euclidean' | 'dotproduct'`): Distance metric for similarity search. Use 'dotproduct' if you plan to use hybrid search. (Default: `cosine`)
|
|
32
|
+
|
|
33
|
+
### upsert()
|
|
34
|
+
|
|
35
|
+
**indexName:** (`string`): Name of your Pinecone index
|
|
36
|
+
|
|
37
|
+
**vectors:** (`number[][]`): Array of dense embedding vectors
|
|
38
|
+
|
|
39
|
+
**sparseVectors?:** (`{ indices: number[], values: number[] }[]`): Array of sparse vectors for hybrid search. Each vector must have matching indices and values arrays.
|
|
40
|
+
|
|
41
|
+
**metadata?:** (`Record<string, any>[]`): Metadata for each vector
|
|
42
|
+
|
|
43
|
+
**ids?:** (`string[]`): Optional vector IDs (auto-generated if not provided)
|
|
44
|
+
|
|
45
|
+
**namespace?:** (`string`): Optional namespace to store vectors in. Vectors in different namespaces are isolated from each other.
|
|
46
|
+
|
|
47
|
+
### query()
|
|
48
|
+
|
|
49
|
+
**indexName:** (`string`): Name of the index to query
|
|
50
|
+
|
|
51
|
+
**queryVector:** (`number[]`): Dense query vector to find similar vectors
|
|
52
|
+
|
|
53
|
+
**sparseVector?:** (`{ indices: number[], values: number[] }`): Optional sparse vector for hybrid search. Must have matching indices and values arrays.
|
|
54
|
+
|
|
55
|
+
**topK?:** (`number`): Number of results to return (Default: `10`)
|
|
56
|
+
|
|
57
|
+
**filter?:** (`Record<string, any>`): Metadata filters for the query
|
|
58
|
+
|
|
59
|
+
**includeVector?:** (`boolean`): Whether to include the vector in the result (Default: `false`)
|
|
60
|
+
|
|
61
|
+
**namespace?:** (`string`): Optional namespace to query vectors from. Only returns results from the specified namespace.
|
|
62
|
+
|
|
63
|
+
### listIndexes()
|
|
64
|
+
|
|
65
|
+
Returns an array of index names as strings.
|
|
66
|
+
|
|
67
|
+
### describeIndex()
|
|
68
|
+
|
|
69
|
+
**indexName:** (`string`): Name of the index to describe
|
|
70
|
+
|
|
71
|
+
Returns:
|
|
72
|
+
|
|
73
|
+
```typescript
|
|
74
|
+
interface IndexStats {
|
|
75
|
+
dimension: number
|
|
76
|
+
count: number
|
|
77
|
+
metric: 'cosine' | 'euclidean' | 'dotproduct'
|
|
78
|
+
}
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
### deleteIndex()
|
|
82
|
+
|
|
83
|
+
**indexName:** (`string`): Name of the index to delete
|
|
84
|
+
|
|
85
|
+
### updateVector()
|
|
86
|
+
|
|
87
|
+
Update a single vector by ID or by metadata filter. Either `id` or `filter` must be provided, but not both.
|
|
88
|
+
|
|
89
|
+
**indexName:** (`string`): Name of the index containing the vector
|
|
90
|
+
|
|
91
|
+
**id?:** (`string`): ID of the vector to update (mutually exclusive with filter)
|
|
92
|
+
|
|
93
|
+
**filter?:** (`Record<string, any>`): Metadata filter to identify vector(s) to update (mutually exclusive with id)
|
|
94
|
+
|
|
95
|
+
**namespace?:** (`string`): Optional namespace for the update operation
|
|
96
|
+
|
|
97
|
+
**update:** (`object`): Update parameters
|
|
98
|
+
|
|
99
|
+
**update.vector?:** (`number[]`): New vector values to update
|
|
100
|
+
|
|
101
|
+
**update.metadata?:** (`Record<string, any>`): New metadata to update
|
|
102
|
+
|
|
103
|
+
### deleteVector()
|
|
104
|
+
|
|
105
|
+
**indexName:** (`string`): Name of the index containing the vector
|
|
106
|
+
|
|
107
|
+
**id:** (`string`): ID of the vector to delete
|
|
108
|
+
|
|
109
|
+
### deleteVectors()
|
|
110
|
+
|
|
111
|
+
Delete multiple vectors by IDs or by metadata filter. Either `ids` or `filter` must be provided, but not both.
|
|
112
|
+
|
|
113
|
+
**indexName:** (`string`): Name of the index containing the vectors to delete
|
|
114
|
+
|
|
115
|
+
**ids?:** (`string[]`): Array of vector IDs to delete (mutually exclusive with filter)
|
|
116
|
+
|
|
117
|
+
**filter?:** (`Record<string, any>`): Metadata filter to identify vectors to delete (mutually exclusive with ids)
|
|
118
|
+
|
|
119
|
+
**namespace?:** (`string`): Optional namespace for the deletion operation
|
|
120
|
+
|
|
121
|
+
## Response Types
|
|
122
|
+
|
|
123
|
+
Query results are returned in this format:
|
|
124
|
+
|
|
125
|
+
```typescript
|
|
126
|
+
interface QueryResult {
|
|
127
|
+
id: string
|
|
128
|
+
score: number
|
|
129
|
+
metadata: Record<string, any>
|
|
130
|
+
vector?: number[] // Only included if includeVector is true
|
|
131
|
+
}
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
## Error Handling
|
|
135
|
+
|
|
136
|
+
The store throws typed errors that can be caught:
|
|
137
|
+
|
|
138
|
+
```typescript
|
|
139
|
+
try {
|
|
140
|
+
await store.query({
|
|
141
|
+
indexName: 'index_name',
|
|
142
|
+
queryVector: queryVector,
|
|
143
|
+
})
|
|
144
|
+
} catch (error) {
|
|
145
|
+
if (error instanceof VectorStoreError) {
|
|
146
|
+
console.log(error.code) // 'connection_failed' | 'invalid_dimension' | etc
|
|
147
|
+
console.log(error.details) // Additional error context
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
### Environment Variables
|
|
153
|
+
|
|
154
|
+
Required environment variables:
|
|
155
|
+
|
|
156
|
+
- `PINECONE_API_KEY`: Your Pinecone API key
|
|
157
|
+
|
|
158
|
+
## Hybrid Search
|
|
159
|
+
|
|
160
|
+
Pinecone supports hybrid search by combining dense and sparse vectors. To use hybrid search:
|
|
161
|
+
|
|
162
|
+
1. Create an index with `metric: 'dotproduct'`
|
|
163
|
+
2. During upsert, provide sparse vectors using the `sparseVectors` parameter
|
|
164
|
+
3. During query, provide a sparse vector using the `sparseVector` parameter
|
|
165
|
+
|
|
166
|
+
## Related
|
|
167
|
+
|
|
168
|
+
- [Metadata Filters](https://mastra.ai/reference/rag/metadata-filters)
|
package/dist/index.cjs
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var error = require('@mastra/core/error');
|
|
4
|
+
var storage = require('@mastra/core/storage');
|
|
4
5
|
var vector = require('@mastra/core/vector');
|
|
5
6
|
var pinecone = require('@pinecone-database/pinecone');
|
|
6
7
|
var filter = require('@mastra/core/vector/filter');
|
|
@@ -86,25 +87,19 @@ var PineconeFilterTranslator = class extends filter.BaseFilterTranslator {
|
|
|
86
87
|
// src/vector/index.ts
|
|
87
88
|
var PineconeVector = class extends vector.MastraVector {
|
|
88
89
|
client;
|
|
90
|
+
cloud;
|
|
91
|
+
region;
|
|
89
92
|
/**
|
|
90
93
|
* Creates a new PineconeVector client.
|
|
91
|
-
*
|
|
92
|
-
* @param
|
|
94
|
+
*
|
|
95
|
+
* @param config - Configuration options for the Pinecone client.
|
|
96
|
+
* @see {@link PineconeVectorConfig} for all available options.
|
|
93
97
|
*/
|
|
94
|
-
constructor({
|
|
95
|
-
super();
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
}
|
|
100
|
-
const baseClient = new pinecone.Pinecone(opts);
|
|
101
|
-
const telemetry = this.__getTelemetry();
|
|
102
|
-
this.client = telemetry?.traceClass(baseClient, {
|
|
103
|
-
spanNamePrefix: "pinecone-vector",
|
|
104
|
-
attributes: {
|
|
105
|
-
"vector.type": "pinecone"
|
|
106
|
-
}
|
|
107
|
-
}) ?? baseClient;
|
|
98
|
+
constructor({ id, cloud, region, ...pineconeConfig }) {
|
|
99
|
+
super({ id });
|
|
100
|
+
this.client = new pinecone.Pinecone(pineconeConfig);
|
|
101
|
+
this.cloud = cloud || "aws";
|
|
102
|
+
this.region = region || "us-east-1";
|
|
108
103
|
}
|
|
109
104
|
get indexSeparator() {
|
|
110
105
|
return "-";
|
|
@@ -120,7 +115,7 @@ var PineconeVector = class extends vector.MastraVector {
|
|
|
120
115
|
} catch (validationError) {
|
|
121
116
|
throw new error.MastraError(
|
|
122
117
|
{
|
|
123
|
-
id: "
|
|
118
|
+
id: storage.createVectorErrorId("PINECONE", "CREATE_INDEX", "INVALID_ARGS"),
|
|
124
119
|
domain: error.ErrorDomain.STORAGE,
|
|
125
120
|
category: error.ErrorCategory.USER,
|
|
126
121
|
details: { indexName, dimension, metric }
|
|
@@ -135,8 +130,8 @@ var PineconeVector = class extends vector.MastraVector {
|
|
|
135
130
|
metric,
|
|
136
131
|
spec: {
|
|
137
132
|
serverless: {
|
|
138
|
-
cloud:
|
|
139
|
-
region:
|
|
133
|
+
cloud: this.cloud,
|
|
134
|
+
region: this.region
|
|
140
135
|
}
|
|
141
136
|
}
|
|
142
137
|
});
|
|
@@ -148,7 +143,7 @@ var PineconeVector = class extends vector.MastraVector {
|
|
|
148
143
|
}
|
|
149
144
|
throw new error.MastraError(
|
|
150
145
|
{
|
|
151
|
-
id: "
|
|
146
|
+
id: storage.createVectorErrorId("PINECONE", "CREATE_INDEX", "FAILED"),
|
|
152
147
|
domain: error.ErrorDomain.STORAGE,
|
|
153
148
|
category: error.ErrorCategory.THIRD_PARTY,
|
|
154
149
|
details: { indexName, dimension, metric }
|
|
@@ -183,7 +178,7 @@ var PineconeVector = class extends vector.MastraVector {
|
|
|
183
178
|
} catch (error$1) {
|
|
184
179
|
throw new error.MastraError(
|
|
185
180
|
{
|
|
186
|
-
id: "
|
|
181
|
+
id: storage.createVectorErrorId("PINECONE", "UPSERT", "FAILED"),
|
|
187
182
|
domain: error.ErrorDomain.STORAGE,
|
|
188
183
|
category: error.ErrorCategory.THIRD_PARTY,
|
|
189
184
|
details: { indexName, vectorCount: vectors.length }
|
|
@@ -205,6 +200,15 @@ var PineconeVector = class extends vector.MastraVector {
|
|
|
205
200
|
namespace,
|
|
206
201
|
sparseVector
|
|
207
202
|
}) {
|
|
203
|
+
if (!queryVector) {
|
|
204
|
+
throw new error.MastraError({
|
|
205
|
+
id: storage.createVectorErrorId("PINECONE", "QUERY", "MISSING_VECTOR"),
|
|
206
|
+
text: "queryVector is required for Pinecone queries. Metadata-only queries are not supported by this vector store.",
|
|
207
|
+
domain: error.ErrorDomain.STORAGE,
|
|
208
|
+
category: error.ErrorCategory.USER,
|
|
209
|
+
details: { indexName }
|
|
210
|
+
});
|
|
211
|
+
}
|
|
208
212
|
const index = this.client.Index(indexName).namespace(namespace || "");
|
|
209
213
|
const translatedFilter = this.transformFilter(filter) ?? void 0;
|
|
210
214
|
const queryParams = {
|
|
@@ -228,7 +232,7 @@ var PineconeVector = class extends vector.MastraVector {
|
|
|
228
232
|
} catch (error$1) {
|
|
229
233
|
throw new error.MastraError(
|
|
230
234
|
{
|
|
231
|
-
id: "
|
|
235
|
+
id: storage.createVectorErrorId("PINECONE", "QUERY", "FAILED"),
|
|
232
236
|
domain: error.ErrorDomain.STORAGE,
|
|
233
237
|
category: error.ErrorCategory.THIRD_PARTY,
|
|
234
238
|
details: { indexName, topK }
|
|
@@ -244,7 +248,7 @@ var PineconeVector = class extends vector.MastraVector {
|
|
|
244
248
|
} catch (error$1) {
|
|
245
249
|
throw new error.MastraError(
|
|
246
250
|
{
|
|
247
|
-
id: "
|
|
251
|
+
id: storage.createVectorErrorId("PINECONE", "LIST_INDEXES", "FAILED"),
|
|
248
252
|
domain: error.ErrorDomain.STORAGE,
|
|
249
253
|
category: error.ErrorCategory.THIRD_PARTY
|
|
250
254
|
},
|
|
@@ -272,7 +276,7 @@ var PineconeVector = class extends vector.MastraVector {
|
|
|
272
276
|
} catch (error$1) {
|
|
273
277
|
throw new error.MastraError(
|
|
274
278
|
{
|
|
275
|
-
id: "
|
|
279
|
+
id: storage.createVectorErrorId("PINECONE", "DESCRIBE_INDEX", "FAILED"),
|
|
276
280
|
domain: error.ErrorDomain.STORAGE,
|
|
277
281
|
category: error.ErrorCategory.THIRD_PARTY,
|
|
278
282
|
details: { indexName }
|
|
@@ -287,7 +291,7 @@ var PineconeVector = class extends vector.MastraVector {
|
|
|
287
291
|
} catch (error$1) {
|
|
288
292
|
throw new error.MastraError(
|
|
289
293
|
{
|
|
290
|
-
id: "
|
|
294
|
+
id: storage.createVectorErrorId("PINECONE", "DELETE_INDEX", "FAILED"),
|
|
291
295
|
domain: error.ErrorDomain.STORAGE,
|
|
292
296
|
category: error.ErrorCategory.THIRD_PARTY,
|
|
293
297
|
details: { indexName }
|
|
@@ -298,42 +302,102 @@ var PineconeVector = class extends vector.MastraVector {
|
|
|
298
302
|
}
|
|
299
303
|
/**
|
|
300
304
|
* Updates a vector by its ID with the provided vector and/or metadata.
|
|
301
|
-
*
|
|
302
|
-
* @param
|
|
303
|
-
* @param
|
|
304
|
-
* @param
|
|
305
|
-
* @param update
|
|
306
|
-
* @param namespace - The namespace of the index (optional).
|
|
305
|
+
* Note: Pinecone only supports update by ID, not by filter.
|
|
306
|
+
* @param params - Parameters containing the id for targeting the vector to update
|
|
307
|
+
* @param params.indexName - The name of the index containing the vector.
|
|
308
|
+
* @param params.id - The ID of the vector to update.
|
|
309
|
+
* @param params.update - An object containing the vector and/or metadata to update.
|
|
310
|
+
* @param namespace - The namespace of the index (optional, Pinecone-specific).
|
|
307
311
|
* @returns A promise that resolves when the update is complete.
|
|
308
312
|
* @throws Will throw an error if no updates are provided or if the update operation fails.
|
|
309
313
|
*/
|
|
310
|
-
async updateVector(
|
|
314
|
+
async updateVector(params) {
|
|
315
|
+
const { indexName, update } = params;
|
|
316
|
+
if ("id" in params && params.id && "filter" in params && params.filter) {
|
|
317
|
+
throw new error.MastraError({
|
|
318
|
+
id: storage.createVectorErrorId("PINECONE", "UPDATE_VECTOR", "MUTUALLY_EXCLUSIVE"),
|
|
319
|
+
text: "Cannot specify both id and filter - they are mutually exclusive",
|
|
320
|
+
domain: error.ErrorDomain.STORAGE,
|
|
321
|
+
category: error.ErrorCategory.USER,
|
|
322
|
+
details: { indexName }
|
|
323
|
+
});
|
|
324
|
+
}
|
|
325
|
+
if (!("id" in params && params.id) && !("filter" in params && params.filter)) {
|
|
326
|
+
throw new error.MastraError({
|
|
327
|
+
id: storage.createVectorErrorId("PINECONE", "UPDATE_VECTOR", "NO_TARGET"),
|
|
328
|
+
text: "Either id or filter must be provided",
|
|
329
|
+
domain: error.ErrorDomain.STORAGE,
|
|
330
|
+
category: error.ErrorCategory.USER,
|
|
331
|
+
details: { indexName }
|
|
332
|
+
});
|
|
333
|
+
}
|
|
311
334
|
if (!update.vector && !update.metadata) {
|
|
312
335
|
throw new error.MastraError({
|
|
313
|
-
id: "
|
|
336
|
+
id: storage.createVectorErrorId("PINECONE", "UPDATE_VECTOR", "NO_PAYLOAD"),
|
|
314
337
|
domain: error.ErrorDomain.STORAGE,
|
|
315
338
|
category: error.ErrorCategory.USER,
|
|
316
339
|
text: "No updates provided",
|
|
317
|
-
details: { indexName
|
|
340
|
+
details: { indexName }
|
|
318
341
|
});
|
|
319
342
|
}
|
|
343
|
+
const namespace = params.namespace;
|
|
320
344
|
try {
|
|
321
345
|
const index = this.client.Index(indexName).namespace(namespace || "");
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
346
|
+
if ("id" in params && params.id) {
|
|
347
|
+
const updateObj = { id: params.id };
|
|
348
|
+
if (update.vector) {
|
|
349
|
+
updateObj.values = update.vector;
|
|
350
|
+
}
|
|
351
|
+
if (update.metadata) {
|
|
352
|
+
updateObj.metadata = update.metadata;
|
|
353
|
+
}
|
|
354
|
+
await index.update(updateObj);
|
|
355
|
+
} else if ("filter" in params && params.filter) {
|
|
356
|
+
if (Object.keys(params.filter).length === 0) {
|
|
357
|
+
throw new error.MastraError({
|
|
358
|
+
id: storage.createVectorErrorId("PINECONE", "UPDATE_VECTOR", "EMPTY_FILTER"),
|
|
359
|
+
text: "Filter cannot be an empty filter object",
|
|
360
|
+
domain: error.ErrorDomain.STORAGE,
|
|
361
|
+
category: error.ErrorCategory.USER,
|
|
362
|
+
details: { indexName }
|
|
363
|
+
});
|
|
364
|
+
}
|
|
365
|
+
const translatedFilter = this.transformFilter(params.filter);
|
|
366
|
+
if (translatedFilter) {
|
|
367
|
+
const stats = await this.describeIndex({ indexName });
|
|
368
|
+
const dummyVector = new Array(stats.dimension).fill(1 / Math.sqrt(stats.dimension));
|
|
369
|
+
const results = await index.query({
|
|
370
|
+
vector: dummyVector,
|
|
371
|
+
topK: 1e4,
|
|
372
|
+
filter: translatedFilter,
|
|
373
|
+
includeMetadata: false,
|
|
374
|
+
includeValues: false
|
|
375
|
+
});
|
|
376
|
+
const idsToUpdate = results.matches.map((m) => m.id);
|
|
377
|
+
for (const id of idsToUpdate) {
|
|
378
|
+
const updateObj = { id };
|
|
379
|
+
if (update.vector) {
|
|
380
|
+
updateObj.values = update.vector;
|
|
381
|
+
}
|
|
382
|
+
if (update.metadata) {
|
|
383
|
+
updateObj.metadata = update.metadata;
|
|
384
|
+
}
|
|
385
|
+
await index.update(updateObj);
|
|
386
|
+
}
|
|
387
|
+
}
|
|
328
388
|
}
|
|
329
|
-
await index.update(updateObj);
|
|
330
389
|
} catch (error$1) {
|
|
390
|
+
if (error$1 instanceof error.MastraError) throw error$1;
|
|
331
391
|
throw new error.MastraError(
|
|
332
392
|
{
|
|
333
|
-
id: "
|
|
393
|
+
id: storage.createVectorErrorId("PINECONE", "UPDATE_VECTOR", "FAILED"),
|
|
334
394
|
domain: error.ErrorDomain.STORAGE,
|
|
335
395
|
category: error.ErrorCategory.THIRD_PARTY,
|
|
336
|
-
details: {
|
|
396
|
+
details: {
|
|
397
|
+
indexName,
|
|
398
|
+
..."id" in params && params.id && { id: params.id },
|
|
399
|
+
..."filter" in params && params.filter && { filter: JSON.stringify(params.filter) }
|
|
400
|
+
}
|
|
337
401
|
},
|
|
338
402
|
error$1
|
|
339
403
|
);
|
|
@@ -354,10 +418,100 @@ var PineconeVector = class extends vector.MastraVector {
|
|
|
354
418
|
} catch (error$1) {
|
|
355
419
|
throw new error.MastraError(
|
|
356
420
|
{
|
|
357
|
-
id: "
|
|
421
|
+
id: storage.createVectorErrorId("PINECONE", "DELETE_VECTOR", "FAILED"),
|
|
358
422
|
domain: error.ErrorDomain.STORAGE,
|
|
359
423
|
category: error.ErrorCategory.THIRD_PARTY,
|
|
360
|
-
details: {
|
|
424
|
+
details: {
|
|
425
|
+
indexName,
|
|
426
|
+
...id && { id }
|
|
427
|
+
}
|
|
428
|
+
},
|
|
429
|
+
error$1
|
|
430
|
+
);
|
|
431
|
+
}
|
|
432
|
+
}
|
|
433
|
+
/**
|
|
434
|
+
* Deletes multiple vectors by IDs or filter.
|
|
435
|
+
* @param indexName - The name of the index containing the vectors.
|
|
436
|
+
* @param ids - Array of vector IDs to delete (mutually exclusive with filter).
|
|
437
|
+
* @param filter - Filter to match vectors to delete (mutually exclusive with ids).
|
|
438
|
+
* @param namespace - The namespace of the index (optional, Pinecone-specific).
|
|
439
|
+
* @returns A promise that resolves when the deletion is complete.
|
|
440
|
+
* @throws Will throw an error if both ids and filter are provided, or if neither is provided.
|
|
441
|
+
*/
|
|
442
|
+
async deleteVectors(params) {
|
|
443
|
+
const { indexName, filter, ids } = params;
|
|
444
|
+
const namespace = params.namespace;
|
|
445
|
+
if (ids && filter) {
|
|
446
|
+
throw new error.MastraError({
|
|
447
|
+
id: storage.createVectorErrorId("PINECONE", "DELETE_VECTORS", "MUTUALLY_EXCLUSIVE"),
|
|
448
|
+
text: "Cannot specify both ids and filter - they are mutually exclusive",
|
|
449
|
+
domain: error.ErrorDomain.STORAGE,
|
|
450
|
+
category: error.ErrorCategory.USER,
|
|
451
|
+
details: { indexName }
|
|
452
|
+
});
|
|
453
|
+
}
|
|
454
|
+
if (!ids && !filter) {
|
|
455
|
+
throw new error.MastraError({
|
|
456
|
+
id: storage.createVectorErrorId("PINECONE", "DELETE_VECTORS", "NO_TARGET"),
|
|
457
|
+
text: "Either filter or ids must be provided",
|
|
458
|
+
domain: error.ErrorDomain.STORAGE,
|
|
459
|
+
category: error.ErrorCategory.USER,
|
|
460
|
+
details: { indexName }
|
|
461
|
+
});
|
|
462
|
+
}
|
|
463
|
+
if (ids && ids.length === 0) {
|
|
464
|
+
throw new error.MastraError({
|
|
465
|
+
id: storage.createVectorErrorId("PINECONE", "DELETE_VECTORS", "EMPTY_IDS"),
|
|
466
|
+
text: "Cannot delete with empty ids array",
|
|
467
|
+
domain: error.ErrorDomain.STORAGE,
|
|
468
|
+
category: error.ErrorCategory.USER,
|
|
469
|
+
details: { indexName }
|
|
470
|
+
});
|
|
471
|
+
}
|
|
472
|
+
if (filter && Object.keys(filter).length === 0) {
|
|
473
|
+
throw new error.MastraError({
|
|
474
|
+
id: storage.createVectorErrorId("PINECONE", "DELETE_VECTORS", "EMPTY_FILTER"),
|
|
475
|
+
text: "Cannot delete with empty filter object",
|
|
476
|
+
domain: error.ErrorDomain.STORAGE,
|
|
477
|
+
category: error.ErrorCategory.USER,
|
|
478
|
+
details: { indexName }
|
|
479
|
+
});
|
|
480
|
+
}
|
|
481
|
+
try {
|
|
482
|
+
const index = this.client.Index(indexName).namespace(namespace || "");
|
|
483
|
+
if (ids) {
|
|
484
|
+
await index.deleteMany(ids);
|
|
485
|
+
} else if (filter) {
|
|
486
|
+
const translatedFilter = this.transformFilter(filter);
|
|
487
|
+
if (translatedFilter) {
|
|
488
|
+
const stats = await this.describeIndex({ indexName });
|
|
489
|
+
const dummyVector = new Array(stats.dimension).fill(1 / Math.sqrt(stats.dimension));
|
|
490
|
+
const results = await index.query({
|
|
491
|
+
vector: dummyVector,
|
|
492
|
+
topK: 1e4,
|
|
493
|
+
filter: translatedFilter,
|
|
494
|
+
includeMetadata: false,
|
|
495
|
+
includeValues: false
|
|
496
|
+
});
|
|
497
|
+
const idsToDelete = results.matches.map((m) => m.id);
|
|
498
|
+
if (idsToDelete.length > 0) {
|
|
499
|
+
await index.deleteMany(idsToDelete);
|
|
500
|
+
}
|
|
501
|
+
}
|
|
502
|
+
}
|
|
503
|
+
} catch (error$1) {
|
|
504
|
+
if (error$1 instanceof error.MastraError) throw error$1;
|
|
505
|
+
throw new error.MastraError(
|
|
506
|
+
{
|
|
507
|
+
id: storage.createVectorErrorId("PINECONE", "DELETE_VECTORS", "FAILED"),
|
|
508
|
+
domain: error.ErrorDomain.STORAGE,
|
|
509
|
+
category: error.ErrorCategory.THIRD_PARTY,
|
|
510
|
+
details: {
|
|
511
|
+
indexName,
|
|
512
|
+
...filter && { filter: JSON.stringify(filter) },
|
|
513
|
+
...ids && { idsCount: ids.length }
|
|
514
|
+
}
|
|
361
515
|
},
|
|
362
516
|
error$1
|
|
363
517
|
);
|