@mastra/chroma 0.10.4-alpha.0 → 0.11.0-alpha.2
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 +24 -0
- package/dist/_tsup-dts-rollup.d.cts +23 -6
- package/dist/_tsup-dts-rollup.d.ts +23 -6
- package/package.json +4 -4
- package/src/vector/filter.test.ts +24 -19
- package/src/vector/filter.ts +35 -4
- package/src/vector/index.test.ts +4 -4
- package/src/vector/index.ts +5 -5
package/.turbo/turbo-build.log
CHANGED
|
@@ -1,23 +1,23 @@
|
|
|
1
1
|
|
|
2
|
-
> @mastra/chroma@0.
|
|
2
|
+
> @mastra/chroma@0.11.0-alpha.2 build /home/runner/work/mastra/mastra/stores/chroma
|
|
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 10138ms
|
|
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/chroma/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/chroma/dist/_tsup-dts-rollup.d.cts[39m
|
|
16
|
-
[32mDTS[39m ⚡️ Build success in
|
|
16
|
+
[32mDTS[39m ⚡️ Build success in 9490ms
|
|
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 739ms
|
|
22
22
|
[32mCJS[39m [1mdist/index.cjs [22m[32m15.17 KB[39m
|
|
23
|
-
[32mCJS[39m ⚡️ Build success in
|
|
23
|
+
[32mCJS[39m ⚡️ Build success in 738ms
|
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,29 @@
|
|
|
1
1
|
# @mastra/chroma
|
|
2
2
|
|
|
3
|
+
## 0.11.0-alpha.2
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 8a3bfd2: Update peerdeps to latest core
|
|
8
|
+
|
|
9
|
+
### Patch Changes
|
|
10
|
+
|
|
11
|
+
- Updated dependencies [792c4c0]
|
|
12
|
+
- Updated dependencies [502fe05]
|
|
13
|
+
- Updated dependencies [4efcfa0]
|
|
14
|
+
- @mastra/core@0.10.7-alpha.3
|
|
15
|
+
|
|
16
|
+
## 0.10.4-alpha.1
|
|
17
|
+
|
|
18
|
+
### Patch Changes
|
|
19
|
+
|
|
20
|
+
- 144eb0b: [MASTRA-3669] Metadata Filter Types
|
|
21
|
+
- Updated dependencies [15e9d26]
|
|
22
|
+
- Updated dependencies [07d6d88]
|
|
23
|
+
- Updated dependencies [5d74aab]
|
|
24
|
+
- Updated dependencies [144eb0b]
|
|
25
|
+
- @mastra/core@0.10.7-alpha.2
|
|
26
|
+
|
|
3
27
|
## 0.10.4-alpha.0
|
|
4
28
|
|
|
5
29
|
### Patch Changes
|
|
@@ -1,11 +1,14 @@
|
|
|
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';
|
|
6
7
|
import type { IndexStats } from '@mastra/core/vector';
|
|
8
|
+
import type { LogicalOperatorValueMap } from '@mastra/core/vector/filter';
|
|
7
9
|
import { MastraVector } from '@mastra/core/vector';
|
|
8
10
|
import type { OperatorSupport } from '@mastra/core/vector/filter';
|
|
11
|
+
import type { OperatorValueMap } from '@mastra/core/vector/filter';
|
|
9
12
|
import type { QueryResult } from '@mastra/core/vector';
|
|
10
13
|
import type { QueryVectorParams } from '@mastra/core/vector';
|
|
11
14
|
import type { UpdateVectorParams } from '@mastra/core/vector';
|
|
@@ -20,27 +23,37 @@ declare const CHROMA_PROMPT = "When querying Chroma, you can ONLY use the operat
|
|
|
20
23
|
export { CHROMA_PROMPT }
|
|
21
24
|
export { CHROMA_PROMPT as CHROMA_PROMPT_alias_1 }
|
|
22
25
|
|
|
26
|
+
declare type ChromaBlacklisted = BlacklistedRootOperators | '$nor' | '$not';
|
|
27
|
+
|
|
28
|
+
declare type ChromaDocumentBlacklisted = Exclude<ChromaBlacklisted, '$contains'>;
|
|
29
|
+
|
|
30
|
+
declare type ChromaDocumentOperatorValueMap = ChromaOperatorValueMap;
|
|
31
|
+
|
|
23
32
|
/**
|
|
24
33
|
* Translator for Chroma filter queries.
|
|
25
34
|
* Maintains MongoDB-compatible syntax while ensuring proper validation
|
|
26
35
|
* and normalization of values.
|
|
27
36
|
*/
|
|
28
|
-
export declare class ChromaFilterTranslator extends BaseFilterTranslator {
|
|
37
|
+
export declare class ChromaFilterTranslator extends BaseFilterTranslator<ChromaVectorFilter> {
|
|
29
38
|
protected getSupportedOperators(): OperatorSupport;
|
|
30
|
-
translate(filter?:
|
|
39
|
+
translate(filter?: ChromaVectorFilter): ChromaVectorFilter;
|
|
31
40
|
private translateNode;
|
|
32
41
|
private translateOperator;
|
|
33
42
|
}
|
|
34
43
|
|
|
35
|
-
declare
|
|
36
|
-
|
|
44
|
+
declare type ChromaLogicalOperatorValueMap = Omit<LogicalOperatorValueMap, '$nor' | '$not'>;
|
|
45
|
+
|
|
46
|
+
declare type ChromaOperatorValueMap = Omit<OperatorValueMap, '$exists' | '$elemMatch' | '$regex' | '$options'>;
|
|
47
|
+
|
|
48
|
+
declare interface ChromaQueryVectorParams extends QueryVectorParams<ChromaVectorFilter> {
|
|
49
|
+
documentFilter?: ChromaVectorDocumentFilter;
|
|
37
50
|
}
|
|
38
51
|
|
|
39
52
|
declare interface ChromaUpsertVectorParams extends UpsertVectorParams {
|
|
40
53
|
documents?: string[];
|
|
41
54
|
}
|
|
42
55
|
|
|
43
|
-
declare class ChromaVector extends MastraVector {
|
|
56
|
+
declare class ChromaVector extends MastraVector<ChromaVectorFilter> {
|
|
44
57
|
private client;
|
|
45
58
|
private collections;
|
|
46
59
|
constructor({ path, auth, }: {
|
|
@@ -55,7 +68,7 @@ declare class ChromaVector extends MastraVector {
|
|
|
55
68
|
upsert({ indexName, vectors, metadata, ids, documents }: ChromaUpsertVectorParams): Promise<string[]>;
|
|
56
69
|
private HnswSpaceMap;
|
|
57
70
|
createIndex({ indexName, dimension, metric }: CreateIndexParams): Promise<void>;
|
|
58
|
-
transformFilter(filter?:
|
|
71
|
+
transformFilter(filter?: ChromaVectorFilter): ChromaVectorFilter;
|
|
59
72
|
query({ indexName, queryVector, topK, filter, includeVector, documentFilter, }: ChromaQueryVectorParams): Promise<QueryResult[]>;
|
|
60
73
|
listIndexes(): Promise<string[]>;
|
|
61
74
|
/**
|
|
@@ -82,4 +95,8 @@ declare class ChromaVector extends MastraVector {
|
|
|
82
95
|
export { ChromaVector }
|
|
83
96
|
export { ChromaVector as ChromaVector_alias_1 }
|
|
84
97
|
|
|
98
|
+
export declare type ChromaVectorDocumentFilter = VectorFilter<keyof ChromaDocumentOperatorValueMap, ChromaDocumentOperatorValueMap, ChromaLogicalOperatorValueMap, ChromaDocumentBlacklisted>;
|
|
99
|
+
|
|
100
|
+
export declare type ChromaVectorFilter = VectorFilter<keyof ChromaOperatorValueMap, ChromaOperatorValueMap, ChromaLogicalOperatorValueMap, ChromaBlacklisted>;
|
|
101
|
+
|
|
85
102
|
export { }
|
|
@@ -1,11 +1,14 @@
|
|
|
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';
|
|
6
7
|
import type { IndexStats } from '@mastra/core/vector';
|
|
8
|
+
import type { LogicalOperatorValueMap } from '@mastra/core/vector/filter';
|
|
7
9
|
import { MastraVector } from '@mastra/core/vector';
|
|
8
10
|
import type { OperatorSupport } from '@mastra/core/vector/filter';
|
|
11
|
+
import type { OperatorValueMap } from '@mastra/core/vector/filter';
|
|
9
12
|
import type { QueryResult } from '@mastra/core/vector';
|
|
10
13
|
import type { QueryVectorParams } from '@mastra/core/vector';
|
|
11
14
|
import type { UpdateVectorParams } from '@mastra/core/vector';
|
|
@@ -20,27 +23,37 @@ declare const CHROMA_PROMPT = "When querying Chroma, you can ONLY use the operat
|
|
|
20
23
|
export { CHROMA_PROMPT }
|
|
21
24
|
export { CHROMA_PROMPT as CHROMA_PROMPT_alias_1 }
|
|
22
25
|
|
|
26
|
+
declare type ChromaBlacklisted = BlacklistedRootOperators | '$nor' | '$not';
|
|
27
|
+
|
|
28
|
+
declare type ChromaDocumentBlacklisted = Exclude<ChromaBlacklisted, '$contains'>;
|
|
29
|
+
|
|
30
|
+
declare type ChromaDocumentOperatorValueMap = ChromaOperatorValueMap;
|
|
31
|
+
|
|
23
32
|
/**
|
|
24
33
|
* Translator for Chroma filter queries.
|
|
25
34
|
* Maintains MongoDB-compatible syntax while ensuring proper validation
|
|
26
35
|
* and normalization of values.
|
|
27
36
|
*/
|
|
28
|
-
export declare class ChromaFilterTranslator extends BaseFilterTranslator {
|
|
37
|
+
export declare class ChromaFilterTranslator extends BaseFilterTranslator<ChromaVectorFilter> {
|
|
29
38
|
protected getSupportedOperators(): OperatorSupport;
|
|
30
|
-
translate(filter?:
|
|
39
|
+
translate(filter?: ChromaVectorFilter): ChromaVectorFilter;
|
|
31
40
|
private translateNode;
|
|
32
41
|
private translateOperator;
|
|
33
42
|
}
|
|
34
43
|
|
|
35
|
-
declare
|
|
36
|
-
|
|
44
|
+
declare type ChromaLogicalOperatorValueMap = Omit<LogicalOperatorValueMap, '$nor' | '$not'>;
|
|
45
|
+
|
|
46
|
+
declare type ChromaOperatorValueMap = Omit<OperatorValueMap, '$exists' | '$elemMatch' | '$regex' | '$options'>;
|
|
47
|
+
|
|
48
|
+
declare interface ChromaQueryVectorParams extends QueryVectorParams<ChromaVectorFilter> {
|
|
49
|
+
documentFilter?: ChromaVectorDocumentFilter;
|
|
37
50
|
}
|
|
38
51
|
|
|
39
52
|
declare interface ChromaUpsertVectorParams extends UpsertVectorParams {
|
|
40
53
|
documents?: string[];
|
|
41
54
|
}
|
|
42
55
|
|
|
43
|
-
declare class ChromaVector extends MastraVector {
|
|
56
|
+
declare class ChromaVector extends MastraVector<ChromaVectorFilter> {
|
|
44
57
|
private client;
|
|
45
58
|
private collections;
|
|
46
59
|
constructor({ path, auth, }: {
|
|
@@ -55,7 +68,7 @@ declare class ChromaVector extends MastraVector {
|
|
|
55
68
|
upsert({ indexName, vectors, metadata, ids, documents }: ChromaUpsertVectorParams): Promise<string[]>;
|
|
56
69
|
private HnswSpaceMap;
|
|
57
70
|
createIndex({ indexName, dimension, metric }: CreateIndexParams): Promise<void>;
|
|
58
|
-
transformFilter(filter?:
|
|
71
|
+
transformFilter(filter?: ChromaVectorFilter): ChromaVectorFilter;
|
|
59
72
|
query({ indexName, queryVector, topK, filter, includeVector, documentFilter, }: ChromaQueryVectorParams): Promise<QueryResult[]>;
|
|
60
73
|
listIndexes(): Promise<string[]>;
|
|
61
74
|
/**
|
|
@@ -82,4 +95,8 @@ declare class ChromaVector extends MastraVector {
|
|
|
82
95
|
export { ChromaVector }
|
|
83
96
|
export { ChromaVector as ChromaVector_alias_1 }
|
|
84
97
|
|
|
98
|
+
export declare type ChromaVectorDocumentFilter = VectorFilter<keyof ChromaDocumentOperatorValueMap, ChromaDocumentOperatorValueMap, ChromaLogicalOperatorValueMap, ChromaDocumentBlacklisted>;
|
|
99
|
+
|
|
100
|
+
export declare type ChromaVectorFilter = VectorFilter<keyof ChromaOperatorValueMap, ChromaOperatorValueMap, ChromaLogicalOperatorValueMap, ChromaBlacklisted>;
|
|
101
|
+
|
|
85
102
|
export { }
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mastra/chroma",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.11.0-alpha.2",
|
|
4
4
|
"description": "Chroma vector store provider for Mastra",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -25,15 +25,15 @@
|
|
|
25
25
|
"devDependencies": {
|
|
26
26
|
"@microsoft/api-extractor": "^7.52.8",
|
|
27
27
|
"@types/node": "^20.19.0",
|
|
28
|
-
"eslint": "^9.
|
|
28
|
+
"eslint": "^9.29.0",
|
|
29
29
|
"tsup": "^8.5.0",
|
|
30
30
|
"typescript": "^5.8.3",
|
|
31
31
|
"vitest": "^3.2.3",
|
|
32
32
|
"@internal/lint": "0.0.13",
|
|
33
|
-
"@mastra/core": "0.10.7-alpha.
|
|
33
|
+
"@mastra/core": "0.10.7-alpha.3"
|
|
34
34
|
},
|
|
35
35
|
"peerDependencies": {
|
|
36
|
-
"@mastra/core": ">=0.10.
|
|
36
|
+
"@mastra/core": ">=0.10.7-0 <0.11.0-0"
|
|
37
37
|
},
|
|
38
38
|
"scripts": {
|
|
39
39
|
"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 { ChromaVectorFilter } from './filter';
|
|
3
4
|
import { ChromaFilterTranslator } from './filter';
|
|
4
5
|
|
|
5
6
|
describe('ChromaFilterTranslator', () => {
|
|
@@ -13,17 +14,17 @@ describe('ChromaFilterTranslator', () => {
|
|
|
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('retains implicit equality', () => {
|
|
21
|
-
const filter = { field: 'value' };
|
|
22
|
+
const filter: ChromaVectorFilter = { field: 'value' };
|
|
22
23
|
expect(translator.translate(filter)).toEqual({ field: 'value' });
|
|
23
24
|
});
|
|
24
25
|
|
|
25
26
|
it('converts multiple top-level fields to $and', () => {
|
|
26
|
-
const filter = {
|
|
27
|
+
const filter: ChromaVectorFilter = {
|
|
27
28
|
field1: 'value1',
|
|
28
29
|
field2: 'value2',
|
|
29
30
|
};
|
|
@@ -33,7 +34,7 @@ describe('ChromaFilterTranslator', () => {
|
|
|
33
34
|
});
|
|
34
35
|
|
|
35
36
|
it('handles multiple operators on same field', () => {
|
|
36
|
-
const filter = {
|
|
37
|
+
const filter: ChromaVectorFilter = {
|
|
37
38
|
price: { $gt: 100, $lt: 200 },
|
|
38
39
|
quantity: { $gte: 10, $lte: 20 },
|
|
39
40
|
};
|
|
@@ -49,7 +50,7 @@ describe('ChromaFilterTranslator', () => {
|
|
|
49
50
|
|
|
50
51
|
it('normalizes date values', () => {
|
|
51
52
|
const date = new Date('2024-01-01');
|
|
52
|
-
const filter = { timestamp: { $gt: date } };
|
|
53
|
+
const filter: ChromaVectorFilter = { timestamp: { $gt: date } };
|
|
53
54
|
expect(translator.translate(filter)).toEqual({ timestamp: { $gt: date.toISOString() } });
|
|
54
55
|
});
|
|
55
56
|
});
|
|
@@ -57,7 +58,7 @@ describe('ChromaFilterTranslator', () => {
|
|
|
57
58
|
// Array Operations
|
|
58
59
|
describe('array operations', () => {
|
|
59
60
|
it('handles arrays as $in operator', () => {
|
|
60
|
-
const filter = { tags: ['tag1', 'tag2'] };
|
|
61
|
+
const filter: ChromaVectorFilter = { tags: ['tag1', 'tag2'] };
|
|
61
62
|
expect(translator.translate(filter)).toEqual({ tags: { $in: ['tag1', 'tag2'] } });
|
|
62
63
|
});
|
|
63
64
|
|
|
@@ -68,10 +69,14 @@ describe('ChromaFilterTranslator', () => {
|
|
|
68
69
|
|
|
69
70
|
it('handles arrays as direct values', () => {
|
|
70
71
|
// Direct array value should be converted to $in
|
|
71
|
-
|
|
72
|
+
const filter: ChromaVectorFilter = { field: ['value1', 'value2'] };
|
|
73
|
+
expect(translator.translate(filter)).toEqual({
|
|
74
|
+
field: { $in: ['value1', 'value2'] },
|
|
75
|
+
});
|
|
72
76
|
|
|
73
77
|
// Empty direct array
|
|
74
|
-
|
|
78
|
+
const filter2 = { field: [] };
|
|
79
|
+
expect(translator.translate(filter2)).toEqual({ field: { $in: [] } });
|
|
75
80
|
});
|
|
76
81
|
|
|
77
82
|
describe('$in operator variations', () => {
|
|
@@ -99,7 +104,7 @@ describe('ChromaFilterTranslator', () => {
|
|
|
99
104
|
// Logical Operators
|
|
100
105
|
describe('logical operators', () => {
|
|
101
106
|
it('handles logical operators', () => {
|
|
102
|
-
const filter = {
|
|
107
|
+
const filter: ChromaVectorFilter = {
|
|
103
108
|
$or: [{ status: { $eq: 'active' } }, { age: { $gt: 25 } }],
|
|
104
109
|
};
|
|
105
110
|
expect(translator.translate(filter)).toEqual({
|
|
@@ -108,7 +113,7 @@ describe('ChromaFilterTranslator', () => {
|
|
|
108
113
|
});
|
|
109
114
|
|
|
110
115
|
it('handles nested logical operators', () => {
|
|
111
|
-
const filter = {
|
|
116
|
+
const filter: ChromaVectorFilter = {
|
|
112
117
|
$and: [
|
|
113
118
|
{ status: { $eq: 'active' } },
|
|
114
119
|
{
|
|
@@ -142,7 +147,7 @@ describe('ChromaFilterTranslator', () => {
|
|
|
142
147
|
});
|
|
143
148
|
|
|
144
149
|
it('handles complex nested conditions', () => {
|
|
145
|
-
const filter = {
|
|
150
|
+
const filter: ChromaVectorFilter = {
|
|
146
151
|
$or: [
|
|
147
152
|
{ age: { $gt: 25 } },
|
|
148
153
|
{
|
|
@@ -176,7 +181,7 @@ describe('ChromaFilterTranslator', () => {
|
|
|
176
181
|
});
|
|
177
182
|
|
|
178
183
|
it('preserves empty objects as exact match conditions', () => {
|
|
179
|
-
const filter = {
|
|
184
|
+
const filter: ChromaVectorFilter = {
|
|
180
185
|
metadata: {},
|
|
181
186
|
'user.profile': {},
|
|
182
187
|
};
|
|
@@ -187,7 +192,7 @@ describe('ChromaFilterTranslator', () => {
|
|
|
187
192
|
});
|
|
188
193
|
|
|
189
194
|
it('handles empty objects in logical operators', () => {
|
|
190
|
-
const filter = {
|
|
195
|
+
const filter: ChromaVectorFilter = {
|
|
191
196
|
$or: [{}, { status: 'active' }],
|
|
192
197
|
};
|
|
193
198
|
|
|
@@ -211,7 +216,7 @@ describe('ChromaFilterTranslator', () => {
|
|
|
211
216
|
});
|
|
212
217
|
|
|
213
218
|
it('handles empty objects in comparison operators', () => {
|
|
214
|
-
const filter = {
|
|
219
|
+
const filter: ChromaVectorFilter = {
|
|
215
220
|
metadata: { $eq: {} },
|
|
216
221
|
};
|
|
217
222
|
|
|
@@ -221,7 +226,7 @@ describe('ChromaFilterTranslator', () => {
|
|
|
221
226
|
});
|
|
222
227
|
|
|
223
228
|
it('handles empty objects in array operators', () => {
|
|
224
|
-
const filter = {
|
|
229
|
+
const filter: ChromaVectorFilter = {
|
|
225
230
|
tags: { $in: [{}] },
|
|
226
231
|
};
|
|
227
232
|
|
|
@@ -335,7 +340,7 @@ describe('ChromaFilterTranslator', () => {
|
|
|
335
340
|
});
|
|
336
341
|
|
|
337
342
|
it('throws error for unsupported logical operators', () => {
|
|
338
|
-
const invalidFilters = [
|
|
343
|
+
const invalidFilters: any = [
|
|
339
344
|
{
|
|
340
345
|
$not: { field: 'value' },
|
|
341
346
|
},
|
|
@@ -374,7 +379,7 @@ describe('ChromaFilterTranslator', () => {
|
|
|
374
379
|
});
|
|
375
380
|
|
|
376
381
|
it('throws error for unsupported operators', () => {
|
|
377
|
-
const unsupportedFilters = [
|
|
382
|
+
const unsupportedFilters: any = [
|
|
378
383
|
{ field: { $regex: 'pattern' } },
|
|
379
384
|
{ field: { $contains: 'value' } },
|
|
380
385
|
{ field: { $exists: true } },
|
|
@@ -395,7 +400,7 @@ describe('ChromaFilterTranslator', () => {
|
|
|
395
400
|
expect(() => translator.translate(filter)).toThrow();
|
|
396
401
|
});
|
|
397
402
|
it('throws error for non-logical operators at top level', () => {
|
|
398
|
-
const invalidFilters = [{ $gt: 100 }, { $in: ['value1', 'value2'] }, { $eq: true }];
|
|
403
|
+
const invalidFilters: any = [{ $gt: 100 }, { $in: ['value1', 'value2'] }, { $eq: true }];
|
|
399
404
|
|
|
400
405
|
invalidFilters.forEach(filter => {
|
|
401
406
|
expect(() => translator.translate(filter)).toThrow(/Invalid top-level operator/);
|
package/src/vector/filter.ts
CHANGED
|
@@ -1,12 +1,43 @@
|
|
|
1
1
|
import { BaseFilterTranslator } from '@mastra/core/vector/filter';
|
|
2
|
-
import type {
|
|
2
|
+
import type {
|
|
3
|
+
VectorFilter,
|
|
4
|
+
OperatorSupport,
|
|
5
|
+
QueryOperator,
|
|
6
|
+
OperatorValueMap,
|
|
7
|
+
LogicalOperatorValueMap,
|
|
8
|
+
BlacklistedRootOperators,
|
|
9
|
+
} from '@mastra/core/vector/filter';
|
|
10
|
+
|
|
11
|
+
type ChromaOperatorValueMap = Omit<OperatorValueMap, '$exists' | '$elemMatch' | '$regex' | '$options'>;
|
|
12
|
+
|
|
13
|
+
type ChromaLogicalOperatorValueMap = Omit<LogicalOperatorValueMap, '$nor' | '$not'>;
|
|
14
|
+
|
|
15
|
+
type ChromaBlacklisted = BlacklistedRootOperators | '$nor' | '$not';
|
|
16
|
+
|
|
17
|
+
export type ChromaVectorFilter = VectorFilter<
|
|
18
|
+
keyof ChromaOperatorValueMap,
|
|
19
|
+
ChromaOperatorValueMap,
|
|
20
|
+
ChromaLogicalOperatorValueMap,
|
|
21
|
+
ChromaBlacklisted
|
|
22
|
+
>;
|
|
23
|
+
|
|
24
|
+
type ChromaDocumentOperatorValueMap = ChromaOperatorValueMap;
|
|
25
|
+
|
|
26
|
+
type ChromaDocumentBlacklisted = Exclude<ChromaBlacklisted, '$contains'>;
|
|
27
|
+
|
|
28
|
+
export type ChromaVectorDocumentFilter = VectorFilter<
|
|
29
|
+
keyof ChromaDocumentOperatorValueMap,
|
|
30
|
+
ChromaDocumentOperatorValueMap,
|
|
31
|
+
ChromaLogicalOperatorValueMap,
|
|
32
|
+
ChromaDocumentBlacklisted
|
|
33
|
+
>;
|
|
3
34
|
|
|
4
35
|
/**
|
|
5
36
|
* Translator for Chroma filter queries.
|
|
6
37
|
* Maintains MongoDB-compatible syntax while ensuring proper validation
|
|
7
38
|
* and normalization of values.
|
|
8
39
|
*/
|
|
9
|
-
export class ChromaFilterTranslator extends BaseFilterTranslator {
|
|
40
|
+
export class ChromaFilterTranslator extends BaseFilterTranslator<ChromaVectorFilter> {
|
|
10
41
|
protected override getSupportedOperators(): OperatorSupport {
|
|
11
42
|
return {
|
|
12
43
|
...BaseFilterTranslator.DEFAULT_OPERATORS,
|
|
@@ -18,14 +49,14 @@ export class ChromaFilterTranslator extends BaseFilterTranslator {
|
|
|
18
49
|
};
|
|
19
50
|
}
|
|
20
51
|
|
|
21
|
-
translate(filter?:
|
|
52
|
+
translate(filter?: ChromaVectorFilter): ChromaVectorFilter {
|
|
22
53
|
if (this.isEmpty(filter)) return filter;
|
|
23
54
|
this.validateFilter(filter);
|
|
24
55
|
|
|
25
56
|
return this.translateNode(filter);
|
|
26
57
|
}
|
|
27
58
|
|
|
28
|
-
private translateNode(node:
|
|
59
|
+
private translateNode(node: ChromaVectorFilter, currentPath: string = ''): any {
|
|
29
60
|
// Handle primitive values and arrays
|
|
30
61
|
if (this.isRegex(node)) {
|
|
31
62
|
throw new Error('Regex is not supported in Chroma');
|
package/src/vector/index.test.ts
CHANGED
|
@@ -378,7 +378,7 @@ describe('ChromaVector Integration Tests', () => {
|
|
|
378
378
|
indexName: testIndexName,
|
|
379
379
|
queryVector: [1, 0, 0],
|
|
380
380
|
filter: {
|
|
381
|
-
tags: { $in: null },
|
|
381
|
+
tags: { $in: null } as any,
|
|
382
382
|
},
|
|
383
383
|
}),
|
|
384
384
|
).rejects.toThrow();
|
|
@@ -479,9 +479,9 @@ describe('ChromaVector Integration Tests', () => {
|
|
|
479
479
|
indexName: testIndexName,
|
|
480
480
|
queryVector: [1, 0, 0],
|
|
481
481
|
filter: {
|
|
482
|
-
field1: { $in: 'not-array' },
|
|
483
|
-
field2: { $exists: 'not-boolean' },
|
|
484
|
-
field3: { $gt: 'not-number' },
|
|
482
|
+
field1: { $in: 'not-array' } as any,
|
|
483
|
+
field2: { $exists: 'not-boolean' } as any,
|
|
484
|
+
field3: { $gt: 'not-number' } as any,
|
|
485
485
|
},
|
|
486
486
|
}),
|
|
487
487
|
).rejects.toThrow();
|
package/src/vector/index.ts
CHANGED
|
@@ -11,20 +11,20 @@ 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 { ChromaClient } from 'chromadb';
|
|
16
15
|
import type { UpdateRecordsParams, Collection } from 'chromadb';
|
|
16
|
+
import type { ChromaVectorDocumentFilter, ChromaVectorFilter } from './filter';
|
|
17
17
|
import { ChromaFilterTranslator } from './filter';
|
|
18
18
|
|
|
19
19
|
interface ChromaUpsertVectorParams extends UpsertVectorParams {
|
|
20
20
|
documents?: string[];
|
|
21
21
|
}
|
|
22
22
|
|
|
23
|
-
interface ChromaQueryVectorParams extends QueryVectorParams {
|
|
24
|
-
documentFilter?:
|
|
23
|
+
interface ChromaQueryVectorParams extends QueryVectorParams<ChromaVectorFilter> {
|
|
24
|
+
documentFilter?: ChromaVectorDocumentFilter;
|
|
25
25
|
}
|
|
26
26
|
|
|
27
|
-
export class ChromaVector extends MastraVector {
|
|
27
|
+
export class ChromaVector extends MastraVector<ChromaVectorFilter> {
|
|
28
28
|
private client: ChromaClient;
|
|
29
29
|
private collections: Map<string, any>;
|
|
30
30
|
|
|
@@ -156,7 +156,7 @@ export class ChromaVector extends MastraVector {
|
|
|
156
156
|
}
|
|
157
157
|
}
|
|
158
158
|
|
|
159
|
-
transformFilter(filter?:
|
|
159
|
+
transformFilter(filter?: ChromaVectorFilter) {
|
|
160
160
|
const translator = new ChromaFilterTranslator();
|
|
161
161
|
return translator.translate(filter);
|
|
162
162
|
}
|