@mastra/pinecone 0.10.3-alpha.0 → 0.11.0
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 +5 -5
- package/CHANGELOG.md +41 -0
- package/dist/_tsup-dts-rollup.d.cts +28 -5
- package/dist/_tsup-dts-rollup.d.ts +28 -5
- package/package.json +5 -5
- package/src/vector/filter.test.ts +25 -24
- package/src/vector/filter.ts +35 -4
- package/src/vector/index.test.ts +7 -3
- package/src/vector/index.ts +4 -4
package/.turbo/turbo-build.log
CHANGED
|
@@ -1,23 +1,23 @@
|
|
|
1
1
|
|
|
2
|
-
> @mastra/pinecone@0.
|
|
2
|
+
> @mastra/pinecone@0.11.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.5.0
|
|
8
8
|
[34mTSC[39m Build start
|
|
9
|
-
[32mTSC[39m ⚡️ Build success in
|
|
9
|
+
[32mTSC[39m ⚡️ Build success in 8153ms
|
|
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 10437ms
|
|
17
17
|
[34mCLI[39m Cleaning output folder
|
|
18
18
|
[34mESM[39m Build start
|
|
19
19
|
[34mCJS[39m Build start
|
|
20
20
|
[32mESM[39m [1mdist/index.js [22m[32m14.87 KB[39m
|
|
21
|
-
[32mESM[39m ⚡️ Build success in
|
|
21
|
+
[32mESM[39m ⚡️ Build success in 816ms
|
|
22
22
|
[32mCJS[39m [1mdist/index.cjs [22m[32m15.11 KB[39m
|
|
23
|
-
[32mCJS[39m ⚡️ Build success in
|
|
23
|
+
[32mCJS[39m ⚡️ Build success in 815ms
|
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,46 @@
|
|
|
1
1
|
# @mastra/pinecone
|
|
2
2
|
|
|
3
|
+
## 0.11.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 8a3bfd2: Update peerdeps to latest core
|
|
8
|
+
|
|
9
|
+
### Patch Changes
|
|
10
|
+
|
|
11
|
+
- 0e17048: Throw mastra errors in storage packages
|
|
12
|
+
- Updated dependencies [15e9d26]
|
|
13
|
+
- Updated dependencies [d1baedb]
|
|
14
|
+
- Updated dependencies [d8f2d19]
|
|
15
|
+
- Updated dependencies [4d21bf2]
|
|
16
|
+
- Updated dependencies [07d6d88]
|
|
17
|
+
- Updated dependencies [9d52b17]
|
|
18
|
+
- Updated dependencies [2097952]
|
|
19
|
+
- Updated dependencies [792c4c0]
|
|
20
|
+
- Updated dependencies [5d74aab]
|
|
21
|
+
- Updated dependencies [a8b194f]
|
|
22
|
+
- Updated dependencies [4fb0cc2]
|
|
23
|
+
- Updated dependencies [d2a7a31]
|
|
24
|
+
- Updated dependencies [502fe05]
|
|
25
|
+
- Updated dependencies [144eb0b]
|
|
26
|
+
- Updated dependencies [8ba1b51]
|
|
27
|
+
- Updated dependencies [4efcfa0]
|
|
28
|
+
- Updated dependencies [0e17048]
|
|
29
|
+
- @mastra/core@0.10.7
|
|
30
|
+
|
|
31
|
+
## 0.11.0-alpha.1
|
|
32
|
+
|
|
33
|
+
### Minor Changes
|
|
34
|
+
|
|
35
|
+
- 8a3bfd2: Update peerdeps to latest core
|
|
36
|
+
|
|
37
|
+
### Patch Changes
|
|
38
|
+
|
|
39
|
+
- Updated dependencies [792c4c0]
|
|
40
|
+
- Updated dependencies [502fe05]
|
|
41
|
+
- Updated dependencies [4efcfa0]
|
|
42
|
+
- @mastra/core@0.10.7-alpha.3
|
|
43
|
+
|
|
3
44
|
## 0.10.3-alpha.0
|
|
4
45
|
|
|
5
46
|
### Patch Changes
|
|
@@ -1,12 +1,17 @@
|
|
|
1
1
|
import { BaseFilterTranslator } from '@mastra/core/vector/filter';
|
|
2
|
+
import type { BlacklistedRootOperators } from '@mastra/core/vector/filter';
|
|
2
3
|
import type { CreateIndexParams } from '@mastra/core/vector';
|
|
3
4
|
import type { DeleteIndexParams } from '@mastra/core/vector';
|
|
4
5
|
import type { DeleteVectorParams } from '@mastra/core/vector';
|
|
5
6
|
import type { DescribeIndexParams } from '@mastra/core/vector';
|
|
7
|
+
import type { FilterValue } from '@mastra/core/vector/filter';
|
|
6
8
|
import type { IndexStats } from '@mastra/core/vector';
|
|
7
9
|
import type { IndexStatsDescription } from '@pinecone-database/pinecone';
|
|
10
|
+
import type { LogicalOperatorValueMap } from '@mastra/core/vector/filter';
|
|
8
11
|
import { MastraVector } from '@mastra/core/vector';
|
|
12
|
+
import type { OperatorCondition } from '@mastra/core/vector/filter';
|
|
9
13
|
import type { OperatorSupport } from '@mastra/core/vector/filter';
|
|
14
|
+
import type { OperatorValueMap } from '@mastra/core/vector/filter';
|
|
10
15
|
import type { QueryResult } from '@mastra/core/vector';
|
|
11
16
|
import type { QueryVectorParams } from '@mastra/core/vector';
|
|
12
17
|
import type { RecordSparseValues } from '@pinecone-database/pinecone';
|
|
@@ -14,6 +19,14 @@ import type { UpdateVectorParams } from '@mastra/core/vector';
|
|
|
14
19
|
import type { UpsertVectorParams } from '@mastra/core/vector';
|
|
15
20
|
import type { VectorFilter } from '@mastra/core/vector/filter';
|
|
16
21
|
|
|
22
|
+
declare type InitialOperatorValueMap = Omit<OperatorValueMap, '$regex' | '$options' | '$elemMatch' | '$all'> & {
|
|
23
|
+
$contains: string;
|
|
24
|
+
$gt: number | Date;
|
|
25
|
+
$gte: number | Date;
|
|
26
|
+
$lt: number | Date;
|
|
27
|
+
$lte: number | Date;
|
|
28
|
+
};
|
|
29
|
+
|
|
17
30
|
/**
|
|
18
31
|
* Vector store specific prompt that details supported operators and examples.
|
|
19
32
|
* This prompt helps users construct valid filters for Pinecone Vector.
|
|
@@ -22,13 +35,15 @@ declare const PINECONE_PROMPT = "When querying Pinecone, you can ONLY use the op
|
|
|
22
35
|
export { PINECONE_PROMPT }
|
|
23
36
|
export { PINECONE_PROMPT as PINECONE_PROMPT_alias_1 }
|
|
24
37
|
|
|
38
|
+
declare type PineconeBlacklisted = BlacklistedRootOperators | '$not' | '$nor';
|
|
39
|
+
|
|
25
40
|
declare interface PineconeDeleteVectorParams extends DeleteVectorParams {
|
|
26
41
|
namespace?: string;
|
|
27
42
|
}
|
|
28
43
|
|
|
29
|
-
export declare class PineconeFilterTranslator extends BaseFilterTranslator {
|
|
44
|
+
export declare class PineconeFilterTranslator extends BaseFilterTranslator<PineconeVectorFilter> {
|
|
30
45
|
protected getSupportedOperators(): OperatorSupport;
|
|
31
|
-
translate(filter?:
|
|
46
|
+
translate(filter?: PineconeVectorFilter): PineconeVectorFilter;
|
|
32
47
|
private translateNode;
|
|
33
48
|
private translateOperator;
|
|
34
49
|
}
|
|
@@ -37,7 +52,13 @@ declare interface PineconeIndexStats extends IndexStats {
|
|
|
37
52
|
namespaces?: IndexStatsDescription['namespaces'];
|
|
38
53
|
}
|
|
39
54
|
|
|
40
|
-
declare
|
|
55
|
+
declare type PineconeLogicalOperatorValueMap = Omit<LogicalOperatorValueMap, '$not' | '$nor'>;
|
|
56
|
+
|
|
57
|
+
declare type PineconeOperatorValueMap = InitialOperatorValueMap & {
|
|
58
|
+
$all: OperatorCondition<keyof InitialOperatorValueMap, InitialOperatorValueMap>[] | FilterValue[];
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
declare interface PineconeQueryVectorParams extends QueryVectorParams<PineconeVectorFilter> {
|
|
41
62
|
namespace?: string;
|
|
42
63
|
sparseVector?: RecordSparseValues;
|
|
43
64
|
}
|
|
@@ -51,7 +72,7 @@ declare interface PineconeUpsertVectorParams extends UpsertVectorParams {
|
|
|
51
72
|
sparseVectors?: RecordSparseValues[];
|
|
52
73
|
}
|
|
53
74
|
|
|
54
|
-
declare class PineconeVector extends MastraVector {
|
|
75
|
+
declare class PineconeVector extends MastraVector<PineconeVectorFilter> {
|
|
55
76
|
private client;
|
|
56
77
|
/**
|
|
57
78
|
* Creates a new PineconeVector client.
|
|
@@ -65,7 +86,7 @@ declare class PineconeVector extends MastraVector {
|
|
|
65
86
|
get indexSeparator(): string;
|
|
66
87
|
createIndex({ indexName, dimension, metric }: CreateIndexParams): Promise<void>;
|
|
67
88
|
upsert({ indexName, vectors, metadata, ids, namespace, sparseVectors, }: PineconeUpsertVectorParams): Promise<string[]>;
|
|
68
|
-
transformFilter(filter?:
|
|
89
|
+
transformFilter(filter?: PineconeVectorFilter): PineconeVectorFilter;
|
|
69
90
|
query({ indexName, queryVector, topK, filter, includeVector, namespace, sparseVector, }: PineconeQueryVectorParams): Promise<QueryResult[]>;
|
|
70
91
|
listIndexes(): Promise<string[]>;
|
|
71
92
|
/**
|
|
@@ -101,4 +122,6 @@ declare class PineconeVector extends MastraVector {
|
|
|
101
122
|
export { PineconeVector }
|
|
102
123
|
export { PineconeVector as PineconeVector_alias_1 }
|
|
103
124
|
|
|
125
|
+
export declare type PineconeVectorFilter = VectorFilter<keyof PineconeOperatorValueMap, PineconeOperatorValueMap, PineconeLogicalOperatorValueMap, PineconeBlacklisted>;
|
|
126
|
+
|
|
104
127
|
export { }
|
|
@@ -1,12 +1,17 @@
|
|
|
1
1
|
import { BaseFilterTranslator } from '@mastra/core/vector/filter';
|
|
2
|
+
import type { BlacklistedRootOperators } from '@mastra/core/vector/filter';
|
|
2
3
|
import type { CreateIndexParams } from '@mastra/core/vector';
|
|
3
4
|
import type { DeleteIndexParams } from '@mastra/core/vector';
|
|
4
5
|
import type { DeleteVectorParams } from '@mastra/core/vector';
|
|
5
6
|
import type { DescribeIndexParams } from '@mastra/core/vector';
|
|
7
|
+
import type { FilterValue } from '@mastra/core/vector/filter';
|
|
6
8
|
import type { IndexStats } from '@mastra/core/vector';
|
|
7
9
|
import type { IndexStatsDescription } from '@pinecone-database/pinecone';
|
|
10
|
+
import type { LogicalOperatorValueMap } from '@mastra/core/vector/filter';
|
|
8
11
|
import { MastraVector } from '@mastra/core/vector';
|
|
12
|
+
import type { OperatorCondition } from '@mastra/core/vector/filter';
|
|
9
13
|
import type { OperatorSupport } from '@mastra/core/vector/filter';
|
|
14
|
+
import type { OperatorValueMap } from '@mastra/core/vector/filter';
|
|
10
15
|
import type { QueryResult } from '@mastra/core/vector';
|
|
11
16
|
import type { QueryVectorParams } from '@mastra/core/vector';
|
|
12
17
|
import type { RecordSparseValues } from '@pinecone-database/pinecone';
|
|
@@ -14,6 +19,14 @@ import type { UpdateVectorParams } from '@mastra/core/vector';
|
|
|
14
19
|
import type { UpsertVectorParams } from '@mastra/core/vector';
|
|
15
20
|
import type { VectorFilter } from '@mastra/core/vector/filter';
|
|
16
21
|
|
|
22
|
+
declare type InitialOperatorValueMap = Omit<OperatorValueMap, '$regex' | '$options' | '$elemMatch' | '$all'> & {
|
|
23
|
+
$contains: string;
|
|
24
|
+
$gt: number | Date;
|
|
25
|
+
$gte: number | Date;
|
|
26
|
+
$lt: number | Date;
|
|
27
|
+
$lte: number | Date;
|
|
28
|
+
};
|
|
29
|
+
|
|
17
30
|
/**
|
|
18
31
|
* Vector store specific prompt that details supported operators and examples.
|
|
19
32
|
* This prompt helps users construct valid filters for Pinecone Vector.
|
|
@@ -22,13 +35,15 @@ declare const PINECONE_PROMPT = "When querying Pinecone, you can ONLY use the op
|
|
|
22
35
|
export { PINECONE_PROMPT }
|
|
23
36
|
export { PINECONE_PROMPT as PINECONE_PROMPT_alias_1 }
|
|
24
37
|
|
|
38
|
+
declare type PineconeBlacklisted = BlacklistedRootOperators | '$not' | '$nor';
|
|
39
|
+
|
|
25
40
|
declare interface PineconeDeleteVectorParams extends DeleteVectorParams {
|
|
26
41
|
namespace?: string;
|
|
27
42
|
}
|
|
28
43
|
|
|
29
|
-
export declare class PineconeFilterTranslator extends BaseFilterTranslator {
|
|
44
|
+
export declare class PineconeFilterTranslator extends BaseFilterTranslator<PineconeVectorFilter> {
|
|
30
45
|
protected getSupportedOperators(): OperatorSupport;
|
|
31
|
-
translate(filter?:
|
|
46
|
+
translate(filter?: PineconeVectorFilter): PineconeVectorFilter;
|
|
32
47
|
private translateNode;
|
|
33
48
|
private translateOperator;
|
|
34
49
|
}
|
|
@@ -37,7 +52,13 @@ declare interface PineconeIndexStats extends IndexStats {
|
|
|
37
52
|
namespaces?: IndexStatsDescription['namespaces'];
|
|
38
53
|
}
|
|
39
54
|
|
|
40
|
-
declare
|
|
55
|
+
declare type PineconeLogicalOperatorValueMap = Omit<LogicalOperatorValueMap, '$not' | '$nor'>;
|
|
56
|
+
|
|
57
|
+
declare type PineconeOperatorValueMap = InitialOperatorValueMap & {
|
|
58
|
+
$all: OperatorCondition<keyof InitialOperatorValueMap, InitialOperatorValueMap>[] | FilterValue[];
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
declare interface PineconeQueryVectorParams extends QueryVectorParams<PineconeVectorFilter> {
|
|
41
62
|
namespace?: string;
|
|
42
63
|
sparseVector?: RecordSparseValues;
|
|
43
64
|
}
|
|
@@ -51,7 +72,7 @@ declare interface PineconeUpsertVectorParams extends UpsertVectorParams {
|
|
|
51
72
|
sparseVectors?: RecordSparseValues[];
|
|
52
73
|
}
|
|
53
74
|
|
|
54
|
-
declare class PineconeVector extends MastraVector {
|
|
75
|
+
declare class PineconeVector extends MastraVector<PineconeVectorFilter> {
|
|
55
76
|
private client;
|
|
56
77
|
/**
|
|
57
78
|
* Creates a new PineconeVector client.
|
|
@@ -65,7 +86,7 @@ declare class PineconeVector extends MastraVector {
|
|
|
65
86
|
get indexSeparator(): string;
|
|
66
87
|
createIndex({ indexName, dimension, metric }: CreateIndexParams): Promise<void>;
|
|
67
88
|
upsert({ indexName, vectors, metadata, ids, namespace, sparseVectors, }: PineconeUpsertVectorParams): Promise<string[]>;
|
|
68
|
-
transformFilter(filter?:
|
|
89
|
+
transformFilter(filter?: PineconeVectorFilter): PineconeVectorFilter;
|
|
69
90
|
query({ indexName, queryVector, topK, filter, includeVector, namespace, sparseVector, }: PineconeQueryVectorParams): Promise<QueryResult[]>;
|
|
70
91
|
listIndexes(): Promise<string[]>;
|
|
71
92
|
/**
|
|
@@ -101,4 +122,6 @@ declare class PineconeVector extends MastraVector {
|
|
|
101
122
|
export { PineconeVector }
|
|
102
123
|
export { PineconeVector as PineconeVector_alias_1 }
|
|
103
124
|
|
|
125
|
+
export declare type PineconeVectorFilter = VectorFilter<keyof PineconeOperatorValueMap, PineconeOperatorValueMap, PineconeLogicalOperatorValueMap, PineconeBlacklisted>;
|
|
126
|
+
|
|
104
127
|
export { }
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mastra/pinecone",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.11.0",
|
|
4
4
|
"description": "Pinecone vector store provider for Mastra",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -26,15 +26,15 @@
|
|
|
26
26
|
"@microsoft/api-extractor": "^7.52.8",
|
|
27
27
|
"@types/node": "^20.19.0",
|
|
28
28
|
"dotenv": "^16.5.0",
|
|
29
|
-
"eslint": "^9.
|
|
29
|
+
"eslint": "^9.29.0",
|
|
30
30
|
"tsup": "^8.5.0",
|
|
31
31
|
"typescript": "^5.8.3",
|
|
32
32
|
"vitest": "^3.2.3",
|
|
33
|
-
"@internal/lint": "0.0.
|
|
34
|
-
"@mastra/core": "0.10.7
|
|
33
|
+
"@internal/lint": "0.0.14",
|
|
34
|
+
"@mastra/core": "0.10.7"
|
|
35
35
|
},
|
|
36
36
|
"peerDependencies": {
|
|
37
|
-
"@mastra/core": ">=0.10.
|
|
37
|
+
"@mastra/core": ">=0.10.7-0 <0.11.0-0"
|
|
38
38
|
},
|
|
39
39
|
"scripts": {
|
|
40
40
|
"build": "tsup src/index.ts --format esm,cjs --experimental-dts --clean --treeshake=smallest --splitting",
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { describe, it, expect, beforeEach } from 'vitest';
|
|
2
2
|
|
|
3
|
+
import type { PineconeVectorFilter } from './filter';
|
|
3
4
|
import { PineconeFilterTranslator } from './filter';
|
|
4
5
|
|
|
5
6
|
describe('PineconeFilterTranslator', () => {
|
|
@@ -13,17 +14,17 @@ describe('PineconeFilterTranslator', () => {
|
|
|
13
14
|
describe('basic operations', () => {
|
|
14
15
|
it('handles empty filters', () => {
|
|
15
16
|
expect(translator.translate({})).toEqual({});
|
|
16
|
-
expect(translator.translate(null
|
|
17
|
-
expect(translator.translate(undefined
|
|
17
|
+
expect(translator.translate(null)).toEqual(null);
|
|
18
|
+
expect(translator.translate(undefined)).toEqual(undefined);
|
|
18
19
|
});
|
|
19
20
|
|
|
20
21
|
it('allows implicit equality', () => {
|
|
21
|
-
const filter = { field: 'value' };
|
|
22
|
+
const filter: PineconeVectorFilter = { field: 'value' };
|
|
22
23
|
expect(translator.translate(filter)).toEqual({ field: 'value' });
|
|
23
24
|
});
|
|
24
25
|
|
|
25
26
|
it('allows multiple top-level fields', () => {
|
|
26
|
-
const filter = {
|
|
27
|
+
const filter: PineconeVectorFilter = {
|
|
27
28
|
field1: 'value1',
|
|
28
29
|
field2: 'value2',
|
|
29
30
|
};
|
|
@@ -34,7 +35,7 @@ describe('PineconeFilterTranslator', () => {
|
|
|
34
35
|
});
|
|
35
36
|
|
|
36
37
|
it('handles multiple operators on same field', () => {
|
|
37
|
-
const filter = {
|
|
38
|
+
const filter: PineconeVectorFilter = {
|
|
38
39
|
price: { $gt: 100, $lt: 200 },
|
|
39
40
|
quantity: { $gte: 10, $lte: 20 },
|
|
40
41
|
};
|
|
@@ -46,12 +47,12 @@ describe('PineconeFilterTranslator', () => {
|
|
|
46
47
|
|
|
47
48
|
it('normalizes date values', () => {
|
|
48
49
|
const date = new Date('2024-01-01');
|
|
49
|
-
const filter = { timestamp: { $gt: date } };
|
|
50
|
+
const filter: PineconeVectorFilter = { timestamp: { $gt: date } };
|
|
50
51
|
expect(translator.translate(filter)).toEqual({ timestamp: { $gt: date.toISOString() } });
|
|
51
52
|
});
|
|
52
53
|
|
|
53
54
|
it('handles $exists operator', () => {
|
|
54
|
-
const filter = { field: { $exists: true } };
|
|
55
|
+
const filter: PineconeVectorFilter = { field: { $exists: true } };
|
|
55
56
|
expect(translator.translate(filter)).toEqual({ field: { $exists: true } });
|
|
56
57
|
});
|
|
57
58
|
});
|
|
@@ -59,12 +60,12 @@ describe('PineconeFilterTranslator', () => {
|
|
|
59
60
|
// Array Operations
|
|
60
61
|
describe('array operations', () => {
|
|
61
62
|
it('handles arrays as $in operator', () => {
|
|
62
|
-
const filter = { tags: ['tag1', 'tag2'] };
|
|
63
|
+
const filter: PineconeVectorFilter = { tags: ['tag1', 'tag2'] };
|
|
63
64
|
expect(translator.translate(filter)).toEqual({ tags: { $in: ['tag1', 'tag2'] } });
|
|
64
65
|
});
|
|
65
66
|
|
|
66
67
|
it('simulates $all using $and + $in', () => {
|
|
67
|
-
const filter = { tags: { $all: ['tag1', 'tag2'] } };
|
|
68
|
+
const filter: PineconeVectorFilter = { tags: { $all: ['tag1', 'tag2'] } };
|
|
68
69
|
expect(translator.translate(filter)).toEqual({
|
|
69
70
|
$and: [{ tags: { $in: ['tag1'] } }, { tags: { $in: ['tag2'] } }],
|
|
70
71
|
});
|
|
@@ -127,7 +128,7 @@ describe('PineconeFilterTranslator', () => {
|
|
|
127
128
|
// Logical Operators
|
|
128
129
|
describe('logical operators', () => {
|
|
129
130
|
it('handles logical operators', () => {
|
|
130
|
-
const filter = {
|
|
131
|
+
const filter: PineconeVectorFilter = {
|
|
131
132
|
$or: [{ status: 'active' }, { age: { $gt: 25 } }],
|
|
132
133
|
};
|
|
133
134
|
expect(translator.translate(filter)).toEqual({
|
|
@@ -136,7 +137,7 @@ describe('PineconeFilterTranslator', () => {
|
|
|
136
137
|
});
|
|
137
138
|
|
|
138
139
|
it('handles nested logical operators', () => {
|
|
139
|
-
const filter = {
|
|
140
|
+
const filter: PineconeVectorFilter = {
|
|
140
141
|
$and: [
|
|
141
142
|
{ status: 'active' },
|
|
142
143
|
{
|
|
@@ -170,7 +171,7 @@ describe('PineconeFilterTranslator', () => {
|
|
|
170
171
|
});
|
|
171
172
|
|
|
172
173
|
it('handles complex nested conditions', () => {
|
|
173
|
-
const filter = {
|
|
174
|
+
const filter: PineconeVectorFilter = {
|
|
174
175
|
$or: [
|
|
175
176
|
{ age: { $gt: 25 } },
|
|
176
177
|
{
|
|
@@ -205,7 +206,7 @@ describe('PineconeFilterTranslator', () => {
|
|
|
205
206
|
});
|
|
206
207
|
|
|
207
208
|
it('preserves empty objects as exact match conditions', () => {
|
|
208
|
-
const filter = {
|
|
209
|
+
const filter: PineconeVectorFilter = {
|
|
209
210
|
metadata: {},
|
|
210
211
|
'user.profile': {},
|
|
211
212
|
};
|
|
@@ -217,7 +218,7 @@ describe('PineconeFilterTranslator', () => {
|
|
|
217
218
|
});
|
|
218
219
|
|
|
219
220
|
it('handles empty objects in logical operators', () => {
|
|
220
|
-
const filter = {
|
|
221
|
+
const filter: PineconeVectorFilter = {
|
|
221
222
|
$or: [{}, { status: 'active' }],
|
|
222
223
|
};
|
|
223
224
|
|
|
@@ -241,7 +242,7 @@ describe('PineconeFilterTranslator', () => {
|
|
|
241
242
|
});
|
|
242
243
|
|
|
243
244
|
it('handles empty objects in comparison operators', () => {
|
|
244
|
-
const filter = {
|
|
245
|
+
const filter: PineconeVectorFilter = {
|
|
245
246
|
metadata: { $eq: {} },
|
|
246
247
|
};
|
|
247
248
|
|
|
@@ -251,7 +252,7 @@ describe('PineconeFilterTranslator', () => {
|
|
|
251
252
|
});
|
|
252
253
|
|
|
253
254
|
it('handles empty objects in array operators', () => {
|
|
254
|
-
const filter = {
|
|
255
|
+
const filter: PineconeVectorFilter = {
|
|
255
256
|
tags: { $in: [{}] },
|
|
256
257
|
};
|
|
257
258
|
|
|
@@ -367,7 +368,7 @@ describe('PineconeFilterTranslator', () => {
|
|
|
367
368
|
});
|
|
368
369
|
|
|
369
370
|
it('throws error for unsupported logical operators', () => {
|
|
370
|
-
const invalidFilters = [
|
|
371
|
+
const invalidFilters: any = [
|
|
371
372
|
{
|
|
372
373
|
$not: { field: 'value' },
|
|
373
374
|
},
|
|
@@ -389,13 +390,13 @@ describe('PineconeFilterTranslator', () => {
|
|
|
389
390
|
});
|
|
390
391
|
|
|
391
392
|
it('ensure all operator filters are supported', () => {
|
|
392
|
-
const supportedFilters = [
|
|
393
|
+
const supportedFilters: PineconeVectorFilter[] = [
|
|
393
394
|
{ field: { $eq: 'value' } },
|
|
394
395
|
{ field: { $ne: 'value' } },
|
|
395
|
-
{ field: { $gt:
|
|
396
|
-
{ field: { $gte:
|
|
397
|
-
{ field: { $lt:
|
|
398
|
-
{ field: { $lte:
|
|
396
|
+
{ field: { $gt: 10 } },
|
|
397
|
+
{ field: { $gte: 10 } },
|
|
398
|
+
{ field: { $lt: 10 } },
|
|
399
|
+
{ field: { $lte: 10 } },
|
|
399
400
|
{ field: { $in: ['value'] } },
|
|
400
401
|
{ $and: [{ field: { $eq: 'value' } }] },
|
|
401
402
|
{ $or: [{ field: { $eq: 'value' } }] },
|
|
@@ -431,7 +432,7 @@ describe('PineconeFilterTranslator', () => {
|
|
|
431
432
|
});
|
|
432
433
|
|
|
433
434
|
it('throws error for invalid operator values', () => {
|
|
434
|
-
const filter = { tags: { $all: 'not-an-array' } };
|
|
435
|
+
const filter: any = { tags: { $all: 'not-an-array' } };
|
|
435
436
|
expect(() => translator.translate(filter)).toThrow();
|
|
436
437
|
});
|
|
437
438
|
it('throws error for regex operators', () => {
|
|
@@ -439,7 +440,7 @@ describe('PineconeFilterTranslator', () => {
|
|
|
439
440
|
expect(() => translator.translate(filter)).toThrow();
|
|
440
441
|
});
|
|
441
442
|
it('throws error for non-logical operators at top level', () => {
|
|
442
|
-
const invalidFilters = [{ $gt: 100 }, { $in: ['value1', 'value2'] }, { $eq: true }];
|
|
443
|
+
const invalidFilters: any = [{ $gt: 100 }, { $in: ['value1', 'value2'] }, { $eq: true }];
|
|
443
444
|
|
|
444
445
|
invalidFilters.forEach(filter => {
|
|
445
446
|
expect(() => translator.translate(filter)).toThrow(/Invalid top-level operator/);
|
package/src/vector/filter.ts
CHANGED
|
@@ -1,7 +1,38 @@
|
|
|
1
1
|
import { BaseFilterTranslator } from '@mastra/core/vector/filter';
|
|
2
|
-
import type {
|
|
2
|
+
import type {
|
|
3
|
+
VectorFilter,
|
|
4
|
+
OperatorSupport,
|
|
5
|
+
OperatorValueMap,
|
|
6
|
+
LogicalOperatorValueMap,
|
|
7
|
+
BlacklistedRootOperators,
|
|
8
|
+
QueryOperator,
|
|
9
|
+
FilterValue,
|
|
10
|
+
OperatorCondition,
|
|
11
|
+
} from '@mastra/core/vector/filter';
|
|
3
12
|
|
|
4
|
-
|
|
13
|
+
type InitialOperatorValueMap = Omit<OperatorValueMap, '$regex' | '$options' | '$elemMatch' | '$all'> & {
|
|
14
|
+
$contains: string;
|
|
15
|
+
$gt: number | Date;
|
|
16
|
+
$gte: number | Date;
|
|
17
|
+
$lt: number | Date;
|
|
18
|
+
$lte: number | Date;
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
type PineconeOperatorValueMap = InitialOperatorValueMap & {
|
|
22
|
+
$all: OperatorCondition<keyof InitialOperatorValueMap, InitialOperatorValueMap>[] | FilterValue[];
|
|
23
|
+
};
|
|
24
|
+
type PineconeLogicalOperatorValueMap = Omit<LogicalOperatorValueMap, '$not' | '$nor'>;
|
|
25
|
+
|
|
26
|
+
type PineconeBlacklisted = BlacklistedRootOperators | '$not' | '$nor';
|
|
27
|
+
|
|
28
|
+
export type PineconeVectorFilter = VectorFilter<
|
|
29
|
+
keyof PineconeOperatorValueMap,
|
|
30
|
+
PineconeOperatorValueMap,
|
|
31
|
+
PineconeLogicalOperatorValueMap,
|
|
32
|
+
PineconeBlacklisted
|
|
33
|
+
>;
|
|
34
|
+
|
|
35
|
+
export class PineconeFilterTranslator extends BaseFilterTranslator<PineconeVectorFilter> {
|
|
5
36
|
protected override getSupportedOperators(): OperatorSupport {
|
|
6
37
|
return {
|
|
7
38
|
...BaseFilterTranslator.DEFAULT_OPERATORS,
|
|
@@ -13,13 +44,13 @@ export class PineconeFilterTranslator extends BaseFilterTranslator {
|
|
|
13
44
|
};
|
|
14
45
|
}
|
|
15
46
|
|
|
16
|
-
translate(filter?:
|
|
47
|
+
translate(filter?: PineconeVectorFilter): PineconeVectorFilter {
|
|
17
48
|
if (this.isEmpty(filter)) return filter;
|
|
18
49
|
this.validateFilter(filter);
|
|
19
50
|
return this.translateNode(filter);
|
|
20
51
|
}
|
|
21
52
|
|
|
22
|
-
private translateNode(node:
|
|
53
|
+
private translateNode(node: PineconeVectorFilter, currentPath: string = ''): any {
|
|
23
54
|
if (this.isRegex(node)) {
|
|
24
55
|
throw new Error('Regex is not supported in Pinecone');
|
|
25
56
|
}
|
package/src/vector/index.test.ts
CHANGED
|
@@ -728,7 +728,11 @@ describe.skip('PineconeVector Integration Tests', () => {
|
|
|
728
728
|
vectorDB.query({
|
|
729
729
|
indexName: testIndexName,
|
|
730
730
|
queryVector: [1, 0, 0],
|
|
731
|
-
filter: {
|
|
731
|
+
filter: {
|
|
732
|
+
field1: { $in: 'not-array' },
|
|
733
|
+
field2: { $exists: 'not-boolean' },
|
|
734
|
+
field3: { $gt: 'not-number' },
|
|
735
|
+
} as any,
|
|
732
736
|
}),
|
|
733
737
|
).rejects.toThrow();
|
|
734
738
|
});
|
|
@@ -754,7 +758,7 @@ describe.skip('PineconeVector Integration Tests', () => {
|
|
|
754
758
|
vectorDB.query({
|
|
755
759
|
indexName: testIndexName,
|
|
756
760
|
queryVector: [1, 0, 0],
|
|
757
|
-
filter: { field: { $all: 'not-an-array' } },
|
|
761
|
+
filter: { field: { $all: 'not-an-array' } } as any,
|
|
758
762
|
}),
|
|
759
763
|
).rejects.toThrow('A non-empty array is required for the $all operator');
|
|
760
764
|
});
|
|
@@ -1164,7 +1168,7 @@ describe.skip('PineconeVector Integration Tests', () => {
|
|
|
1164
1168
|
vectorDB.query({
|
|
1165
1169
|
indexName: testIndexName,
|
|
1166
1170
|
queryVector: [1, 0, 0],
|
|
1167
|
-
filter: { price: { $gt: '500' } }, // string instead of number
|
|
1171
|
+
filter: { price: { $gt: '500' } } as any, // string instead of number
|
|
1168
1172
|
}),
|
|
1169
1173
|
).rejects.toThrow('the $gt operator must be followed by a number');
|
|
1170
1174
|
});
|
package/src/vector/index.ts
CHANGED
|
@@ -11,7 +11,6 @@ import type {
|
|
|
11
11
|
DeleteVectorParams,
|
|
12
12
|
UpdateVectorParams,
|
|
13
13
|
} from '@mastra/core/vector';
|
|
14
|
-
import type { VectorFilter } from '@mastra/core/vector/filter';
|
|
15
14
|
import { Pinecone } from '@pinecone-database/pinecone';
|
|
16
15
|
import type {
|
|
17
16
|
IndexStatsDescription,
|
|
@@ -21,12 +20,13 @@ import type {
|
|
|
21
20
|
} from '@pinecone-database/pinecone';
|
|
22
21
|
|
|
23
22
|
import { PineconeFilterTranslator } from './filter';
|
|
23
|
+
import type { PineconeVectorFilter } from './filter';
|
|
24
24
|
|
|
25
25
|
interface PineconeIndexStats extends IndexStats {
|
|
26
26
|
namespaces?: IndexStatsDescription['namespaces'];
|
|
27
27
|
}
|
|
28
28
|
|
|
29
|
-
interface PineconeQueryVectorParams extends QueryVectorParams {
|
|
29
|
+
interface PineconeQueryVectorParams extends QueryVectorParams<PineconeVectorFilter> {
|
|
30
30
|
namespace?: string;
|
|
31
31
|
sparseVector?: RecordSparseValues;
|
|
32
32
|
}
|
|
@@ -44,7 +44,7 @@ interface PineconeDeleteVectorParams extends DeleteVectorParams {
|
|
|
44
44
|
namespace?: string;
|
|
45
45
|
}
|
|
46
46
|
|
|
47
|
-
export class PineconeVector extends MastraVector {
|
|
47
|
+
export class PineconeVector extends MastraVector<PineconeVectorFilter> {
|
|
48
48
|
private client: Pinecone;
|
|
49
49
|
|
|
50
50
|
/**
|
|
@@ -172,7 +172,7 @@ export class PineconeVector extends MastraVector {
|
|
|
172
172
|
}
|
|
173
173
|
}
|
|
174
174
|
|
|
175
|
-
transformFilter(filter?:
|
|
175
|
+
transformFilter(filter?: PineconeVectorFilter) {
|
|
176
176
|
const translator = new PineconeFilterTranslator();
|
|
177
177
|
return translator.translate(filter);
|
|
178
178
|
}
|