@mastra/rag 0.10.2-alpha.0 → 0.10.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 +7 -7
- package/CHANGELOG.md +35 -0
- package/dist/_tsup-dts-rollup.d.cts +63 -1
- package/dist/_tsup-dts-rollup.d.ts +63 -1
- package/dist/index.cjs +58 -6
- package/dist/index.js +58 -6
- package/package.json +3 -3
- package/src/tools/README.md +153 -0
- package/src/tools/types.ts +53 -0
- package/src/tools/vector-query-database-config.test.ts +190 -0
- package/src/tools/vector-query.ts +5 -2
- package/src/utils/vector-search.ts +73 -4
package/.turbo/turbo-build.log
CHANGED
|
@@ -1,23 +1,23 @@
|
|
|
1
1
|
|
|
2
|
-
> @mastra/rag@0.10.2-alpha.
|
|
2
|
+
> @mastra/rag@0.10.2-alpha.1 build /home/runner/work/mastra/mastra/packages/rag
|
|
3
3
|
> tsup src/index.ts --format esm,cjs --experimental-dts --clean --treeshake=smallest --splitting
|
|
4
4
|
|
|
5
5
|
[34mCLI[39m Building entry: src/index.ts
|
|
6
6
|
[34mCLI[39m Using tsconfig: tsconfig.json
|
|
7
7
|
[34mCLI[39m tsup v8.4.0
|
|
8
8
|
[34mTSC[39m Build start
|
|
9
|
-
[32mTSC[39m ⚡️ Build success in
|
|
9
|
+
[32mTSC[39m ⚡️ Build success in 12829ms
|
|
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/packages/rag/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/packages/rag/dist/_tsup-dts-rollup.d.cts[39m
|
|
16
|
-
[32mDTS[39m ⚡️ Build success in
|
|
16
|
+
[32mDTS[39m ⚡️ Build success in 13312ms
|
|
17
17
|
[34mCLI[39m Cleaning output folder
|
|
18
18
|
[34mESM[39m Build start
|
|
19
19
|
[34mCJS[39m Build start
|
|
20
|
-
[32mESM[39m [1mdist/index.js [22m[
|
|
21
|
-
[32mESM[39m ⚡️ Build success in
|
|
22
|
-
[32mCJS[39m [1mdist/index.cjs [22m[
|
|
23
|
-
[32mCJS[39m ⚡️ Build success in
|
|
20
|
+
[32mESM[39m [1mdist/index.js [22m[32m241.64 KB[39m
|
|
21
|
+
[32mESM[39m ⚡️ Build success in 4913ms
|
|
22
|
+
[32mCJS[39m [1mdist/index.cjs [22m[32m243.35 KB[39m
|
|
23
|
+
[32mCJS[39m ⚡️ Build success in 4909ms
|
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,40 @@
|
|
|
1
1
|
# @mastra/rag
|
|
2
2
|
|
|
3
|
+
## 0.10.2
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- a60d630: Adds runtime and initialization DB specific configuration to createVectorQueryTool to account for different configuration between db providers.
|
|
8
|
+
- f0d559f: Fix peerdeps for alpha channel
|
|
9
|
+
- Updated dependencies [ee77e78]
|
|
10
|
+
- Updated dependencies [592a2db]
|
|
11
|
+
- Updated dependencies [e5dc18d]
|
|
12
|
+
- Updated dependencies [ab5adbe]
|
|
13
|
+
- Updated dependencies [1e8bb40]
|
|
14
|
+
- Updated dependencies [1b5fc55]
|
|
15
|
+
- Updated dependencies [195c428]
|
|
16
|
+
- Updated dependencies [f73e11b]
|
|
17
|
+
- Updated dependencies [37643b8]
|
|
18
|
+
- Updated dependencies [99fd6cf]
|
|
19
|
+
- Updated dependencies [c5bf1ce]
|
|
20
|
+
- Updated dependencies [add596e]
|
|
21
|
+
- Updated dependencies [8dc94d8]
|
|
22
|
+
- Updated dependencies [ecebbeb]
|
|
23
|
+
- Updated dependencies [79d5145]
|
|
24
|
+
- Updated dependencies [12b7002]
|
|
25
|
+
- Updated dependencies [2901125]
|
|
26
|
+
- @mastra/core@0.10.2
|
|
27
|
+
|
|
28
|
+
## 0.10.2-alpha.1
|
|
29
|
+
|
|
30
|
+
### Patch Changes
|
|
31
|
+
|
|
32
|
+
- a60d630: Adds runtime and initialization DB specific configuration to createVectorQueryTool to account for different configuration between db providers.
|
|
33
|
+
- Updated dependencies [1b5fc55]
|
|
34
|
+
- Updated dependencies [add596e]
|
|
35
|
+
- Updated dependencies [ecebbeb]
|
|
36
|
+
- @mastra/core@0.10.2-alpha.5
|
|
37
|
+
|
|
3
38
|
## 0.10.2-alpha.0
|
|
4
39
|
|
|
5
40
|
### Patch Changes
|
|
@@ -83,6 +83,10 @@ declare const baseSchema: {
|
|
|
83
83
|
export { baseSchema }
|
|
84
84
|
export { baseSchema as baseSchema_alias_1 }
|
|
85
85
|
|
|
86
|
+
declare type BaseWhere = {
|
|
87
|
+
[key: string]: LiteralValue | OperatorExpression;
|
|
88
|
+
};
|
|
89
|
+
|
|
86
90
|
export declare class CharacterTransformer extends TextTransformer {
|
|
87
91
|
protected separator: string;
|
|
88
92
|
protected isSeparatorRegex: boolean;
|
|
@@ -115,6 +119,11 @@ declare const CHROMA_PROMPT = "When querying Chroma, you can ONLY use the operat
|
|
|
115
119
|
export { CHROMA_PROMPT }
|
|
116
120
|
export { CHROMA_PROMPT as CHROMA_PROMPT_alias_1 }
|
|
117
121
|
|
|
122
|
+
export declare interface ChromaConfig {
|
|
123
|
+
where?: Where;
|
|
124
|
+
whereDocument?: WhereDocument;
|
|
125
|
+
}
|
|
126
|
+
|
|
118
127
|
declare type ChunkOptions = {
|
|
119
128
|
headers?: [string, string][];
|
|
120
129
|
returnEachLine?: boolean;
|
|
@@ -226,6 +235,13 @@ export { createVectorQueryTool }
|
|
|
226
235
|
export { createVectorQueryTool as createVectorQueryTool_alias_1 }
|
|
227
236
|
export { createVectorQueryTool as createVectorQueryTool_alias_2 }
|
|
228
237
|
|
|
238
|
+
export declare type DatabaseConfig = {
|
|
239
|
+
pinecone?: PineconeConfig;
|
|
240
|
+
pgvector?: PgVectorConfig;
|
|
241
|
+
chroma?: ChromaConfig;
|
|
242
|
+
[key: string]: any;
|
|
243
|
+
};
|
|
244
|
+
|
|
229
245
|
/**
|
|
230
246
|
* Default options for GraphRAG
|
|
231
247
|
* @default
|
|
@@ -440,6 +456,8 @@ export declare class HTMLSectionTransformer {
|
|
|
440
456
|
transformDocuments(documents: Document[]): Document[];
|
|
441
457
|
}
|
|
442
458
|
|
|
459
|
+
declare type InclusionOperator = '$in' | '$nin';
|
|
460
|
+
|
|
443
461
|
declare type KeywordExtractArgs = {
|
|
444
462
|
llm?: MastraLanguageModel;
|
|
445
463
|
keywords?: number;
|
|
@@ -539,6 +557,18 @@ declare const LIBSQL_PROMPT = "When querying LibSQL Vector, you can ONLY use the
|
|
|
539
557
|
export { LIBSQL_PROMPT }
|
|
540
558
|
export { LIBSQL_PROMPT as LIBSQL_PROMPT_alias_1 }
|
|
541
559
|
|
|
560
|
+
declare type ListLiteralValue = LiteralValue[];
|
|
561
|
+
|
|
562
|
+
declare type LiteralNumber = number;
|
|
563
|
+
|
|
564
|
+
declare type LiteralValue = string | number | boolean;
|
|
565
|
+
|
|
566
|
+
declare type LogicalOperator = '$and' | '$or';
|
|
567
|
+
|
|
568
|
+
declare type LogicalWhere = {
|
|
569
|
+
[key in LogicalOperator]?: Where[];
|
|
570
|
+
};
|
|
571
|
+
|
|
542
572
|
export declare class MarkdownHeaderTransformer {
|
|
543
573
|
private headersToSplitOn;
|
|
544
574
|
private returnEachLine;
|
|
@@ -637,6 +667,10 @@ declare enum ObjectType {
|
|
|
637
667
|
export { ObjectType }
|
|
638
668
|
export { ObjectType as ObjectType_alias_1 }
|
|
639
669
|
|
|
670
|
+
declare type OperatorExpression = {
|
|
671
|
+
[key in WhereOperator | InclusionOperator | LogicalOperator]?: LiteralValue | ListLiteralValue;
|
|
672
|
+
};
|
|
673
|
+
|
|
640
674
|
declare const outputSchema: z.ZodObject<{
|
|
641
675
|
relevantContext: z.ZodAny;
|
|
642
676
|
sources: z.ZodArray<z.ZodObject<{
|
|
@@ -685,11 +719,25 @@ declare const PGVECTOR_PROMPT = "When querying PG Vector, you can ONLY use the o
|
|
|
685
719
|
export { PGVECTOR_PROMPT }
|
|
686
720
|
export { PGVECTOR_PROMPT as PGVECTOR_PROMPT_alias_1 }
|
|
687
721
|
|
|
722
|
+
export declare interface PgVectorConfig {
|
|
723
|
+
minScore?: number;
|
|
724
|
+
ef?: number;
|
|
725
|
+
probes?: number;
|
|
726
|
+
}
|
|
727
|
+
|
|
688
728
|
/** @deprecated Import from @mastra/pinecone instead */
|
|
689
729
|
declare const PINECONE_PROMPT = "When querying Pinecone, you can ONLY use the operators listed below. Any other operators will be rejected.\nImportant: Don't explain how to construct the filter - use the specified operators and fields to search the content and return relevant results.\nIf a user tries to give an explicit operator that is not supported, reject the filter entirely and let them know that the operator is not supported.\n\nBasic Comparison Operators:\n- $eq: Exact match (default when using field: value)\n Example: { \"category\": \"electronics\" }\n- $ne: Not equal\n Example: { \"category\": { \"$ne\": \"electronics\" } }\n- $gt: Greater than\n Example: { \"price\": { \"$gt\": 100 } }\n- $gte: Greater than or equal\n Example: { \"price\": { \"$gte\": 100 } }\n- $lt: Less than\n Example: { \"price\": { \"$lt\": 100 } }\n- $lte: Less than or equal\n Example: { \"price\": { \"$lte\": 100 } }\n\nArray Operators:\n- $in: Match any value in array\n Example: { \"category\": { \"$in\": [\"electronics\", \"books\"] } }\n- $nin: Does not match any value in array\n Example: { \"category\": { \"$nin\": [\"electronics\", \"books\"] } }\n- $all: Match all values in array\n Example: { \"tags\": { \"$all\": [\"premium\", \"sale\"] } }\n\nLogical Operators:\n- $and: Logical AND (can be implicit or explicit)\n Implicit Example: { \"price\": { \"$gt\": 100 }, \"category\": \"electronics\" }\n Explicit Example: { \"$and\": [{ \"price\": { \"$gt\": 100 } }, { \"category\": \"electronics\" }] }\n- $or: Logical OR\n Example: { \"$or\": [{ \"price\": { \"$lt\": 50 } }, { \"category\": \"books\" }] }\n\nElement Operators:\n- $exists: Check if field exists\n Example: { \"rating\": { \"$exists\": true } }\n\nRestrictions:\n- Regex patterns are not supported\n- Only $and and $or logical operators are supported at the top level\n- Empty arrays in $in/$nin will return no results\n- A non-empty array is required for $all operator\n- Nested fields are supported using dot notation\n- Multiple conditions on the same field are supported with both implicit and explicit $and\n- At least one key-value pair is required in filter object\n- Empty objects and undefined values are treated as no filter\n- Invalid types in comparison operators will throw errors\n- All non-logical operators must be used within a field condition\n Valid: { \"field\": { \"$gt\": 100 } }\n Valid: { \"$and\": [...] }\n Invalid: { \"$gt\": 100 }\n- Logical operators must contain field conditions, not direct operators\n Valid: { \"$and\": [{ \"field\": { \"$gt\": 100 } }] }\n Invalid: { \"$and\": [{ \"$gt\": 100 }] }\n- Logical operators ($and, $or):\n - Can only be used at top level or nested within other logical operators\n - Can not be used on a field level, or be nested inside a field\n - Can not be used inside an operator\n - Valid: { \"$and\": [{ \"field\": { \"$gt\": 100 } }] }\n - Valid: { \"$or\": [{ \"$and\": [{ \"field\": { \"$gt\": 100 } }] }] }\n - Invalid: { \"field\": { \"$and\": [{ \"$gt\": 100 }] } }\n - Invalid: { \"field\": { \"$or\": [{ \"$gt\": 100 }] } }\n - Invalid: { \"field\": { \"$gt\": { \"$and\": [{...}] } } }\nExample Complex Query:\n{\n \"$and\": [\n { \"category\": { \"$in\": [\"electronics\", \"computers\"] } },\n { \"price\": { \"$gte\": 100, \"$lte\": 1000 } },\n { \"tags\": { \"$all\": [\"premium\", \"sale\"] } },\n { \"rating\": { \"$exists\": true, \"$gt\": 4 } },\n { \"$or\": [\n { \"stock\": { \"$gt\": 0 } },\n { \"preorder\": true }\n ]}\n ]\n}";
|
|
690
730
|
export { PINECONE_PROMPT }
|
|
691
731
|
export { PINECONE_PROMPT as PINECONE_PROMPT_alias_1 }
|
|
692
732
|
|
|
733
|
+
export declare interface PineconeConfig {
|
|
734
|
+
namespace?: string;
|
|
735
|
+
sparseVector?: {
|
|
736
|
+
indices: number[];
|
|
737
|
+
values: number[];
|
|
738
|
+
};
|
|
739
|
+
}
|
|
740
|
+
|
|
693
741
|
declare class PromptTemplate<const TemplatesVar extends readonly string[] = string[]> extends BasePromptTemplate<TemplatesVar> {
|
|
694
742
|
#private;
|
|
695
743
|
constructor(options: PromptTemplateOptions<TemplatesVar>);
|
|
@@ -1156,7 +1204,7 @@ declare const VECTORIZE_PROMPT = "When querying Vectorize, you can ONLY use the
|
|
|
1156
1204
|
export { VECTORIZE_PROMPT }
|
|
1157
1205
|
export { VECTORIZE_PROMPT as VECTORIZE_PROMPT_alias_1 }
|
|
1158
1206
|
|
|
1159
|
-
declare const vectorQuerySearch: ({ indexName, vectorStore, queryText, model, queryFilter, topK, includeVectors, maxRetries, }: VectorQuerySearchParams) => Promise<VectorQuerySearchResult>;
|
|
1207
|
+
declare const vectorQuerySearch: ({ indexName, vectorStore, queryText, model, queryFilter, topK, includeVectors, maxRetries, databaseConfig, }: VectorQuerySearchParams) => Promise<VectorQuerySearchResult>;
|
|
1160
1208
|
export { vectorQuerySearch }
|
|
1161
1209
|
export { vectorQuerySearch as vectorQuerySearch_alias_1 }
|
|
1162
1210
|
|
|
@@ -1169,6 +1217,8 @@ declare interface VectorQuerySearchParams {
|
|
|
1169
1217
|
topK: number;
|
|
1170
1218
|
includeVectors?: boolean;
|
|
1171
1219
|
maxRetries?: number;
|
|
1220
|
+
/** Database-specific configuration options */
|
|
1221
|
+
databaseConfig?: DatabaseConfig;
|
|
1172
1222
|
}
|
|
1173
1223
|
|
|
1174
1224
|
declare interface VectorQuerySearchResult {
|
|
@@ -1186,6 +1236,8 @@ export declare type VectorQueryToolOptions = {
|
|
|
1186
1236
|
includeVectors?: boolean;
|
|
1187
1237
|
includeSources?: boolean;
|
|
1188
1238
|
reranker?: RerankConfig;
|
|
1239
|
+
/** Database-specific configuration options */
|
|
1240
|
+
databaseConfig?: DatabaseConfig;
|
|
1189
1241
|
};
|
|
1190
1242
|
|
|
1191
1243
|
declare type WeightConfig = {
|
|
@@ -1194,4 +1246,14 @@ declare type WeightConfig = {
|
|
|
1194
1246
|
position?: number;
|
|
1195
1247
|
};
|
|
1196
1248
|
|
|
1249
|
+
declare type Where = BaseWhere | LogicalWhere;
|
|
1250
|
+
|
|
1251
|
+
declare type WhereDocument = {
|
|
1252
|
+
[key in WhereDocumentOperator]?: LiteralValue | LiteralNumber | WhereDocument[];
|
|
1253
|
+
};
|
|
1254
|
+
|
|
1255
|
+
declare type WhereDocumentOperator = '$contains' | '$not_contains' | LogicalOperator;
|
|
1256
|
+
|
|
1257
|
+
declare type WhereOperator = '$gt' | '$gte' | '$lt' | '$lte' | '$ne' | '$eq';
|
|
1258
|
+
|
|
1197
1259
|
export { }
|
|
@@ -83,6 +83,10 @@ declare const baseSchema: {
|
|
|
83
83
|
export { baseSchema }
|
|
84
84
|
export { baseSchema as baseSchema_alias_1 }
|
|
85
85
|
|
|
86
|
+
declare type BaseWhere = {
|
|
87
|
+
[key: string]: LiteralValue | OperatorExpression;
|
|
88
|
+
};
|
|
89
|
+
|
|
86
90
|
export declare class CharacterTransformer extends TextTransformer {
|
|
87
91
|
protected separator: string;
|
|
88
92
|
protected isSeparatorRegex: boolean;
|
|
@@ -115,6 +119,11 @@ declare const CHROMA_PROMPT = "When querying Chroma, you can ONLY use the operat
|
|
|
115
119
|
export { CHROMA_PROMPT }
|
|
116
120
|
export { CHROMA_PROMPT as CHROMA_PROMPT_alias_1 }
|
|
117
121
|
|
|
122
|
+
export declare interface ChromaConfig {
|
|
123
|
+
where?: Where;
|
|
124
|
+
whereDocument?: WhereDocument;
|
|
125
|
+
}
|
|
126
|
+
|
|
118
127
|
declare type ChunkOptions = {
|
|
119
128
|
headers?: [string, string][];
|
|
120
129
|
returnEachLine?: boolean;
|
|
@@ -226,6 +235,13 @@ export { createVectorQueryTool }
|
|
|
226
235
|
export { createVectorQueryTool as createVectorQueryTool_alias_1 }
|
|
227
236
|
export { createVectorQueryTool as createVectorQueryTool_alias_2 }
|
|
228
237
|
|
|
238
|
+
export declare type DatabaseConfig = {
|
|
239
|
+
pinecone?: PineconeConfig;
|
|
240
|
+
pgvector?: PgVectorConfig;
|
|
241
|
+
chroma?: ChromaConfig;
|
|
242
|
+
[key: string]: any;
|
|
243
|
+
};
|
|
244
|
+
|
|
229
245
|
/**
|
|
230
246
|
* Default options for GraphRAG
|
|
231
247
|
* @default
|
|
@@ -440,6 +456,8 @@ export declare class HTMLSectionTransformer {
|
|
|
440
456
|
transformDocuments(documents: Document[]): Document[];
|
|
441
457
|
}
|
|
442
458
|
|
|
459
|
+
declare type InclusionOperator = '$in' | '$nin';
|
|
460
|
+
|
|
443
461
|
declare type KeywordExtractArgs = {
|
|
444
462
|
llm?: MastraLanguageModel;
|
|
445
463
|
keywords?: number;
|
|
@@ -539,6 +557,18 @@ declare const LIBSQL_PROMPT = "When querying LibSQL Vector, you can ONLY use the
|
|
|
539
557
|
export { LIBSQL_PROMPT }
|
|
540
558
|
export { LIBSQL_PROMPT as LIBSQL_PROMPT_alias_1 }
|
|
541
559
|
|
|
560
|
+
declare type ListLiteralValue = LiteralValue[];
|
|
561
|
+
|
|
562
|
+
declare type LiteralNumber = number;
|
|
563
|
+
|
|
564
|
+
declare type LiteralValue = string | number | boolean;
|
|
565
|
+
|
|
566
|
+
declare type LogicalOperator = '$and' | '$or';
|
|
567
|
+
|
|
568
|
+
declare type LogicalWhere = {
|
|
569
|
+
[key in LogicalOperator]?: Where[];
|
|
570
|
+
};
|
|
571
|
+
|
|
542
572
|
export declare class MarkdownHeaderTransformer {
|
|
543
573
|
private headersToSplitOn;
|
|
544
574
|
private returnEachLine;
|
|
@@ -637,6 +667,10 @@ declare enum ObjectType {
|
|
|
637
667
|
export { ObjectType }
|
|
638
668
|
export { ObjectType as ObjectType_alias_1 }
|
|
639
669
|
|
|
670
|
+
declare type OperatorExpression = {
|
|
671
|
+
[key in WhereOperator | InclusionOperator | LogicalOperator]?: LiteralValue | ListLiteralValue;
|
|
672
|
+
};
|
|
673
|
+
|
|
640
674
|
declare const outputSchema: z.ZodObject<{
|
|
641
675
|
relevantContext: z.ZodAny;
|
|
642
676
|
sources: z.ZodArray<z.ZodObject<{
|
|
@@ -685,11 +719,25 @@ declare const PGVECTOR_PROMPT = "When querying PG Vector, you can ONLY use the o
|
|
|
685
719
|
export { PGVECTOR_PROMPT }
|
|
686
720
|
export { PGVECTOR_PROMPT as PGVECTOR_PROMPT_alias_1 }
|
|
687
721
|
|
|
722
|
+
export declare interface PgVectorConfig {
|
|
723
|
+
minScore?: number;
|
|
724
|
+
ef?: number;
|
|
725
|
+
probes?: number;
|
|
726
|
+
}
|
|
727
|
+
|
|
688
728
|
/** @deprecated Import from @mastra/pinecone instead */
|
|
689
729
|
declare const PINECONE_PROMPT = "When querying Pinecone, you can ONLY use the operators listed below. Any other operators will be rejected.\nImportant: Don't explain how to construct the filter - use the specified operators and fields to search the content and return relevant results.\nIf a user tries to give an explicit operator that is not supported, reject the filter entirely and let them know that the operator is not supported.\n\nBasic Comparison Operators:\n- $eq: Exact match (default when using field: value)\n Example: { \"category\": \"electronics\" }\n- $ne: Not equal\n Example: { \"category\": { \"$ne\": \"electronics\" } }\n- $gt: Greater than\n Example: { \"price\": { \"$gt\": 100 } }\n- $gte: Greater than or equal\n Example: { \"price\": { \"$gte\": 100 } }\n- $lt: Less than\n Example: { \"price\": { \"$lt\": 100 } }\n- $lte: Less than or equal\n Example: { \"price\": { \"$lte\": 100 } }\n\nArray Operators:\n- $in: Match any value in array\n Example: { \"category\": { \"$in\": [\"electronics\", \"books\"] } }\n- $nin: Does not match any value in array\n Example: { \"category\": { \"$nin\": [\"electronics\", \"books\"] } }\n- $all: Match all values in array\n Example: { \"tags\": { \"$all\": [\"premium\", \"sale\"] } }\n\nLogical Operators:\n- $and: Logical AND (can be implicit or explicit)\n Implicit Example: { \"price\": { \"$gt\": 100 }, \"category\": \"electronics\" }\n Explicit Example: { \"$and\": [{ \"price\": { \"$gt\": 100 } }, { \"category\": \"electronics\" }] }\n- $or: Logical OR\n Example: { \"$or\": [{ \"price\": { \"$lt\": 50 } }, { \"category\": \"books\" }] }\n\nElement Operators:\n- $exists: Check if field exists\n Example: { \"rating\": { \"$exists\": true } }\n\nRestrictions:\n- Regex patterns are not supported\n- Only $and and $or logical operators are supported at the top level\n- Empty arrays in $in/$nin will return no results\n- A non-empty array is required for $all operator\n- Nested fields are supported using dot notation\n- Multiple conditions on the same field are supported with both implicit and explicit $and\n- At least one key-value pair is required in filter object\n- Empty objects and undefined values are treated as no filter\n- Invalid types in comparison operators will throw errors\n- All non-logical operators must be used within a field condition\n Valid: { \"field\": { \"$gt\": 100 } }\n Valid: { \"$and\": [...] }\n Invalid: { \"$gt\": 100 }\n- Logical operators must contain field conditions, not direct operators\n Valid: { \"$and\": [{ \"field\": { \"$gt\": 100 } }] }\n Invalid: { \"$and\": [{ \"$gt\": 100 }] }\n- Logical operators ($and, $or):\n - Can only be used at top level or nested within other logical operators\n - Can not be used on a field level, or be nested inside a field\n - Can not be used inside an operator\n - Valid: { \"$and\": [{ \"field\": { \"$gt\": 100 } }] }\n - Valid: { \"$or\": [{ \"$and\": [{ \"field\": { \"$gt\": 100 } }] }] }\n - Invalid: { \"field\": { \"$and\": [{ \"$gt\": 100 }] } }\n - Invalid: { \"field\": { \"$or\": [{ \"$gt\": 100 }] } }\n - Invalid: { \"field\": { \"$gt\": { \"$and\": [{...}] } } }\nExample Complex Query:\n{\n \"$and\": [\n { \"category\": { \"$in\": [\"electronics\", \"computers\"] } },\n { \"price\": { \"$gte\": 100, \"$lte\": 1000 } },\n { \"tags\": { \"$all\": [\"premium\", \"sale\"] } },\n { \"rating\": { \"$exists\": true, \"$gt\": 4 } },\n { \"$or\": [\n { \"stock\": { \"$gt\": 0 } },\n { \"preorder\": true }\n ]}\n ]\n}";
|
|
690
730
|
export { PINECONE_PROMPT }
|
|
691
731
|
export { PINECONE_PROMPT as PINECONE_PROMPT_alias_1 }
|
|
692
732
|
|
|
733
|
+
export declare interface PineconeConfig {
|
|
734
|
+
namespace?: string;
|
|
735
|
+
sparseVector?: {
|
|
736
|
+
indices: number[];
|
|
737
|
+
values: number[];
|
|
738
|
+
};
|
|
739
|
+
}
|
|
740
|
+
|
|
693
741
|
declare class PromptTemplate<const TemplatesVar extends readonly string[] = string[]> extends BasePromptTemplate<TemplatesVar> {
|
|
694
742
|
#private;
|
|
695
743
|
constructor(options: PromptTemplateOptions<TemplatesVar>);
|
|
@@ -1156,7 +1204,7 @@ declare const VECTORIZE_PROMPT = "When querying Vectorize, you can ONLY use the
|
|
|
1156
1204
|
export { VECTORIZE_PROMPT }
|
|
1157
1205
|
export { VECTORIZE_PROMPT as VECTORIZE_PROMPT_alias_1 }
|
|
1158
1206
|
|
|
1159
|
-
declare const vectorQuerySearch: ({ indexName, vectorStore, queryText, model, queryFilter, topK, includeVectors, maxRetries, }: VectorQuerySearchParams) => Promise<VectorQuerySearchResult>;
|
|
1207
|
+
declare const vectorQuerySearch: ({ indexName, vectorStore, queryText, model, queryFilter, topK, includeVectors, maxRetries, databaseConfig, }: VectorQuerySearchParams) => Promise<VectorQuerySearchResult>;
|
|
1160
1208
|
export { vectorQuerySearch }
|
|
1161
1209
|
export { vectorQuerySearch as vectorQuerySearch_alias_1 }
|
|
1162
1210
|
|
|
@@ -1169,6 +1217,8 @@ declare interface VectorQuerySearchParams {
|
|
|
1169
1217
|
topK: number;
|
|
1170
1218
|
includeVectors?: boolean;
|
|
1171
1219
|
maxRetries?: number;
|
|
1220
|
+
/** Database-specific configuration options */
|
|
1221
|
+
databaseConfig?: DatabaseConfig;
|
|
1172
1222
|
}
|
|
1173
1223
|
|
|
1174
1224
|
declare interface VectorQuerySearchResult {
|
|
@@ -1186,6 +1236,8 @@ export declare type VectorQueryToolOptions = {
|
|
|
1186
1236
|
includeVectors?: boolean;
|
|
1187
1237
|
includeSources?: boolean;
|
|
1188
1238
|
reranker?: RerankConfig;
|
|
1239
|
+
/** Database-specific configuration options */
|
|
1240
|
+
databaseConfig?: DatabaseConfig;
|
|
1189
1241
|
};
|
|
1190
1242
|
|
|
1191
1243
|
declare type WeightConfig = {
|
|
@@ -1194,4 +1246,14 @@ declare type WeightConfig = {
|
|
|
1194
1246
|
position?: number;
|
|
1195
1247
|
};
|
|
1196
1248
|
|
|
1249
|
+
declare type Where = BaseWhere | LogicalWhere;
|
|
1250
|
+
|
|
1251
|
+
declare type WhereDocument = {
|
|
1252
|
+
[key in WhereDocumentOperator]?: LiteralValue | LiteralNumber | WhereDocument[];
|
|
1253
|
+
};
|
|
1254
|
+
|
|
1255
|
+
declare type WhereDocumentOperator = '$contains' | '$not_contains' | LogicalOperator;
|
|
1256
|
+
|
|
1257
|
+
declare type WhereOperator = '$gt' | '$gte' | '$lt' | '$lte' | '$ne' | '$eq';
|
|
1258
|
+
|
|
1197
1259
|
export { }
|
package/dist/index.cjs
CHANGED
|
@@ -6217,6 +6217,13 @@ var createDocumentChunkerTool = ({
|
|
|
6217
6217
|
}
|
|
6218
6218
|
});
|
|
6219
6219
|
};
|
|
6220
|
+
var DatabaseType = /* @__PURE__ */ ((DatabaseType2) => {
|
|
6221
|
+
DatabaseType2["Pinecone"] = "pinecone";
|
|
6222
|
+
DatabaseType2["PgVector"] = "pgvector";
|
|
6223
|
+
DatabaseType2["Chroma"] = "chroma";
|
|
6224
|
+
return DatabaseType2;
|
|
6225
|
+
})(DatabaseType || {});
|
|
6226
|
+
var DATABASE_TYPE_MAP = Object.keys(DatabaseType);
|
|
6220
6227
|
var vectorQuerySearch = async ({
|
|
6221
6228
|
indexName,
|
|
6222
6229
|
vectorStore,
|
|
@@ -6225,22 +6232,65 @@ var vectorQuerySearch = async ({
|
|
|
6225
6232
|
queryFilter,
|
|
6226
6233
|
topK,
|
|
6227
6234
|
includeVectors = false,
|
|
6228
|
-
maxRetries = 2
|
|
6235
|
+
maxRetries = 2,
|
|
6236
|
+
databaseConfig = {}
|
|
6229
6237
|
}) => {
|
|
6230
6238
|
const { embedding } = await ai.embed({
|
|
6231
6239
|
value: queryText,
|
|
6232
6240
|
model,
|
|
6233
6241
|
maxRetries
|
|
6234
6242
|
});
|
|
6235
|
-
const
|
|
6243
|
+
const queryParams = {
|
|
6236
6244
|
indexName,
|
|
6237
6245
|
queryVector: embedding,
|
|
6238
6246
|
topK,
|
|
6239
6247
|
filter: queryFilter,
|
|
6240
6248
|
includeVector: includeVectors
|
|
6241
|
-
}
|
|
6249
|
+
};
|
|
6250
|
+
const results = await vectorStore.query({ ...queryParams, ...databaseSpecificParams(databaseConfig) });
|
|
6242
6251
|
return { results, queryEmbedding: embedding };
|
|
6243
6252
|
};
|
|
6253
|
+
var databaseSpecificParams = (databaseConfig) => {
|
|
6254
|
+
const databaseSpecificParams2 = {};
|
|
6255
|
+
if (databaseConfig) {
|
|
6256
|
+
if (databaseConfig.pinecone) {
|
|
6257
|
+
if (databaseConfig.pinecone.namespace) {
|
|
6258
|
+
databaseSpecificParams2.namespace = databaseConfig.pinecone.namespace;
|
|
6259
|
+
}
|
|
6260
|
+
if (databaseConfig.pinecone.sparseVector) {
|
|
6261
|
+
databaseSpecificParams2.sparseVector = databaseConfig.pinecone.sparseVector;
|
|
6262
|
+
}
|
|
6263
|
+
}
|
|
6264
|
+
if (databaseConfig.pgvector) {
|
|
6265
|
+
if (databaseConfig.pgvector.minScore !== void 0) {
|
|
6266
|
+
databaseSpecificParams2.minScore = databaseConfig.pgvector.minScore;
|
|
6267
|
+
}
|
|
6268
|
+
if (databaseConfig.pgvector.ef !== void 0) {
|
|
6269
|
+
databaseSpecificParams2.ef = databaseConfig.pgvector.ef;
|
|
6270
|
+
}
|
|
6271
|
+
if (databaseConfig.pgvector.probes !== void 0) {
|
|
6272
|
+
databaseSpecificParams2.probes = databaseConfig.pgvector.probes;
|
|
6273
|
+
}
|
|
6274
|
+
}
|
|
6275
|
+
if (databaseConfig.chroma) {
|
|
6276
|
+
if (databaseConfig.chroma.where) {
|
|
6277
|
+
databaseSpecificParams2.where = databaseConfig.chroma.where;
|
|
6278
|
+
}
|
|
6279
|
+
if (databaseConfig.chroma.whereDocument) {
|
|
6280
|
+
databaseSpecificParams2.whereDocument = databaseConfig.chroma.whereDocument;
|
|
6281
|
+
}
|
|
6282
|
+
}
|
|
6283
|
+
Object.keys(databaseConfig).forEach((dbName) => {
|
|
6284
|
+
if (!DATABASE_TYPE_MAP.includes(dbName)) {
|
|
6285
|
+
const config = databaseConfig[dbName];
|
|
6286
|
+
if (config && typeof config === "object") {
|
|
6287
|
+
Object.assign(databaseSpecificParams2, config);
|
|
6288
|
+
}
|
|
6289
|
+
}
|
|
6290
|
+
});
|
|
6291
|
+
}
|
|
6292
|
+
return databaseSpecificParams2;
|
|
6293
|
+
};
|
|
6244
6294
|
|
|
6245
6295
|
// src/utils/default-settings.ts
|
|
6246
6296
|
var defaultVectorQueryDescription = () => `Access the knowledge base to find information needed to answer user questions.`;
|
|
@@ -6481,6 +6531,7 @@ var createVectorQueryTool = (options) => {
|
|
|
6481
6531
|
const includeVectors = runtimeContext.get("includeVectors") ?? options.includeVectors ?? false;
|
|
6482
6532
|
const includeSources = runtimeContext.get("includeSources") ?? options.includeSources ?? true;
|
|
6483
6533
|
const reranker = runtimeContext.get("reranker") ?? options.reranker;
|
|
6534
|
+
const databaseConfig = runtimeContext.get("databaseConfig") ?? options.databaseConfig;
|
|
6484
6535
|
if (!indexName) throw new Error(`indexName is required, got: ${indexName}`);
|
|
6485
6536
|
if (!vectorStoreName) throw new Error(`vectorStoreName is required, got: ${vectorStoreName}`);
|
|
6486
6537
|
const topK = runtimeContext.get("topK") ?? context.topK ?? 10;
|
|
@@ -6494,7 +6545,7 @@ var createVectorQueryTool = (options) => {
|
|
|
6494
6545
|
);
|
|
6495
6546
|
}
|
|
6496
6547
|
if (logger) {
|
|
6497
|
-
logger.debug("[VectorQueryTool] execute called with:", { queryText, topK, filter });
|
|
6548
|
+
logger.debug("[VectorQueryTool] execute called with:", { queryText, topK, filter, databaseConfig });
|
|
6498
6549
|
}
|
|
6499
6550
|
try {
|
|
6500
6551
|
const topKValue = typeof topK === "number" && !isNaN(topK) ? topK : typeof topK === "string" && !isNaN(Number(topK)) ? Number(topK) : 10;
|
|
@@ -6519,7 +6570,7 @@ var createVectorQueryTool = (options) => {
|
|
|
6519
6570
|
})();
|
|
6520
6571
|
}
|
|
6521
6572
|
if (logger) {
|
|
6522
|
-
logger.debug("Prepared vector query parameters", { queryText, topK: topKValue, queryFilter });
|
|
6573
|
+
logger.debug("Prepared vector query parameters", { queryText, topK: topKValue, queryFilter, databaseConfig });
|
|
6523
6574
|
}
|
|
6524
6575
|
const { results } = await vectorQuerySearch({
|
|
6525
6576
|
indexName,
|
|
@@ -6528,7 +6579,8 @@ var createVectorQueryTool = (options) => {
|
|
|
6528
6579
|
model,
|
|
6529
6580
|
queryFilter: Object.keys(queryFilter || {}).length > 0 ? queryFilter : void 0,
|
|
6530
6581
|
topK: topKValue,
|
|
6531
|
-
includeVectors
|
|
6582
|
+
includeVectors,
|
|
6583
|
+
databaseConfig
|
|
6532
6584
|
});
|
|
6533
6585
|
if (logger) {
|
|
6534
6586
|
logger.debug("vectorQuerySearch returned results", { count: results.length });
|
package/dist/index.js
CHANGED
|
@@ -6215,6 +6215,13 @@ var createDocumentChunkerTool = ({
|
|
|
6215
6215
|
}
|
|
6216
6216
|
});
|
|
6217
6217
|
};
|
|
6218
|
+
var DatabaseType = /* @__PURE__ */ ((DatabaseType2) => {
|
|
6219
|
+
DatabaseType2["Pinecone"] = "pinecone";
|
|
6220
|
+
DatabaseType2["PgVector"] = "pgvector";
|
|
6221
|
+
DatabaseType2["Chroma"] = "chroma";
|
|
6222
|
+
return DatabaseType2;
|
|
6223
|
+
})(DatabaseType || {});
|
|
6224
|
+
var DATABASE_TYPE_MAP = Object.keys(DatabaseType);
|
|
6218
6225
|
var vectorQuerySearch = async ({
|
|
6219
6226
|
indexName,
|
|
6220
6227
|
vectorStore,
|
|
@@ -6223,22 +6230,65 @@ var vectorQuerySearch = async ({
|
|
|
6223
6230
|
queryFilter,
|
|
6224
6231
|
topK,
|
|
6225
6232
|
includeVectors = false,
|
|
6226
|
-
maxRetries = 2
|
|
6233
|
+
maxRetries = 2,
|
|
6234
|
+
databaseConfig = {}
|
|
6227
6235
|
}) => {
|
|
6228
6236
|
const { embedding } = await embed({
|
|
6229
6237
|
value: queryText,
|
|
6230
6238
|
model,
|
|
6231
6239
|
maxRetries
|
|
6232
6240
|
});
|
|
6233
|
-
const
|
|
6241
|
+
const queryParams = {
|
|
6234
6242
|
indexName,
|
|
6235
6243
|
queryVector: embedding,
|
|
6236
6244
|
topK,
|
|
6237
6245
|
filter: queryFilter,
|
|
6238
6246
|
includeVector: includeVectors
|
|
6239
|
-
}
|
|
6247
|
+
};
|
|
6248
|
+
const results = await vectorStore.query({ ...queryParams, ...databaseSpecificParams(databaseConfig) });
|
|
6240
6249
|
return { results, queryEmbedding: embedding };
|
|
6241
6250
|
};
|
|
6251
|
+
var databaseSpecificParams = (databaseConfig) => {
|
|
6252
|
+
const databaseSpecificParams2 = {};
|
|
6253
|
+
if (databaseConfig) {
|
|
6254
|
+
if (databaseConfig.pinecone) {
|
|
6255
|
+
if (databaseConfig.pinecone.namespace) {
|
|
6256
|
+
databaseSpecificParams2.namespace = databaseConfig.pinecone.namespace;
|
|
6257
|
+
}
|
|
6258
|
+
if (databaseConfig.pinecone.sparseVector) {
|
|
6259
|
+
databaseSpecificParams2.sparseVector = databaseConfig.pinecone.sparseVector;
|
|
6260
|
+
}
|
|
6261
|
+
}
|
|
6262
|
+
if (databaseConfig.pgvector) {
|
|
6263
|
+
if (databaseConfig.pgvector.minScore !== void 0) {
|
|
6264
|
+
databaseSpecificParams2.minScore = databaseConfig.pgvector.minScore;
|
|
6265
|
+
}
|
|
6266
|
+
if (databaseConfig.pgvector.ef !== void 0) {
|
|
6267
|
+
databaseSpecificParams2.ef = databaseConfig.pgvector.ef;
|
|
6268
|
+
}
|
|
6269
|
+
if (databaseConfig.pgvector.probes !== void 0) {
|
|
6270
|
+
databaseSpecificParams2.probes = databaseConfig.pgvector.probes;
|
|
6271
|
+
}
|
|
6272
|
+
}
|
|
6273
|
+
if (databaseConfig.chroma) {
|
|
6274
|
+
if (databaseConfig.chroma.where) {
|
|
6275
|
+
databaseSpecificParams2.where = databaseConfig.chroma.where;
|
|
6276
|
+
}
|
|
6277
|
+
if (databaseConfig.chroma.whereDocument) {
|
|
6278
|
+
databaseSpecificParams2.whereDocument = databaseConfig.chroma.whereDocument;
|
|
6279
|
+
}
|
|
6280
|
+
}
|
|
6281
|
+
Object.keys(databaseConfig).forEach((dbName) => {
|
|
6282
|
+
if (!DATABASE_TYPE_MAP.includes(dbName)) {
|
|
6283
|
+
const config = databaseConfig[dbName];
|
|
6284
|
+
if (config && typeof config === "object") {
|
|
6285
|
+
Object.assign(databaseSpecificParams2, config);
|
|
6286
|
+
}
|
|
6287
|
+
}
|
|
6288
|
+
});
|
|
6289
|
+
}
|
|
6290
|
+
return databaseSpecificParams2;
|
|
6291
|
+
};
|
|
6242
6292
|
|
|
6243
6293
|
// src/utils/default-settings.ts
|
|
6244
6294
|
var defaultVectorQueryDescription = () => `Access the knowledge base to find information needed to answer user questions.`;
|
|
@@ -6479,6 +6529,7 @@ var createVectorQueryTool = (options) => {
|
|
|
6479
6529
|
const includeVectors = runtimeContext.get("includeVectors") ?? options.includeVectors ?? false;
|
|
6480
6530
|
const includeSources = runtimeContext.get("includeSources") ?? options.includeSources ?? true;
|
|
6481
6531
|
const reranker = runtimeContext.get("reranker") ?? options.reranker;
|
|
6532
|
+
const databaseConfig = runtimeContext.get("databaseConfig") ?? options.databaseConfig;
|
|
6482
6533
|
if (!indexName) throw new Error(`indexName is required, got: ${indexName}`);
|
|
6483
6534
|
if (!vectorStoreName) throw new Error(`vectorStoreName is required, got: ${vectorStoreName}`);
|
|
6484
6535
|
const topK = runtimeContext.get("topK") ?? context.topK ?? 10;
|
|
@@ -6492,7 +6543,7 @@ var createVectorQueryTool = (options) => {
|
|
|
6492
6543
|
);
|
|
6493
6544
|
}
|
|
6494
6545
|
if (logger) {
|
|
6495
|
-
logger.debug("[VectorQueryTool] execute called with:", { queryText, topK, filter });
|
|
6546
|
+
logger.debug("[VectorQueryTool] execute called with:", { queryText, topK, filter, databaseConfig });
|
|
6496
6547
|
}
|
|
6497
6548
|
try {
|
|
6498
6549
|
const topKValue = typeof topK === "number" && !isNaN(topK) ? topK : typeof topK === "string" && !isNaN(Number(topK)) ? Number(topK) : 10;
|
|
@@ -6517,7 +6568,7 @@ var createVectorQueryTool = (options) => {
|
|
|
6517
6568
|
})();
|
|
6518
6569
|
}
|
|
6519
6570
|
if (logger) {
|
|
6520
|
-
logger.debug("Prepared vector query parameters", { queryText, topK: topKValue, queryFilter });
|
|
6571
|
+
logger.debug("Prepared vector query parameters", { queryText, topK: topKValue, queryFilter, databaseConfig });
|
|
6521
6572
|
}
|
|
6522
6573
|
const { results } = await vectorQuerySearch({
|
|
6523
6574
|
indexName,
|
|
@@ -6526,7 +6577,8 @@ var createVectorQueryTool = (options) => {
|
|
|
6526
6577
|
model,
|
|
6527
6578
|
queryFilter: Object.keys(queryFilter || {}).length > 0 ? queryFilter : void 0,
|
|
6528
6579
|
topK: topKValue,
|
|
6529
|
-
includeVectors
|
|
6580
|
+
includeVectors,
|
|
6581
|
+
databaseConfig
|
|
6530
6582
|
});
|
|
6531
6583
|
if (logger) {
|
|
6532
6584
|
logger.debug("vectorQuerySearch returned results", { count: results.length });
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mastra/rag",
|
|
3
|
-
"version": "0.10.2
|
|
3
|
+
"version": "0.10.2",
|
|
4
4
|
"description": "",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -44,8 +44,8 @@
|
|
|
44
44
|
"tsup": "^8.4.0",
|
|
45
45
|
"typescript": "^5.8.2",
|
|
46
46
|
"vitest": "^3.1.2",
|
|
47
|
-
"@
|
|
48
|
-
"@
|
|
47
|
+
"@mastra/core": "0.10.2",
|
|
48
|
+
"@internal/lint": "0.0.8"
|
|
49
49
|
},
|
|
50
50
|
"keywords": [
|
|
51
51
|
"rag",
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
# Vector Query Tool with Database-Specific Configurations
|
|
2
|
+
|
|
3
|
+
The `createVectorQueryTool` function now supports database-specific configurations to handle unique properties and optimizations for different vector databases.
|
|
4
|
+
|
|
5
|
+
## Database Configuration Types
|
|
6
|
+
|
|
7
|
+
### Pinecone Configuration
|
|
8
|
+
|
|
9
|
+
```typescript
|
|
10
|
+
import { createVectorQueryTool } from '@mastra/rag/tools';
|
|
11
|
+
|
|
12
|
+
const pineconeVectorTool = createVectorQueryTool({
|
|
13
|
+
id: 'pinecone-search',
|
|
14
|
+
indexName: 'my-index',
|
|
15
|
+
vectorStoreName: 'pinecone',
|
|
16
|
+
model: embedModel,
|
|
17
|
+
databaseConfig: {
|
|
18
|
+
pinecone: {
|
|
19
|
+
namespace: 'my-namespace', // Pinecone namespace
|
|
20
|
+
sparseVector: {
|
|
21
|
+
// For hybrid search
|
|
22
|
+
indices: [0, 1, 2],
|
|
23
|
+
values: [0.1, 0.2, 0.3],
|
|
24
|
+
},
|
|
25
|
+
},
|
|
26
|
+
},
|
|
27
|
+
});
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
### pgVector Configuration
|
|
31
|
+
|
|
32
|
+
```typescript
|
|
33
|
+
const pgVectorTool = createVectorQueryTool({
|
|
34
|
+
id: 'pgvector-search',
|
|
35
|
+
indexName: 'my-index',
|
|
36
|
+
vectorStoreName: 'postgres',
|
|
37
|
+
model: embedModel,
|
|
38
|
+
databaseConfig: {
|
|
39
|
+
pgvector: {
|
|
40
|
+
minScore: 0.7, // Minimum similarity score
|
|
41
|
+
ef: 200, // HNSW search parameter
|
|
42
|
+
probes: 10, // IVFFlat probe parameter
|
|
43
|
+
},
|
|
44
|
+
},
|
|
45
|
+
});
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
### Chroma Configuration
|
|
49
|
+
|
|
50
|
+
```typescript
|
|
51
|
+
const chromaTool = createVectorQueryTool({
|
|
52
|
+
id: 'chroma-search',
|
|
53
|
+
indexName: 'my-index',
|
|
54
|
+
vectorStoreName: 'chroma',
|
|
55
|
+
model: embedModel,
|
|
56
|
+
databaseConfig: {
|
|
57
|
+
chroma: {
|
|
58
|
+
where: {
|
|
59
|
+
// Metadata filtering
|
|
60
|
+
category: 'documents',
|
|
61
|
+
},
|
|
62
|
+
whereDocument: {
|
|
63
|
+
// Document content filtering
|
|
64
|
+
$contains: 'important',
|
|
65
|
+
},
|
|
66
|
+
},
|
|
67
|
+
},
|
|
68
|
+
});
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
## Runtime Configuration Override
|
|
72
|
+
|
|
73
|
+
You can also override database configurations at runtime using the runtime context:
|
|
74
|
+
|
|
75
|
+
```typescript
|
|
76
|
+
import { RuntimeContext } from '@mastra/core/runtime-context';
|
|
77
|
+
|
|
78
|
+
const runtimeContext = new RuntimeContext();
|
|
79
|
+
|
|
80
|
+
// Override Pinecone namespace at runtime
|
|
81
|
+
runtimeContext.set('databaseConfig', {
|
|
82
|
+
pinecone: {
|
|
83
|
+
namespace: 'runtime-namespace',
|
|
84
|
+
},
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
await vectorTool.execute({
|
|
88
|
+
context: { queryText: 'search query' },
|
|
89
|
+
mastra,
|
|
90
|
+
runtimeContext,
|
|
91
|
+
});
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
## Extensibility for New Databases
|
|
95
|
+
|
|
96
|
+
The system is designed to be extensible. For new vector databases, you can:
|
|
97
|
+
|
|
98
|
+
1. Add configuration types:
|
|
99
|
+
|
|
100
|
+
```typescript
|
|
101
|
+
export interface NewDatabaseConfig {
|
|
102
|
+
customParam1?: string;
|
|
103
|
+
customParam2?: number;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
export type DatabaseConfig = {
|
|
107
|
+
pinecone?: PineconeConfig;
|
|
108
|
+
pgvector?: PgVectorConfig;
|
|
109
|
+
chroma?: ChromaConfig;
|
|
110
|
+
newdatabase?: NewDatabaseConfig; // Add your config here
|
|
111
|
+
[key: string]: any;
|
|
112
|
+
};
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
2. The configuration will be automatically passed through to the vector store's query method.
|
|
116
|
+
|
|
117
|
+
## Type Safety
|
|
118
|
+
|
|
119
|
+
All database configurations are fully typed, providing IntelliSense and compile-time checking:
|
|
120
|
+
|
|
121
|
+
```typescript
|
|
122
|
+
const config: DatabaseConfig = {
|
|
123
|
+
pinecone: {
|
|
124
|
+
namespace: 'valid-namespace',
|
|
125
|
+
sparseVector: {
|
|
126
|
+
indices: [1, 2, 3],
|
|
127
|
+
values: [0.1, 0.2, 0.3],
|
|
128
|
+
},
|
|
129
|
+
},
|
|
130
|
+
pgvector: {
|
|
131
|
+
minScore: 0.8,
|
|
132
|
+
ef: 100,
|
|
133
|
+
probes: 5,
|
|
134
|
+
},
|
|
135
|
+
};
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
## Migration Guide
|
|
139
|
+
|
|
140
|
+
Existing code will continue to work without changes. To add database-specific configurations:
|
|
141
|
+
|
|
142
|
+
```diff
|
|
143
|
+
const vectorTool = createVectorQueryTool({
|
|
144
|
+
indexName: 'my-index',
|
|
145
|
+
vectorStoreName: 'pinecone',
|
|
146
|
+
model: embedModel,
|
|
147
|
+
+ databaseConfig: {
|
|
148
|
+
+ pinecone: {
|
|
149
|
+
+ namespace: 'my-namespace'
|
|
150
|
+
+ }
|
|
151
|
+
+ }
|
|
152
|
+
});
|
|
153
|
+
```
|
package/src/tools/types.ts
CHANGED
|
@@ -1,6 +1,57 @@
|
|
|
1
1
|
import type { EmbeddingModel } from 'ai';
|
|
2
2
|
import type { RerankConfig } from '../rerank';
|
|
3
3
|
|
|
4
|
+
export interface PineconeConfig {
|
|
5
|
+
namespace?: string;
|
|
6
|
+
sparseVector?: {
|
|
7
|
+
indices: number[];
|
|
8
|
+
values: number[];
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export interface PgVectorConfig {
|
|
13
|
+
minScore?: number;
|
|
14
|
+
ef?: number; // HNSW search parameter
|
|
15
|
+
probes?: number; // IVFFlat probe parameter
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
// Chroma types
|
|
19
|
+
type LiteralValue = string | number | boolean;
|
|
20
|
+
type ListLiteralValue = LiteralValue[];
|
|
21
|
+
type LiteralNumber = number;
|
|
22
|
+
type LogicalOperator = '$and' | '$or';
|
|
23
|
+
type InclusionOperator = '$in' | '$nin';
|
|
24
|
+
type WhereOperator = '$gt' | '$gte' | '$lt' | '$lte' | '$ne' | '$eq';
|
|
25
|
+
type OperatorExpression = {
|
|
26
|
+
[key in WhereOperator | InclusionOperator | LogicalOperator]?: LiteralValue | ListLiteralValue;
|
|
27
|
+
};
|
|
28
|
+
type BaseWhere = {
|
|
29
|
+
[key: string]: LiteralValue | OperatorExpression;
|
|
30
|
+
};
|
|
31
|
+
type LogicalWhere = {
|
|
32
|
+
[key in LogicalOperator]?: Where[];
|
|
33
|
+
};
|
|
34
|
+
type Where = BaseWhere | LogicalWhere;
|
|
35
|
+
type WhereDocumentOperator = '$contains' | '$not_contains' | LogicalOperator;
|
|
36
|
+
type WhereDocument = {
|
|
37
|
+
[key in WhereDocumentOperator]?: LiteralValue | LiteralNumber | WhereDocument[];
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
export interface ChromaConfig {
|
|
41
|
+
// Add Chroma-specific configs here if needed
|
|
42
|
+
where?: Where;
|
|
43
|
+
whereDocument?: WhereDocument;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// Union type for all database-specific configs
|
|
47
|
+
export type DatabaseConfig = {
|
|
48
|
+
pinecone?: PineconeConfig;
|
|
49
|
+
pgvector?: PgVectorConfig;
|
|
50
|
+
chroma?: ChromaConfig;
|
|
51
|
+
// Add other database configs as needed
|
|
52
|
+
[key: string]: any; // Allow for future database extensions
|
|
53
|
+
};
|
|
54
|
+
|
|
4
55
|
export type VectorQueryToolOptions = {
|
|
5
56
|
id?: string;
|
|
6
57
|
description?: string;
|
|
@@ -11,6 +62,8 @@ export type VectorQueryToolOptions = {
|
|
|
11
62
|
includeVectors?: boolean;
|
|
12
63
|
includeSources?: boolean;
|
|
13
64
|
reranker?: RerankConfig;
|
|
65
|
+
/** Database-specific configuration options */
|
|
66
|
+
databaseConfig?: DatabaseConfig;
|
|
14
67
|
};
|
|
15
68
|
|
|
16
69
|
export type GraphRagToolOptions = {
|
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
import { RuntimeContext } from '@mastra/core/runtime-context';
|
|
2
|
+
import { describe, it, expect, vi, beforeEach } from 'vitest';
|
|
3
|
+
import { vectorQuerySearch } from '../utils';
|
|
4
|
+
import type { DatabaseConfig } from './types';
|
|
5
|
+
import { createVectorQueryTool } from './vector-query';
|
|
6
|
+
|
|
7
|
+
vi.mock('../utils', async importOriginal => {
|
|
8
|
+
const actual: any = await importOriginal();
|
|
9
|
+
return {
|
|
10
|
+
...actual,
|
|
11
|
+
vectorQuerySearch: vi.fn().mockResolvedValue({
|
|
12
|
+
results: [{ metadata: { text: 'test result' }, vector: [1, 2, 3] }],
|
|
13
|
+
}),
|
|
14
|
+
};
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
describe('createVectorQueryTool with database-specific configurations', () => {
|
|
18
|
+
const mockModel = { name: 'test-model' } as any;
|
|
19
|
+
const mockMastra = {
|
|
20
|
+
getVector: vi.fn(() => ({})),
|
|
21
|
+
getLogger: vi.fn(() => ({
|
|
22
|
+
debug: vi.fn(),
|
|
23
|
+
warn: vi.fn(),
|
|
24
|
+
error: vi.fn(),
|
|
25
|
+
})),
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
beforeEach(() => {
|
|
29
|
+
vi.clearAllMocks();
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
it('should pass Pinecone configuration to vectorQuerySearch', async () => {
|
|
33
|
+
const databaseConfig: DatabaseConfig = {
|
|
34
|
+
pinecone: {
|
|
35
|
+
namespace: 'test-namespace',
|
|
36
|
+
sparseVector: {
|
|
37
|
+
indices: [0, 1, 2],
|
|
38
|
+
values: [0.1, 0.2, 0.3],
|
|
39
|
+
},
|
|
40
|
+
},
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
const tool = createVectorQueryTool({
|
|
44
|
+
vectorStoreName: 'pinecone',
|
|
45
|
+
indexName: 'testIndex',
|
|
46
|
+
model: mockModel,
|
|
47
|
+
databaseConfig,
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
const runtimeContext = new RuntimeContext();
|
|
51
|
+
|
|
52
|
+
await tool.execute({
|
|
53
|
+
context: { queryText: 'test query', topK: 5 },
|
|
54
|
+
mastra: mockMastra as any,
|
|
55
|
+
runtimeContext,
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
expect(vectorQuerySearch).toHaveBeenCalledWith(
|
|
59
|
+
expect.objectContaining({
|
|
60
|
+
databaseConfig,
|
|
61
|
+
}),
|
|
62
|
+
);
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
it('should pass pgVector configuration to vectorQuerySearch', async () => {
|
|
66
|
+
const databaseConfig: DatabaseConfig = {
|
|
67
|
+
pgvector: {
|
|
68
|
+
minScore: 0.7,
|
|
69
|
+
ef: 200,
|
|
70
|
+
probes: 10,
|
|
71
|
+
},
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
const tool = createVectorQueryTool({
|
|
75
|
+
vectorStoreName: 'postgres',
|
|
76
|
+
indexName: 'testIndex',
|
|
77
|
+
model: mockModel,
|
|
78
|
+
databaseConfig,
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
const runtimeContext = new RuntimeContext();
|
|
82
|
+
|
|
83
|
+
await tool.execute({
|
|
84
|
+
context: { queryText: 'test query', topK: 5 },
|
|
85
|
+
mastra: mockMastra as any,
|
|
86
|
+
runtimeContext,
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
expect(vectorQuerySearch).toHaveBeenCalledWith(
|
|
90
|
+
expect.objectContaining({
|
|
91
|
+
databaseConfig,
|
|
92
|
+
}),
|
|
93
|
+
);
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
it('should allow runtime context to override database configuration', async () => {
|
|
97
|
+
const initialConfig: DatabaseConfig = {
|
|
98
|
+
pinecone: {
|
|
99
|
+
namespace: 'initial-namespace',
|
|
100
|
+
},
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
const runtimeConfig: DatabaseConfig = {
|
|
104
|
+
pinecone: {
|
|
105
|
+
namespace: 'runtime-namespace',
|
|
106
|
+
},
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
const tool = createVectorQueryTool({
|
|
110
|
+
vectorStoreName: 'pinecone',
|
|
111
|
+
indexName: 'testIndex',
|
|
112
|
+
model: mockModel,
|
|
113
|
+
databaseConfig: initialConfig,
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
const runtimeContext = new RuntimeContext();
|
|
117
|
+
runtimeContext.set('databaseConfig', runtimeConfig);
|
|
118
|
+
|
|
119
|
+
await tool.execute({
|
|
120
|
+
context: { queryText: 'test query', topK: 5 },
|
|
121
|
+
mastra: mockMastra as any,
|
|
122
|
+
runtimeContext,
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
expect(vectorQuerySearch).toHaveBeenCalledWith(
|
|
126
|
+
expect.objectContaining({
|
|
127
|
+
databaseConfig: runtimeConfig, // Should use runtime config, not initial
|
|
128
|
+
}),
|
|
129
|
+
);
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
it('should work without database configuration (backward compatibility)', async () => {
|
|
133
|
+
const tool = createVectorQueryTool({
|
|
134
|
+
vectorStoreName: 'testStore',
|
|
135
|
+
indexName: 'testIndex',
|
|
136
|
+
model: mockModel,
|
|
137
|
+
// No databaseConfig provided
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
const runtimeContext = new RuntimeContext();
|
|
141
|
+
|
|
142
|
+
await tool.execute({
|
|
143
|
+
context: { queryText: 'test query', topK: 5 },
|
|
144
|
+
mastra: mockMastra as any,
|
|
145
|
+
runtimeContext,
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
expect(vectorQuerySearch).toHaveBeenCalledWith(
|
|
149
|
+
expect.objectContaining({
|
|
150
|
+
databaseConfig: undefined,
|
|
151
|
+
}),
|
|
152
|
+
);
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
it('should handle multiple database configurations', async () => {
|
|
156
|
+
const databaseConfig: DatabaseConfig = {
|
|
157
|
+
pinecone: {
|
|
158
|
+
namespace: 'test-namespace',
|
|
159
|
+
},
|
|
160
|
+
pgvector: {
|
|
161
|
+
minScore: 0.8,
|
|
162
|
+
ef: 100,
|
|
163
|
+
},
|
|
164
|
+
chroma: {
|
|
165
|
+
where: { category: 'documents' },
|
|
166
|
+
},
|
|
167
|
+
};
|
|
168
|
+
|
|
169
|
+
const tool = createVectorQueryTool({
|
|
170
|
+
vectorStoreName: 'multidb',
|
|
171
|
+
indexName: 'testIndex',
|
|
172
|
+
model: mockModel,
|
|
173
|
+
databaseConfig,
|
|
174
|
+
});
|
|
175
|
+
|
|
176
|
+
const runtimeContext = new RuntimeContext();
|
|
177
|
+
|
|
178
|
+
await tool.execute({
|
|
179
|
+
context: { queryText: 'test query', topK: 5 },
|
|
180
|
+
mastra: mockMastra as any,
|
|
181
|
+
runtimeContext,
|
|
182
|
+
});
|
|
183
|
+
|
|
184
|
+
expect(vectorQuerySearch).toHaveBeenCalledWith(
|
|
185
|
+
expect.objectContaining({
|
|
186
|
+
databaseConfig,
|
|
187
|
+
}),
|
|
188
|
+
);
|
|
189
|
+
});
|
|
190
|
+
});
|
|
@@ -25,6 +25,8 @@ export const createVectorQueryTool = (options: VectorQueryToolOptions) => {
|
|
|
25
25
|
const includeVectors: boolean = runtimeContext.get('includeVectors') ?? options.includeVectors ?? false;
|
|
26
26
|
const includeSources: boolean = runtimeContext.get('includeSources') ?? options.includeSources ?? true;
|
|
27
27
|
const reranker: RerankConfig = runtimeContext.get('reranker') ?? options.reranker;
|
|
28
|
+
const databaseConfig = runtimeContext.get('databaseConfig') ?? options.databaseConfig;
|
|
29
|
+
|
|
28
30
|
if (!indexName) throw new Error(`indexName is required, got: ${indexName}`);
|
|
29
31
|
if (!vectorStoreName) throw new Error(`vectorStoreName is required, got: ${vectorStoreName}`);
|
|
30
32
|
|
|
@@ -40,7 +42,7 @@ export const createVectorQueryTool = (options: VectorQueryToolOptions) => {
|
|
|
40
42
|
);
|
|
41
43
|
}
|
|
42
44
|
if (logger) {
|
|
43
|
-
logger.debug('[VectorQueryTool] execute called with:', { queryText, topK, filter });
|
|
45
|
+
logger.debug('[VectorQueryTool] execute called with:', { queryText, topK, filter, databaseConfig });
|
|
44
46
|
}
|
|
45
47
|
try {
|
|
46
48
|
const topKValue =
|
|
@@ -74,7 +76,7 @@ export const createVectorQueryTool = (options: VectorQueryToolOptions) => {
|
|
|
74
76
|
})();
|
|
75
77
|
}
|
|
76
78
|
if (logger) {
|
|
77
|
-
logger.debug('Prepared vector query parameters', { queryText, topK: topKValue, queryFilter });
|
|
79
|
+
logger.debug('Prepared vector query parameters', { queryText, topK: topKValue, queryFilter, databaseConfig });
|
|
78
80
|
}
|
|
79
81
|
|
|
80
82
|
const { results } = await vectorQuerySearch({
|
|
@@ -85,6 +87,7 @@ export const createVectorQueryTool = (options: VectorQueryToolOptions) => {
|
|
|
85
87
|
queryFilter: Object.keys(queryFilter || {}).length > 0 ? queryFilter : undefined,
|
|
86
88
|
topK: topKValue,
|
|
87
89
|
includeVectors,
|
|
90
|
+
databaseConfig,
|
|
88
91
|
});
|
|
89
92
|
if (logger) {
|
|
90
93
|
logger.debug('vectorQuerySearch returned results', { count: results.length });
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import type { MastraVector, QueryResult } from '@mastra/core/vector';
|
|
1
|
+
import type { MastraVector, QueryResult, QueryVectorParams } from '@mastra/core/vector';
|
|
2
2
|
import type { VectorFilter } from '@mastra/core/vector/filter';
|
|
3
3
|
import { embed } from 'ai';
|
|
4
4
|
import type { EmbeddingModel } from 'ai';
|
|
5
|
+
import type { DatabaseConfig } from '../tools/types';
|
|
5
6
|
|
|
6
7
|
interface VectorQuerySearchParams {
|
|
7
8
|
indexName: string;
|
|
@@ -12,6 +13,8 @@ interface VectorQuerySearchParams {
|
|
|
12
13
|
topK: number;
|
|
13
14
|
includeVectors?: boolean;
|
|
14
15
|
maxRetries?: number;
|
|
16
|
+
/** Database-specific configuration options */
|
|
17
|
+
databaseConfig?: DatabaseConfig;
|
|
15
18
|
}
|
|
16
19
|
|
|
17
20
|
interface VectorQuerySearchResult {
|
|
@@ -19,6 +22,14 @@ interface VectorQuerySearchResult {
|
|
|
19
22
|
queryEmbedding: number[];
|
|
20
23
|
}
|
|
21
24
|
|
|
25
|
+
enum DatabaseType {
|
|
26
|
+
Pinecone = 'pinecone',
|
|
27
|
+
PgVector = 'pgvector',
|
|
28
|
+
Chroma = 'chroma',
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const DATABASE_TYPE_MAP = Object.keys(DatabaseType);
|
|
32
|
+
|
|
22
33
|
// Helper function to handle vector query search
|
|
23
34
|
export const vectorQuerySearch = async ({
|
|
24
35
|
indexName,
|
|
@@ -29,20 +40,78 @@ export const vectorQuerySearch = async ({
|
|
|
29
40
|
topK,
|
|
30
41
|
includeVectors = false,
|
|
31
42
|
maxRetries = 2,
|
|
43
|
+
databaseConfig = {},
|
|
32
44
|
}: VectorQuerySearchParams): Promise<VectorQuerySearchResult> => {
|
|
33
45
|
const { embedding } = await embed({
|
|
34
46
|
value: queryText,
|
|
35
47
|
model,
|
|
36
48
|
maxRetries,
|
|
37
49
|
});
|
|
38
|
-
|
|
39
|
-
|
|
50
|
+
|
|
51
|
+
// Build query parameters with database-specific configurations
|
|
52
|
+
const queryParams: QueryVectorParams = {
|
|
40
53
|
indexName,
|
|
41
54
|
queryVector: embedding,
|
|
42
55
|
topK,
|
|
43
56
|
filter: queryFilter,
|
|
44
57
|
includeVector: includeVectors,
|
|
45
|
-
}
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
// Get relevant chunks from the vector database
|
|
61
|
+
const results = await vectorStore.query({ ...queryParams, ...databaseSpecificParams(databaseConfig) });
|
|
46
62
|
|
|
47
63
|
return { results, queryEmbedding: embedding };
|
|
48
64
|
};
|
|
65
|
+
|
|
66
|
+
const databaseSpecificParams = (databaseConfig: DatabaseConfig) => {
|
|
67
|
+
const databaseSpecificParams: DatabaseConfig = {};
|
|
68
|
+
|
|
69
|
+
// Apply database-specific configurations
|
|
70
|
+
if (databaseConfig) {
|
|
71
|
+
// Pinecone-specific configurations
|
|
72
|
+
if (databaseConfig.pinecone) {
|
|
73
|
+
if (databaseConfig.pinecone.namespace) {
|
|
74
|
+
databaseSpecificParams.namespace = databaseConfig.pinecone.namespace;
|
|
75
|
+
}
|
|
76
|
+
if (databaseConfig.pinecone.sparseVector) {
|
|
77
|
+
databaseSpecificParams.sparseVector = databaseConfig.pinecone.sparseVector;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
// pgVector-specific configurations
|
|
82
|
+
if (databaseConfig.pgvector) {
|
|
83
|
+
if (databaseConfig.pgvector.minScore !== undefined) {
|
|
84
|
+
databaseSpecificParams.minScore = databaseConfig.pgvector.minScore;
|
|
85
|
+
}
|
|
86
|
+
if (databaseConfig.pgvector.ef !== undefined) {
|
|
87
|
+
databaseSpecificParams.ef = databaseConfig.pgvector.ef;
|
|
88
|
+
}
|
|
89
|
+
if (databaseConfig.pgvector.probes !== undefined) {
|
|
90
|
+
databaseSpecificParams.probes = databaseConfig.pgvector.probes;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
// Chroma-specific configurations
|
|
95
|
+
if (databaseConfig.chroma) {
|
|
96
|
+
if (databaseConfig.chroma.where) {
|
|
97
|
+
databaseSpecificParams.where = databaseConfig.chroma.where;
|
|
98
|
+
}
|
|
99
|
+
if (databaseConfig.chroma.whereDocument) {
|
|
100
|
+
databaseSpecificParams.whereDocument = databaseConfig.chroma.whereDocument;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
// Handle any additional database configs
|
|
105
|
+
Object.keys(databaseConfig).forEach(dbName => {
|
|
106
|
+
if (!DATABASE_TYPE_MAP.includes(dbName)) {
|
|
107
|
+
// For unknown database types, merge the config directly
|
|
108
|
+
const config = databaseConfig[dbName];
|
|
109
|
+
if (config && typeof config === 'object') {
|
|
110
|
+
Object.assign(databaseSpecificParams, config);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
return databaseSpecificParams;
|
|
117
|
+
};
|