@mastra/chroma 1.1.4 → 1.1.5-alpha.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.
@@ -3,7 +3,7 @@ name: mastra-chroma
3
3
  description: Documentation for @mastra/chroma. Use when working with @mastra/chroma APIs, configuration, or implementation.
4
4
  metadata:
5
5
  package: "@mastra/chroma"
6
- version: "1.1.4"
6
+ version: "1.1.5-alpha.0"
7
7
  ---
8
8
 
9
9
  ## When to use
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.1.4",
2
+ "version": "1.1.5-alpha.0",
3
3
  "package": "@mastra/chroma",
4
4
  "exports": {},
5
5
  "modules": {}
@@ -382,11 +382,12 @@ Vector store prompts define query patterns and filtering capabilities for each v
382
382
 
383
383
  ```ts
384
384
  import { MONGODB_PROMPT } from '@mastra/mongodb'
385
+ import { Agent } from '@mastra/core/agent'
385
386
 
386
387
  export const ragAgent = new Agent({
387
388
  id: 'rag-agent',
388
389
  name: 'RAG Agent',
389
- model: 'openai/gpt-5.6-sol',
390
+ model: 'openai/gpt-6.1-sol',
390
391
  instructions: `
391
392
  Process queries using the provided context. Structure responses to be concise and relevant.
392
393
  ${MONGODB_PROMPT}
@@ -403,7 +404,7 @@ import { PGVECTOR_PROMPT } from '@mastra/pg'
403
404
  export const ragAgent = new Agent({
404
405
  id: 'rag-agent',
405
406
  name: 'RAG Agent',
406
- model: 'openai/gpt-5.6-sol',
407
+ model: 'openai/gpt-6.1-sol',
407
408
  instructions: `
408
409
  Process queries using the provided context. Structure responses to be concise and relevant.
409
410
  ${PGVECTOR_PROMPT}
@@ -416,11 +417,12 @@ export const ragAgent = new Agent({
416
417
 
417
418
  ```ts
418
419
  import { PINECONE_PROMPT } from '@mastra/pinecone'
420
+ import { Agent } from '@mastra/core/agent'
419
421
 
420
422
  export const ragAgent = new Agent({
421
423
  id: 'rag-agent',
422
424
  name: 'RAG Agent',
423
- model: 'openai/gpt-5.6-sol',
425
+ model: 'openai/gpt-6.1-sol',
424
426
  instructions: `
425
427
  Process queries using the provided context. Structure responses to be concise and relevant.
426
428
  ${PINECONE_PROMPT}
@@ -433,11 +435,12 @@ export const ragAgent = new Agent({
433
435
 
434
436
  ```ts
435
437
  import { QDRANT_PROMPT } from '@mastra/qdrant'
438
+ import { Agent } from '@mastra/core/agent'
436
439
 
437
440
  export const ragAgent = new Agent({
438
441
  id: 'rag-agent',
439
442
  name: 'RAG Agent',
440
- model: 'openai/gpt-5.6-sol',
443
+ model: 'openai/gpt-6.1-sol',
441
444
  instructions: `
442
445
  Process queries using the provided context. Structure responses to be concise and relevant.
443
446
  ${QDRANT_PROMPT}
@@ -450,11 +453,12 @@ export const ragAgent = new Agent({
450
453
 
451
454
  ```ts
452
455
  import { CHROMA_PROMPT } from '@mastra/chroma'
456
+ import { Agent } from '@mastra/core/agent'
453
457
 
454
458
  export const ragAgent = new Agent({
455
459
  id: 'rag-agent',
456
460
  name: 'RAG Agent',
457
- model: 'openai/gpt-5.6-sol',
461
+ model: 'openai/gpt-6.1-sol',
458
462
  instructions: `
459
463
  Process queries using the provided context. Structure responses to be concise and relevant.
460
464
  ${CHROMA_PROMPT}
@@ -467,11 +471,12 @@ export const ragAgent = new Agent({
467
471
 
468
472
  ```ts
469
473
  import { ASTRA_PROMPT } from '@mastra/astra'
474
+ import { Agent } from '@mastra/core/agent'
470
475
 
471
476
  export const ragAgent = new Agent({
472
477
  id: 'rag-agent',
473
478
  name: 'RAG Agent',
474
- model: 'openai/gpt-5.6-sol',
479
+ model: 'openai/gpt-6.1-sol',
475
480
  instructions: `
476
481
  Process queries using the provided context. Structure responses to be concise and relevant.
477
482
  ${ASTRA_PROMPT}
@@ -484,11 +489,12 @@ export const ragAgent = new Agent({
484
489
 
485
490
  ```ts
486
491
  import { LIBSQL_PROMPT } from '@mastra/libsql'
492
+ import { Agent } from '@mastra/core/agent'
487
493
 
488
494
  export const ragAgent = new Agent({
489
495
  id: 'rag-agent',
490
496
  name: 'RAG Agent',
491
- model: 'openai/gpt-5.6-sol',
497
+ model: 'openai/gpt-6.1-sol',
492
498
  instructions: `
493
499
  Process queries using the provided context. Structure responses to be concise and relevant.
494
500
  ${LIBSQL_PROMPT}
@@ -501,11 +507,12 @@ export const ragAgent = new Agent({
501
507
 
502
508
  ```ts
503
509
  import { UPSTASH_PROMPT } from '@mastra/upstash'
510
+ import { Agent } from '@mastra/core/agent'
504
511
 
505
512
  export const ragAgent = new Agent({
506
513
  id: 'rag-agent',
507
514
  name: 'RAG Agent',
508
- model: 'openai/gpt-5.6-sol',
515
+ model: 'openai/gpt-6.1-sol',
509
516
  instructions: `
510
517
  Process queries using the provided context. Structure responses to be concise and relevant.
511
518
  ${UPSTASH_PROMPT}
@@ -518,11 +525,12 @@ export const ragAgent = new Agent({
518
525
 
519
526
  ```ts
520
527
  import { VECTORIZE_PROMPT } from '@mastra/vectorize'
528
+ import { Agent } from '@mastra/core/agent'
521
529
 
522
530
  export const ragAgent = new Agent({
523
531
  id: 'rag-agent',
524
532
  name: 'RAG Agent',
525
- model: 'openai/gpt-5.6-sol',
533
+ model: 'openai/gpt-6.1-sol',
526
534
  instructions: `
527
535
  Process queries using the provided context. Structure responses to be concise and relevant.
528
536
  ${VECTORIZE_PROMPT}
@@ -535,11 +543,12 @@ export const ragAgent = new Agent({
535
543
 
536
544
  ```ts
537
545
  import { OPENSEARCH_PROMPT } from '@mastra/opensearch'
546
+ import { Agent } from '@mastra/core/agent'
538
547
 
539
548
  export const ragAgent = new Agent({
540
549
  id: 'rag-agent',
541
550
  name: 'RAG Agent',
542
- model: 'openai/gpt-5.6-sol',
551
+ model: 'openai/gpt-6.1-sol',
543
552
  instructions: `
544
553
  Process queries using the provided context. Structure responses to be concise and relevant.
545
554
  ${OPENSEARCH_PROMPT}
@@ -552,11 +561,12 @@ export const ragAgent = new Agent({
552
561
 
553
562
  ```ts
554
563
  import { ORACLEDB_PROMPT } from '@mastra/oracledb'
564
+ import { Agent } from '@mastra/core/agent'
555
565
 
556
566
  export const ragAgent = new Agent({
557
567
  id: 'rag-agent',
558
568
  name: 'RAG Agent',
559
- model: 'openai/gpt-5.6-sol',
569
+ model: 'openai/gpt-6.1-sol',
560
570
  instructions: `
561
571
  Process queries using the provided context. Structure responses to be concise and relevant.
562
572
  ${ORACLEDB_PROMPT}
@@ -569,11 +579,12 @@ export const ragAgent = new Agent({
569
579
 
570
580
  ```ts
571
581
  import { S3VECTORS_PROMPT } from '@mastra/s3vectors'
582
+ import { Agent } from '@mastra/core/agent'
572
583
 
573
584
  export const ragAgent = new Agent({
574
585
  id: 'rag-agent',
575
586
  name: 'RAG Agent',
576
- model: 'openai/gpt-5.6-sol',
587
+ model: 'openai/gpt-6.1-sol',
577
588
  instructions: `
578
589
  Process queries using the provided context. Structure responses to be concise and relevant.
579
590
  ${S3VECTORS_PROMPT}
@@ -605,7 +616,7 @@ const initialResults = await pgVector.query({
605
616
  // Create a relevance scorer
606
617
  const relevanceProvider = new MastraAgentRelevanceScorer(
607
618
  'relevance-scorer',
608
- 'openai/gpt-5.6-sol',
619
+ 'openai/gpt-6.1-sol',
609
620
  )
610
621
 
611
622
  // Re-rank the results
@@ -24,9 +24,9 @@ The ChromaVector class provides vector search using [Chroma](https://docs.trychr
24
24
 
25
25
  **apiKey** (`string`): A Chroma Cloud API key
26
26
 
27
- **tenant** (`string`): The tenant name in the Chroma server to connect to. Defaults to 'default\_tenant' for single-node Chroma. Auto-resolved for Chroma Cloud users based on the provided API key
27
+ **tenant** (`string`): The tenant name in the Chroma server to connect to. Defaults to 'default_tenant' for single-node Chroma. Auto-resolved for Chroma Cloud users based on the provided API key
28
28
 
29
- **database** (`string`): The database name to connect to. Defaults to 'default\_database' for single-node Chroma. Auto-resolved for Chroma Cloud users based on the provided API key
29
+ **database** (`string`): The database name to connect to. Defaults to 'default_database' for single-node Chroma. Auto-resolved for Chroma Cloud users based on the provided API key
30
30
 
31
31
  **headers** (`Record<string, any>`): Additional HTTP headers to send with requests
32
32
 
package/dist/index.cjs CHANGED
@@ -4,15 +4,14 @@ let _mastra_core_storage = require("@mastra/core/storage");
4
4
  let _mastra_core_vector = require("@mastra/core/vector");
5
5
  let chromadb = require("chromadb");
6
6
  let _mastra_core_vector_filter = require("@mastra/core/vector/filter");
7
- //#region src/vector/distance-to-score.ts
7
+ // src/vector/distance-to-score.ts
8
8
  function distanceToScore(distance, metric) {
9
9
  switch (metric) {
10
10
  case "euclidean": return 1 / (1 + Math.sqrt(distance));
11
11
  default: return 1 - distance;
12
12
  }
13
13
  }
14
- //#endregion
15
- //#region src/vector/filter.ts
14
+ // src/vector/filter.ts
16
15
  /**
17
16
  * Translator for Chroma filter queries.
18
17
  * Maintains MongoDB-compatible syntax while ensuring proper validation
@@ -84,8 +83,7 @@ var ChromaFilterTranslator = class extends _mastra_core_vector_filter.BaseFilter
84
83
  return this.normalizeComparisonValue(value);
85
84
  }
86
85
  };
87
- //#endregion
88
- //#region src/vector/index.ts
86
+ // src/vector/index.ts
89
87
  const spaceMappings = {
90
88
  cosine: "cosine",
91
89
  euclidean: "l2",
@@ -506,8 +504,7 @@ var ChromaVector = class extends _mastra_core_vector.MastraVector {
506
504
  }
507
505
  }
508
506
  };
509
- //#endregion
510
- //#region src/vector/prompt.ts
507
+ // src/vector/prompt.ts
511
508
  /**
512
509
  * Vector store specific prompt that details supported operators and examples.
513
510
  * This prompt helps users construct valid filters for Chroma Vector.
@@ -580,7 +577,6 @@ Example Complex Query:
580
577
  ]}
581
578
  ]
582
579
  }`;
583
- //#endregion
584
580
  exports.CHROMA_PROMPT = CHROMA_PROMPT;
585
581
  exports.ChromaVector = ChromaVector;
586
582
 
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","names":["BaseFilterTranslator","MastraVector","CloudClient","ChromaClient","MastraError","createVectorErrorId","ErrorDomain","ErrorCategory"],"sources":["../src/vector/distance-to-score.ts","../src/vector/filter.ts","../src/vector/index.ts","../src/vector/prompt.ts"],"sourcesContent":["export function distanceToScore(distance: number, metric: 'cosine' | 'euclidean' | 'dotproduct'): number {\n switch (metric) {\n case 'euclidean':\n return 1 / (1 + Math.sqrt(distance));\n case 'dotproduct':\n case 'cosine':\n default:\n return 1 - distance;\n }\n}\n","import { BaseFilterTranslator } from '@mastra/core/vector/filter';\nimport type {\n VectorFilter,\n OperatorSupport,\n QueryOperator,\n OperatorValueMap,\n LogicalOperatorValueMap,\n BlacklistedRootOperators,\n} from '@mastra/core/vector/filter';\n\ntype ChromaOperatorValueMap = Omit<OperatorValueMap, '$exists' | '$elemMatch' | '$regex' | '$options'>;\n\ntype ChromaLogicalOperatorValueMap = Omit<LogicalOperatorValueMap, '$nor' | '$not'>;\n\ntype ChromaBlacklisted = BlacklistedRootOperators | '$nor' | '$not';\n\nexport type ChromaVectorFilter = VectorFilter<\n keyof ChromaOperatorValueMap,\n ChromaOperatorValueMap,\n ChromaLogicalOperatorValueMap,\n ChromaBlacklisted\n>;\n\n/**\n * Translator for Chroma filter queries.\n * Maintains MongoDB-compatible syntax while ensuring proper validation\n * and normalization of values.\n */\nexport class ChromaFilterTranslator extends BaseFilterTranslator<ChromaVectorFilter> {\n protected override getSupportedOperators(): OperatorSupport {\n return {\n ...BaseFilterTranslator.DEFAULT_OPERATORS,\n logical: ['$and', '$or'],\n array: ['$in', '$nin'],\n element: [],\n regex: [],\n custom: [],\n };\n }\n\n translate(filter?: ChromaVectorFilter): ChromaVectorFilter {\n if (this.isEmpty(filter)) return filter;\n this.validateFilter(filter);\n\n return this.translateNode(filter);\n }\n\n private translateNode(node: ChromaVectorFilter, currentPath: string = ''): any {\n // Handle primitive values and arrays\n if (this.isRegex(node)) {\n throw new Error('Regex is supported in Chroma via the `documentFilter` argument');\n }\n if (this.isPrimitive(node)) return this.normalizeComparisonValue(node);\n if (Array.isArray(node)) return { $in: this.normalizeArrayValues(node) };\n\n const entries = Object.entries(node as Record<string, any>);\n const firstEntry = entries[0];\n // Handle single operator case\n if (entries.length === 1 && firstEntry && this.isOperator(firstEntry[0])) {\n const [operator, value] = firstEntry;\n const translated = this.translateOperator(operator, value);\n if (this.isLogicalOperator(operator) && Array.isArray(translated) && translated.length === 1) {\n return translated[0];\n }\n return this.isLogicalOperator(operator) ? { [operator]: translated } : translated;\n }\n\n // Process each entry\n const result: Record<string, any> = {};\n const multiOperatorConditions: any[] = [];\n\n for (const [key, value] of entries) {\n const newPath = currentPath ? `${currentPath}.${key}` : key;\n\n if (this.isOperator(key)) {\n result[key] = this.translateOperator(key, value);\n continue;\n }\n\n if (typeof value === 'object' && value !== null && !Array.isArray(value)) {\n // Check for multiple operators on same field\n const valueEntries = Object.entries(value);\n if (valueEntries.every(([op]) => this.isOperator(op)) && valueEntries.length > 1) {\n valueEntries.forEach(([op, opValue]) => {\n multiOperatorConditions.push({\n [newPath]: { [op]: this.normalizeComparisonValue(opValue) },\n });\n });\n continue;\n }\n\n // Check if the nested object contains operators\n if (Object.keys(value).length === 0) {\n result[newPath] = this.translateNode(value);\n } else {\n const hasOperators = Object.keys(value).some(k => this.isOperator(k));\n if (hasOperators) {\n // For objects with operators, normalize each operator value\n const normalizedValue: Record<string, any> = {};\n for (const [op, opValue] of Object.entries(value)) {\n normalizedValue[op] = this.isOperator(op) ? this.translateOperator(op, opValue) : opValue;\n }\n result[newPath] = normalizedValue;\n } else {\n // For objects without operators, flatten them\n Object.assign(result, this.translateNode(value, newPath));\n }\n }\n } else {\n result[newPath] = this.translateNode(value);\n }\n }\n\n // Combine multiOperatorConditions with result if both exist\n if (multiOperatorConditions.length > 0) {\n // Convert result to array of conditions for $and\n const resultConditions = Object.entries(result).map(([key, value]) => ({ [key]: value }));\n const allConditions = [...multiOperatorConditions, ...resultConditions];\n\n if (allConditions.length === 1) {\n return allConditions[0];\n }\n return { $and: allConditions };\n }\n\n // Wrap in $and if there are multiple top-level fields\n if (Object.keys(result).length > 1 && !currentPath) {\n return {\n $and: Object.entries(result).map(([key, value]) => ({ [key]: value })),\n };\n }\n\n return result;\n }\n\n private translateOperator(operator: QueryOperator, value: any): any {\n // Handle logical operators\n if (this.isLogicalOperator(operator)) {\n return Array.isArray(value) ? value.map(item => this.translateNode(item)) : this.translateNode(value);\n }\n\n // Handle comparison and element operators\n return this.normalizeComparisonValue(value);\n }\n}\n","import { MastraError, ErrorDomain, ErrorCategory } from '@mastra/core/error';\nimport { createVectorErrorId } from '@mastra/core/storage';\nimport { MastraVector, validateUpsert, validateTopK } from '@mastra/core/vector';\nimport type {\n QueryResult,\n IndexStats,\n CreateIndexParams,\n UpsertVectorParams,\n QueryVectorParams,\n DescribeIndexParams,\n DeleteIndexParams,\n DeleteVectorParams,\n UpdateVectorParams,\n DeleteVectorsParams,\n} from '@mastra/core/vector';\nimport { ChromaClient, CloudClient } from 'chromadb';\nimport type { ChromaClientArgs, RecordSet, Where, WhereDocument, Collection, Metadata, Search } from 'chromadb';\nimport { distanceToScore } from './distance-to-score';\nimport type { ChromaVectorFilter } from './filter';\nimport { ChromaFilterTranslator } from './filter';\n\ninterface ChromaUpsertVectorParams extends UpsertVectorParams {\n documents?: string[];\n}\n\ninterface ChromaQueryVectorParams extends QueryVectorParams<ChromaVectorFilter> {\n documentFilter?: WhereDocument | null;\n}\n\ninterface ChromaGetRecordsParams {\n indexName: string;\n ids?: string[];\n filter?: ChromaVectorFilter;\n documentFilter?: WhereDocument | null;\n includeVector?: boolean;\n limit?: number;\n offset?: number;\n}\n\ntype MastraMetadata = {\n dimension?: number;\n};\n\ntype ChromaVectorArgs = ChromaClientArgs & { apiKey?: string };\n\nconst spaceMappings = {\n cosine: 'cosine',\n euclidean: 'l2',\n dotproduct: 'ip',\n l2: 'euclidean',\n ip: 'dotproduct',\n};\n\nexport class ChromaVector extends MastraVector<ChromaVectorFilter> {\n private client: ChromaClient;\n private collections: Map<string, Collection>;\n\n constructor({ id, ...chromaClientArgs }: ChromaVectorArgs & { id: string }) {\n super({ id });\n if (chromaClientArgs?.apiKey) {\n this.client = new CloudClient({\n apiKey: chromaClientArgs.apiKey,\n tenant: chromaClientArgs.tenant,\n database: chromaClientArgs.database,\n });\n } else {\n this.client = new ChromaClient(chromaClientArgs);\n }\n this.collections = new Map();\n }\n\n async getCollection({ indexName, forceUpdate = false }: { indexName: string; forceUpdate?: boolean }) {\n let collection = this.collections.get(indexName);\n if (forceUpdate || !collection) {\n try {\n collection = await this.client.getCollection({ name: indexName });\n this.collections.set(indexName, collection);\n return collection;\n } catch {\n throw new MastraError({\n id: createVectorErrorId('CHROMA', 'GET_COLLECTION', 'FAILED'),\n domain: ErrorDomain.MASTRA_VECTOR,\n category: ErrorCategory.THIRD_PARTY,\n details: { indexName },\n });\n }\n }\n return collection;\n }\n\n private validateVectorDimensions(vectors: number[][], dimension: number): void {\n for (let i = 0; i < vectors.length; i++) {\n if (vectors?.[i]?.length !== dimension) {\n throw new Error(\n `Vector at index ${i} has invalid dimension ${vectors?.[i]?.length}. Expected ${dimension} dimensions.`,\n );\n }\n }\n }\n\n async upsert({ indexName, vectors, metadata, ids, documents }: ChromaUpsertVectorParams): Promise<string[]> {\n // Validate input parameters and vector values\n validateUpsert('CHROMA', vectors, metadata, ids, true);\n\n try {\n const collection = await this.getCollection({ indexName });\n\n const stats = await this.describeIndex({ indexName });\n this.validateVectorDimensions(vectors, stats.dimension);\n const generatedIds = ids || vectors.map(() => crypto.randomUUID());\n\n await collection.upsert({\n ids: generatedIds,\n embeddings: vectors,\n metadatas: metadata,\n documents: documents,\n });\n\n return generatedIds;\n } catch (error: any) {\n if (error instanceof MastraError) throw error;\n throw new MastraError(\n {\n id: createVectorErrorId('CHROMA', 'UPSERT', 'FAILED'),\n domain: ErrorDomain.MASTRA_VECTOR,\n category: ErrorCategory.THIRD_PARTY,\n details: { indexName },\n },\n error,\n );\n }\n }\n\n async createIndex({ indexName, dimension, metric = 'cosine' }: CreateIndexParams): Promise<void> {\n if (!Number.isInteger(dimension) || dimension <= 0) {\n throw new MastraError({\n id: createVectorErrorId('CHROMA', 'CREATE_INDEX', 'INVALID_DIMENSION'),\n text: 'Dimension must be a positive integer',\n domain: ErrorDomain.MASTRA_VECTOR,\n category: ErrorCategory.USER,\n details: { dimension },\n });\n }\n\n const hnswSpace = spaceMappings[metric] as 'cosine' | 'l2' | 'ip' | undefined;\n\n if (!hnswSpace || !['cosine', 'l2', 'ip'].includes(hnswSpace)) {\n throw new MastraError({\n id: createVectorErrorId('CHROMA', 'CREATE_INDEX', 'INVALID_METRIC'),\n text: `Invalid metric: \"${metric}\". Must be one of: cosine, euclidean, dotproduct`,\n domain: ErrorDomain.MASTRA_VECTOR,\n category: ErrorCategory.USER,\n details: { metric },\n });\n }\n\n try {\n const collection = await this.client.createCollection({\n name: indexName,\n metadata: { dimension },\n configuration: { hnsw: { space: hnswSpace } },\n embeddingFunction: null,\n });\n this.collections.set(indexName, collection);\n } catch (error: any) {\n // Check for 'already exists' error\n const message = error?.message || error?.toString();\n if (message && message.toLowerCase().includes('already exists')) {\n // Fetch collection info and check dimension\n await this.validateExistingIndex(indexName, dimension, metric);\n return;\n }\n throw new MastraError(\n {\n id: createVectorErrorId('CHROMA', 'CREATE_INDEX', 'FAILED'),\n domain: ErrorDomain.MASTRA_VECTOR,\n category: ErrorCategory.THIRD_PARTY,\n details: { indexName },\n },\n error,\n );\n }\n }\n\n transformFilter(filter?: ChromaVectorFilter) {\n const translator = new ChromaFilterTranslator();\n const translatedFilter = translator.translate(filter);\n return translatedFilter ? (translatedFilter as Where) : undefined;\n }\n\n async query<T extends Metadata = Metadata>({\n indexName,\n queryVector,\n topK = 10,\n filter,\n includeVector = false,\n documentFilter,\n }: ChromaQueryVectorParams): Promise<QueryResult[]> {\n if (!queryVector) {\n throw new MastraError({\n id: createVectorErrorId('CHROMA', 'QUERY', 'MISSING_VECTOR'),\n text: 'queryVector is required for Chroma queries. Metadata-only queries are not supported by this vector store.',\n domain: ErrorDomain.MASTRA_VECTOR,\n category: ErrorCategory.USER,\n details: { indexName },\n });\n }\n\n // Validate topK parameter\n validateTopK('CHROMA', topK);\n\n try {\n const collection = await this.getCollection({ indexName });\n\n const defaultInclude: ['documents', 'metadatas', 'distances'] = ['documents', 'metadatas', 'distances'];\n\n const translatedFilter = this.transformFilter(filter);\n const results = await collection.query<T>({\n queryEmbeddings: [queryVector],\n nResults: topK,\n where: translatedFilter ?? undefined,\n whereDocument: documentFilter ?? undefined,\n include: includeVector ? [...defaultInclude, 'embeddings'] : defaultInclude,\n });\n\n const space = collection.configuration?.hnsw?.space || collection.configuration?.spann?.space || 'cosine';\n const metric = spaceMappings[space] as 'cosine' | 'euclidean' | 'dotproduct';\n\n return (results.ids[0] || []).map((id: string, index: number) => {\n const distance = results.distances?.[0]?.[index];\n const score = distance == null ? 0 : distanceToScore(distance, metric);\n return {\n id,\n score,\n metadata: results.metadatas?.[0]?.[index] || {},\n document: results.documents?.[0]?.[index] ?? undefined,\n ...(includeVector && { vector: results.embeddings?.[0]?.[index] || [] }),\n };\n });\n } catch (error: any) {\n if (error instanceof MastraError) throw error;\n throw new MastraError(\n {\n id: createVectorErrorId('CHROMA', 'QUERY', 'FAILED'),\n domain: ErrorDomain.MASTRA_VECTOR,\n category: ErrorCategory.THIRD_PARTY,\n details: { indexName },\n },\n error,\n );\n }\n }\n\n async hybridSearch({ indexName, search }: { indexName: string; search: Search }): Promise<QueryResult[]> {\n try {\n const collection = await this.getCollection({ indexName });\n const results = await collection.search(search);\n return (results.rows()[0] ?? []).map(record => ({\n id: record.id,\n score: record.score ?? 0,\n metadata: record.metadata ?? undefined,\n vector: record.embedding ?? undefined,\n document: record.document ?? undefined,\n }));\n } catch (error: any) {\n if (error instanceof MastraError) throw error;\n throw new MastraError(\n {\n id: createVectorErrorId('CHROMA', 'SEARCH_API', 'FAILED'),\n domain: ErrorDomain.MASTRA_VECTOR,\n category: ErrorCategory.THIRD_PARTY,\n details: { indexName },\n },\n error,\n );\n }\n }\n\n async get<T extends Metadata = Metadata>({\n indexName,\n ids,\n filter,\n includeVector = false,\n documentFilter,\n offset,\n limit,\n }: ChromaGetRecordsParams) {\n try {\n const collection = await this.getCollection({ indexName });\n\n const defaultInclude: ['documents', 'metadatas'] = ['documents', 'metadatas'];\n const translatedFilter = this.transformFilter(filter);\n\n const result = await collection.get<T>({\n ids,\n where: translatedFilter ?? undefined,\n whereDocument: documentFilter ?? undefined,\n offset,\n limit,\n include: includeVector ? [...defaultInclude, 'embeddings'] : defaultInclude,\n });\n return result.rows();\n } catch (error: any) {\n if (error instanceof MastraError) throw error;\n throw new MastraError(\n {\n id: createVectorErrorId('CHROMA', 'GET', 'FAILED'),\n domain: ErrorDomain.MASTRA_VECTOR,\n category: ErrorCategory.THIRD_PARTY,\n details: { indexName },\n },\n error,\n );\n }\n }\n\n async listIndexes(): Promise<string[]> {\n try {\n const collections = await this.client.listCollections();\n return collections.map(collection => collection.name);\n } catch (error: any) {\n throw new MastraError(\n {\n id: createVectorErrorId('CHROMA', 'LIST_INDEXES', 'FAILED'),\n domain: ErrorDomain.MASTRA_VECTOR,\n category: ErrorCategory.THIRD_PARTY,\n },\n error,\n );\n }\n }\n\n /**\n * Retrieves statistics about a vector index.\n *\n * @param {string} indexName - The name of the index to describe\n * @returns A promise that resolves to the index statistics including dimension, count and metric\n */\n async describeIndex({ indexName }: DescribeIndexParams): Promise<IndexStats> {\n try {\n const collection = await this.getCollection({ indexName });\n const count = await collection.count();\n const metadata = collection.metadata as MastraMetadata | undefined;\n const space = collection.configuration.hnsw?.space || collection.configuration.spann?.space || undefined;\n\n return {\n dimension: metadata?.dimension || 0,\n count,\n metric: space ? (spaceMappings[space] as 'cosine' | 'euclidean' | 'dotproduct') : undefined,\n };\n } catch (error: any) {\n if (error instanceof MastraError) throw error;\n throw new MastraError(\n {\n id: createVectorErrorId('CHROMA', 'DESCRIBE_INDEX', 'FAILED'),\n domain: ErrorDomain.MASTRA_VECTOR,\n category: ErrorCategory.THIRD_PARTY,\n details: { indexName },\n },\n error,\n );\n }\n }\n\n async deleteIndex({ indexName }: DeleteIndexParams): Promise<void> {\n try {\n await this.client.deleteCollection({ name: indexName });\n this.collections.delete(indexName);\n } catch (error: any) {\n throw new MastraError(\n {\n id: createVectorErrorId('CHROMA', 'DELETE_INDEX', 'FAILED'),\n domain: ErrorDomain.MASTRA_VECTOR,\n category: ErrorCategory.THIRD_PARTY,\n details: { indexName },\n },\n error,\n );\n }\n }\n\n async forkIndex({ indexName, newIndexName }: { indexName: string; newIndexName: string }): Promise<void> {\n try {\n const collection = await this.getCollection({ indexName, forceUpdate: true });\n const forkedCollection = await collection.fork({ name: newIndexName });\n this.collections.set(newIndexName, forkedCollection);\n } catch (error: any) {\n if (error instanceof MastraError) throw error;\n throw new MastraError(\n {\n id: createVectorErrorId('CHROMA', 'FORK_INDEX', 'FAILED'),\n domain: ErrorDomain.MASTRA_VECTOR,\n category: ErrorCategory.THIRD_PARTY,\n details: { indexName },\n },\n error,\n );\n }\n }\n\n /**\n * Updates a vector by its ID or multiple vectors matching a filter.\n * @param indexName - The name of the index containing the vector(s).\n * @param id - The ID of the vector to update (mutually exclusive with filter).\n * @param filter - Filter to match multiple vectors to update (mutually exclusive with id).\n * @param update - An object containing the vector and/or metadata to update.\n * @param update.vector - An optional array of numbers representing the new vector.\n * @param update.metadata - An optional record containing the new metadata.\n * @returns A promise that resolves when the update is complete.\n * @throws Will throw an error if no updates are provided or if the update operation fails.\n */\n async updateVector({ indexName, id, filter, update }: UpdateVectorParams<ChromaVectorFilter>): Promise<void> {\n // Validate mutually exclusive parameters\n if (id && filter) {\n throw new MastraError({\n id: createVectorErrorId('CHROMA', 'UPDATE_VECTOR', 'MUTUALLY_EXCLUSIVE'),\n text: 'Cannot specify both id and filter - they are mutually exclusive',\n domain: ErrorDomain.MASTRA_VECTOR,\n category: ErrorCategory.USER,\n details: { indexName },\n });\n }\n\n if (!id && !filter) {\n throw new MastraError({\n id: createVectorErrorId('CHROMA', 'UPDATE_VECTOR', 'NO_TARGET'),\n text: 'Either id or filter must be provided',\n domain: ErrorDomain.MASTRA_VECTOR,\n category: ErrorCategory.USER,\n details: { indexName },\n });\n }\n\n if (!update.vector && !update.metadata) {\n throw new MastraError({\n id: createVectorErrorId('CHROMA', 'UPDATE_VECTOR', 'NO_PAYLOAD'),\n text: 'No updates provided',\n domain: ErrorDomain.MASTRA_VECTOR,\n category: ErrorCategory.USER,\n details: {\n indexName,\n ...(id && { id }),\n },\n });\n }\n\n // Validate filter is not empty\n if (filter && Object.keys(filter).length === 0) {\n throw new MastraError({\n id: createVectorErrorId('CHROMA', 'UPDATE_VECTOR', 'EMPTY_FILTER'),\n text: 'Filter cannot be an empty filter object',\n domain: ErrorDomain.MASTRA_VECTOR,\n category: ErrorCategory.USER,\n details: { indexName },\n });\n }\n\n try {\n const collection: Collection = await this.getCollection({ indexName });\n\n // Validate vector dimensions if provided\n if (update?.vector) {\n const stats = await this.describeIndex({ indexName });\n this.validateVectorDimensions([update.vector], stats.dimension);\n }\n\n if (id) {\n // Update single vector by ID\n const updateRecordSet: RecordSet = { ids: [id] };\n\n if (update?.vector) {\n updateRecordSet.embeddings = [update.vector];\n }\n\n if (update?.metadata) {\n updateRecordSet.metadatas = [update.metadata];\n }\n\n return await collection.update(updateRecordSet);\n } else if (filter) {\n // Update multiple vectors matching filter\n // First, get all vectors matching the filter\n const translatedFilter = this.transformFilter(filter);\n const matchingVectors = await collection.get({\n where: translatedFilter ?? undefined,\n include: ['embeddings', 'metadatas'],\n });\n\n const vectorRows = matchingVectors.rows();\n if (vectorRows.length === 0) {\n // No vectors to update - this is not an error\n return;\n }\n\n // Prepare update for all matching vectors\n const updateRecordSet: RecordSet = {\n ids: vectorRows.map(row => row.id),\n };\n\n if (update?.vector) {\n // Use the same new vector for all matching records\n updateRecordSet.embeddings = vectorRows.map(() => update.vector!);\n }\n\n if (update?.metadata) {\n // Use the same new metadata for all matching records\n updateRecordSet.metadatas = vectorRows.map(() => update.metadata!);\n }\n\n return await collection.update(updateRecordSet);\n }\n } catch (error: any) {\n if (error instanceof MastraError) throw error;\n throw new MastraError(\n {\n id: createVectorErrorId('CHROMA', 'UPDATE_VECTOR', 'FAILED'),\n domain: ErrorDomain.MASTRA_VECTOR,\n category: ErrorCategory.THIRD_PARTY,\n details: {\n indexName,\n ...(id && { id }),\n ...(filter && { filter: JSON.stringify(filter) }),\n },\n },\n error,\n );\n }\n }\n\n async deleteVector({ indexName, id }: DeleteVectorParams): Promise<void> {\n try {\n const collection: Collection = await this.getCollection({ indexName });\n await collection.delete({ ids: [id] });\n } catch (error: any) {\n if (error instanceof MastraError) throw error;\n throw new MastraError(\n {\n id: createVectorErrorId('CHROMA', 'DELETE_VECTOR', 'FAILED'),\n domain: ErrorDomain.MASTRA_VECTOR,\n category: ErrorCategory.THIRD_PARTY,\n details: {\n indexName,\n ...(id && { id }),\n },\n },\n error,\n );\n }\n }\n\n /**\n * Deletes multiple vectors by IDs or filter.\n * @param indexName - The name of the index containing the vectors.\n * @param ids - Array of vector IDs to delete (mutually exclusive with filter).\n * @param filter - Filter to match vectors to delete (mutually exclusive with ids).\n * @returns A promise that resolves when the deletion is complete.\n * @throws Will throw an error if both ids and filter are provided, or if neither is provided.\n */\n async deleteVectors({ indexName, filter, ids }: DeleteVectorsParams<ChromaVectorFilter>): Promise<void> {\n // Validate mutually exclusive parameters\n if (ids && filter) {\n throw new MastraError({\n id: createVectorErrorId('CHROMA', 'DELETE_VECTORS', 'MUTUALLY_EXCLUSIVE'),\n text: 'Cannot specify both ids and filter - they are mutually exclusive',\n domain: ErrorDomain.MASTRA_VECTOR,\n category: ErrorCategory.USER,\n details: { indexName },\n });\n }\n\n if (!ids && !filter) {\n throw new MastraError({\n id: createVectorErrorId('CHROMA', 'DELETE_VECTORS', 'NO_TARGET'),\n text: 'Either filter or ids must be provided',\n domain: ErrorDomain.MASTRA_VECTOR,\n category: ErrorCategory.USER,\n details: { indexName },\n });\n }\n\n // Validate ids array is not empty\n if (ids && ids.length === 0) {\n throw new MastraError({\n id: createVectorErrorId('CHROMA', 'DELETE_VECTORS', 'EMPTY_IDS'),\n text: 'Cannot delete with empty ids array',\n domain: ErrorDomain.MASTRA_VECTOR,\n category: ErrorCategory.USER,\n details: { indexName },\n });\n }\n\n // Validate filter is not empty\n if (filter && Object.keys(filter).length === 0) {\n throw new MastraError({\n id: createVectorErrorId('CHROMA', 'DELETE_VECTORS', 'EMPTY_FILTER'),\n text: 'Cannot delete with empty filter object',\n domain: ErrorDomain.MASTRA_VECTOR,\n category: ErrorCategory.USER,\n details: { indexName },\n });\n }\n\n try {\n const collection: Collection = await this.getCollection({ indexName });\n\n if (ids) {\n // Delete by IDs\n await collection.delete({ ids });\n } else if (filter) {\n // Delete by filter\n const translatedFilter = this.transformFilter(filter);\n await collection.delete({\n where: translatedFilter ?? undefined,\n });\n }\n } catch (error: any) {\n if (error instanceof MastraError) throw error;\n throw new MastraError(\n {\n id: createVectorErrorId('CHROMA', 'DELETE_VECTORS', 'FAILED'),\n domain: ErrorDomain.MASTRA_VECTOR,\n category: ErrorCategory.THIRD_PARTY,\n details: {\n indexName,\n ...(filter && { filter: JSON.stringify(filter) }),\n ...(ids && { idsCount: ids.length }),\n },\n },\n error,\n );\n }\n }\n}\n","/**\n * Vector store specific prompt that details supported operators and examples.\n * This prompt helps users construct valid filters for Chroma Vector.\n */\nexport const CHROMA_PROMPT = `When querying Chroma, 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\nLogical Operators:\n- $and: Logical AND\n Example: { \"$and\": [{ \"price\": { \"$gt\": 100 } }, { \"category\": \"electronics\" }] }\n- $or: Logical OR\n Example: { \"$or\": [{ \"price\": { \"$lt\": 50 } }, { \"category\": \"books\" }] }\n\nRestrictions:\n- Regex patterns are not supported\n- Element operators are not supported\n- Only $and and $or logical operators are supported\n- Nested fields are supported using dot notation\n- Multiple conditions on the same field are supported with both implicit and explicit $and\n- Empty arrays in $in/$nin will return no results\n- If multiple top-level fields exist, they're wrapped in $and\n- Only logical operators ($and, $or) can be used at the top level\n- All other operators must be used within a field condition\n Valid: { \"field\": { \"$gt\": 100 } }\n Valid: { \"$and\": [...] }\n Invalid: { \"$gt\": 100 }\n Invalid: { \"$in\": [...] }\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\": [{...}] } } }\n\nExample Complex Query:\n{\n \"$and\": [\n { \"category\": { \"$in\": [\"electronics\", \"computers\"] } },\n { \"price\": { \"$gte\": 100, \"$lte\": 1000 } },\n { \"$or\": [\n { \"inStock\": true },\n { \"preorder\": true }\n ]}\n ]\n}`;\n"],"mappings":";;;;;;;AAAA,SAAgB,gBAAgB,UAAkB,QAAuD;CACvG,QAAQ,QAAR;EACE,KAAK,aACH,OAAO,KAAK,IAAI,KAAK,KAAK,QAAQ;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kB,WAAW;GAC/D,MAAM;GACN,QAAQC,mBAAAA,YAAY;GACpB,UAAUC,mBAAAA,cAAc;GACxB,SAAS,EAAE,UAAU;EACvB,CAAC;EAIH,IAAI,UAAU,OAAO,KAAK,MAAM,CAAC,CAAC,WAAW,GAC3C,MAAM,IAAIH,mBAAAA,YAAY;GACpB,KAAA,GAAIC,qBAAAA,oBAAAA,CAAoB,UAAU,kBAAkB,cAAc;GAClE,MAAM;GACN,QAAQC,mBAAAA,YAAY;GACpB,UAAUC,mBAAAA,cAAc;GACxB,SAAS,EAAE,UAAU;EACvB,CAAC;EAGH,IAAI;GACF,MAAM,aAAyB,MAAM,KAAK,cAAc,EAAE,UAAU,CAAC;GAErE,IAAI,KAEF,MAAM,WAAW,OAAO,EAAE,IAAI,CAAC;QAC1B,IAAI,QAAQ;IAEjB,MAAM,mBAAmB,KAAK,gBAAgB,MAAM;IACpD,MAAM,WAAW,OAAO,EACtB,OAAO,oBAAoB,KAAA,EAC7B,CAAC;GACH;EACF,SAAS,OAAY;GACnB,IAAI,iBAAiBH,mBAAAA,aAAa,MAAM;GACxC,MAAM,IAAIA,mBAAAA,YACR;IACE,KAAA,GAAIC,qBAAAA,oBAAAA,CAAoB,UAAU,kBAAkB,QAAQ;IAC5D,QAAQC,mBAAAA,YAAY;IACpB,UAAUC,mBAAAA,cAAc;IACxB,SAAS;KACP;KACA,GAAI,UAAU,EAAE,QAAQ,KAAK,UAAU,MAAM,EAAE;KAC/C,GAAI,OAAO,EAAE,UAAU,IAAI,OAAO;IACpC;GACF,GACA,KACF;EACF;CACF;AACF;;;;;;;ACpnBA,MAAa,gBAAgB"}
1
+ {"version":3,"file":"index.cjs","names":["BaseFilterTranslator","MastraVector","CloudClient","ChromaClient","MastraError","createVectorErrorId","ErrorDomain","ErrorCategory"],"sources":["../src/vector/distance-to-score.ts","../src/vector/filter.ts","../src/vector/index.ts","../src/vector/prompt.ts"],"sourcesContent":["export function distanceToScore(distance: number, metric: 'cosine' | 'euclidean' | 'dotproduct'): number {\n switch (metric) {\n case 'euclidean':\n return 1 / (1 + Math.sqrt(distance));\n case 'dotproduct':\n case 'cosine':\n default:\n return 1 - distance;\n }\n}\n","import { BaseFilterTranslator } from '@mastra/core/vector/filter';\nimport type {\n VectorFilter,\n OperatorSupport,\n QueryOperator,\n OperatorValueMap,\n LogicalOperatorValueMap,\n BlacklistedRootOperators,\n} from '@mastra/core/vector/filter';\n\ntype ChromaOperatorValueMap = Omit<OperatorValueMap, '$exists' | '$elemMatch' | '$regex' | '$options'>;\n\ntype ChromaLogicalOperatorValueMap = Omit<LogicalOperatorValueMap, '$nor' | '$not'>;\n\ntype ChromaBlacklisted = BlacklistedRootOperators | '$nor' | '$not';\n\nexport type ChromaVectorFilter = VectorFilter<\n keyof ChromaOperatorValueMap,\n ChromaOperatorValueMap,\n ChromaLogicalOperatorValueMap,\n ChromaBlacklisted\n>;\n\n/**\n * Translator for Chroma filter queries.\n * Maintains MongoDB-compatible syntax while ensuring proper validation\n * and normalization of values.\n */\nexport class ChromaFilterTranslator extends BaseFilterTranslator<ChromaVectorFilter> {\n protected override getSupportedOperators(): OperatorSupport {\n return {\n ...BaseFilterTranslator.DEFAULT_OPERATORS,\n logical: ['$and', '$or'],\n array: ['$in', '$nin'],\n element: [],\n regex: [],\n custom: [],\n };\n }\n\n translate(filter?: ChromaVectorFilter): ChromaVectorFilter {\n if (this.isEmpty(filter)) return filter;\n this.validateFilter(filter);\n\n return this.translateNode(filter);\n }\n\n private translateNode(node: ChromaVectorFilter, currentPath: string = ''): any {\n // Handle primitive values and arrays\n if (this.isRegex(node)) {\n throw new Error('Regex is supported in Chroma via the `documentFilter` argument');\n }\n if (this.isPrimitive(node)) return this.normalizeComparisonValue(node);\n if (Array.isArray(node)) return { $in: this.normalizeArrayValues(node) };\n\n const entries = Object.entries(node as Record<string, any>);\n const firstEntry = entries[0];\n // Handle single operator case\n if (entries.length === 1 && firstEntry && this.isOperator(firstEntry[0])) {\n const [operator, value] = firstEntry;\n const translated = this.translateOperator(operator, value);\n if (this.isLogicalOperator(operator) && Array.isArray(translated) && translated.length === 1) {\n return translated[0];\n }\n return this.isLogicalOperator(operator) ? { [operator]: translated } : translated;\n }\n\n // Process each entry\n const result: Record<string, any> = {};\n const multiOperatorConditions: any[] = [];\n\n for (const [key, value] of entries) {\n const newPath = currentPath ? `${currentPath}.${key}` : key;\n\n if (this.isOperator(key)) {\n result[key] = this.translateOperator(key, value);\n continue;\n }\n\n if (typeof value === 'object' && value !== null && !Array.isArray(value)) {\n // Check for multiple operators on same field\n const valueEntries = Object.entries(value);\n if (valueEntries.every(([op]) => this.isOperator(op)) && valueEntries.length > 1) {\n valueEntries.forEach(([op, opValue]) => {\n multiOperatorConditions.push({\n [newPath]: { [op]: this.normalizeComparisonValue(opValue) },\n });\n });\n continue;\n }\n\n // Check if the nested object contains operators\n if (Object.keys(value).length === 0) {\n result[newPath] = this.translateNode(value);\n } else {\n const hasOperators = Object.keys(value).some(k => this.isOperator(k));\n if (hasOperators) {\n // For objects with operators, normalize each operator value\n const normalizedValue: Record<string, any> = {};\n for (const [op, opValue] of Object.entries(value)) {\n normalizedValue[op] = this.isOperator(op) ? this.translateOperator(op, opValue) : opValue;\n }\n result[newPath] = normalizedValue;\n } else {\n // For objects without operators, flatten them\n Object.assign(result, this.translateNode(value, newPath));\n }\n }\n } else {\n result[newPath] = this.translateNode(value);\n }\n }\n\n // Combine multiOperatorConditions with result if both exist\n if (multiOperatorConditions.length > 0) {\n // Convert result to array of conditions for $and\n const resultConditions = Object.entries(result).map(([key, value]) => ({ [key]: value }));\n const allConditions = [...multiOperatorConditions, ...resultConditions];\n\n if (allConditions.length === 1) {\n return allConditions[0];\n }\n return { $and: allConditions };\n }\n\n // Wrap in $and if there are multiple top-level fields\n if (Object.keys(result).length > 1 && !currentPath) {\n return {\n $and: Object.entries(result).map(([key, value]) => ({ [key]: value })),\n };\n }\n\n return result;\n }\n\n private translateOperator(operator: QueryOperator, value: any): any {\n // Handle logical operators\n if (this.isLogicalOperator(operator)) {\n return Array.isArray(value) ? value.map(item => this.translateNode(item)) : this.translateNode(value);\n }\n\n // Handle comparison and element operators\n return this.normalizeComparisonValue(value);\n }\n}\n","import { MastraError, ErrorDomain, ErrorCategory } from '@mastra/core/error';\nimport { createVectorErrorId } from '@mastra/core/storage';\nimport { MastraVector, validateUpsert, validateTopK } from '@mastra/core/vector';\nimport type {\n QueryResult,\n IndexStats,\n CreateIndexParams,\n UpsertVectorParams,\n QueryVectorParams,\n DescribeIndexParams,\n DeleteIndexParams,\n DeleteVectorParams,\n UpdateVectorParams,\n DeleteVectorsParams,\n} from '@mastra/core/vector';\nimport { ChromaClient, CloudClient } from 'chromadb';\nimport type { ChromaClientArgs, RecordSet, Where, WhereDocument, Collection, Metadata, Search } from 'chromadb';\nimport { distanceToScore } from './distance-to-score';\nimport type { ChromaVectorFilter } from './filter';\nimport { ChromaFilterTranslator } from './filter';\n\ninterface ChromaUpsertVectorParams extends UpsertVectorParams {\n documents?: string[];\n}\n\ninterface ChromaQueryVectorParams extends QueryVectorParams<ChromaVectorFilter> {\n documentFilter?: WhereDocument | null;\n}\n\ninterface ChromaGetRecordsParams {\n indexName: string;\n ids?: string[];\n filter?: ChromaVectorFilter;\n documentFilter?: WhereDocument | null;\n includeVector?: boolean;\n limit?: number;\n offset?: number;\n}\n\ntype MastraMetadata = {\n dimension?: number;\n};\n\ntype ChromaVectorArgs = ChromaClientArgs & { apiKey?: string };\n\nconst spaceMappings = {\n cosine: 'cosine',\n euclidean: 'l2',\n dotproduct: 'ip',\n l2: 'euclidean',\n ip: 'dotproduct',\n};\n\nexport class ChromaVector extends MastraVector<ChromaVectorFilter> {\n private client: ChromaClient;\n private collections: Map<string, Collection>;\n\n constructor({ id, ...chromaClientArgs }: ChromaVectorArgs & { id: string }) {\n super({ id });\n if (chromaClientArgs?.apiKey) {\n this.client = new CloudClient({\n apiKey: chromaClientArgs.apiKey,\n tenant: chromaClientArgs.tenant,\n database: chromaClientArgs.database,\n });\n } else {\n this.client = new ChromaClient(chromaClientArgs);\n }\n this.collections = new Map();\n }\n\n async getCollection({ indexName, forceUpdate = false }: { indexName: string; forceUpdate?: boolean }) {\n let collection = this.collections.get(indexName);\n if (forceUpdate || !collection) {\n try {\n collection = await this.client.getCollection({ name: indexName });\n this.collections.set(indexName, collection);\n return collection;\n } catch {\n throw new MastraError({\n id: createVectorErrorId('CHROMA', 'GET_COLLECTION', 'FAILED'),\n domain: ErrorDomain.MASTRA_VECTOR,\n category: ErrorCategory.THIRD_PARTY,\n details: { indexName },\n });\n }\n }\n return collection;\n }\n\n private validateVectorDimensions(vectors: number[][], dimension: number): void {\n for (let i = 0; i < vectors.length; i++) {\n if (vectors?.[i]?.length !== dimension) {\n throw new Error(\n `Vector at index ${i} has invalid dimension ${vectors?.[i]?.length}. Expected ${dimension} dimensions.`,\n );\n }\n }\n }\n\n async upsert({ indexName, vectors, metadata, ids, documents }: ChromaUpsertVectorParams): Promise<string[]> {\n // Validate input parameters and vector values\n validateUpsert('CHROMA', vectors, metadata, ids, true);\n\n try {\n const collection = await this.getCollection({ indexName });\n\n const stats = await this.describeIndex({ indexName });\n this.validateVectorDimensions(vectors, stats.dimension);\n const generatedIds = ids || vectors.map(() => crypto.randomUUID());\n\n await collection.upsert({\n ids: generatedIds,\n embeddings: vectors,\n metadatas: metadata,\n documents: documents,\n });\n\n return generatedIds;\n } catch (error: any) {\n if (error instanceof MastraError) throw error;\n throw new MastraError(\n {\n id: createVectorErrorId('CHROMA', 'UPSERT', 'FAILED'),\n domain: ErrorDomain.MASTRA_VECTOR,\n category: ErrorCategory.THIRD_PARTY,\n details: { indexName },\n },\n error,\n );\n }\n }\n\n async createIndex({ indexName, dimension, metric = 'cosine' }: CreateIndexParams): Promise<void> {\n if (!Number.isInteger(dimension) || dimension <= 0) {\n throw new MastraError({\n id: createVectorErrorId('CHROMA', 'CREATE_INDEX', 'INVALID_DIMENSION'),\n text: 'Dimension must be a positive integer',\n domain: ErrorDomain.MASTRA_VECTOR,\n category: ErrorCategory.USER,\n details: { dimension },\n });\n }\n\n const hnswSpace = spaceMappings[metric] as 'cosine' | 'l2' | 'ip' | undefined;\n\n if (!hnswSpace || !['cosine', 'l2', 'ip'].includes(hnswSpace)) {\n throw new MastraError({\n id: createVectorErrorId('CHROMA', 'CREATE_INDEX', 'INVALID_METRIC'),\n text: `Invalid metric: \"${metric}\". Must be one of: cosine, euclidean, dotproduct`,\n domain: ErrorDomain.MASTRA_VECTOR,\n category: ErrorCategory.USER,\n details: { metric },\n });\n }\n\n try {\n const collection = await this.client.createCollection({\n name: indexName,\n metadata: { dimension },\n configuration: { hnsw: { space: hnswSpace } },\n embeddingFunction: null,\n });\n this.collections.set(indexName, collection);\n } catch (error: any) {\n // Check for 'already exists' error\n const message = error?.message || error?.toString();\n if (message && message.toLowerCase().includes('already exists')) {\n // Fetch collection info and check dimension\n await this.validateExistingIndex(indexName, dimension, metric);\n return;\n }\n throw new MastraError(\n {\n id: createVectorErrorId('CHROMA', 'CREATE_INDEX', 'FAILED'),\n domain: ErrorDomain.MASTRA_VECTOR,\n category: ErrorCategory.THIRD_PARTY,\n details: { indexName },\n },\n error,\n );\n }\n }\n\n transformFilter(filter?: ChromaVectorFilter) {\n const translator = new ChromaFilterTranslator();\n const translatedFilter = translator.translate(filter);\n return translatedFilter ? (translatedFilter as Where) : undefined;\n }\n\n async query<T extends Metadata = Metadata>({\n indexName,\n queryVector,\n topK = 10,\n filter,\n includeVector = false,\n documentFilter,\n }: ChromaQueryVectorParams): Promise<QueryResult[]> {\n if (!queryVector) {\n throw new MastraError({\n id: createVectorErrorId('CHROMA', 'QUERY', 'MISSING_VECTOR'),\n text: 'queryVector is required for Chroma queries. Metadata-only queries are not supported by this vector store.',\n domain: ErrorDomain.MASTRA_VECTOR,\n category: ErrorCategory.USER,\n details: { indexName },\n });\n }\n\n // Validate topK parameter\n validateTopK('CHROMA', topK);\n\n try {\n const collection = await this.getCollection({ indexName });\n\n const defaultInclude: ['documents', 'metadatas', 'distances'] = ['documents', 'metadatas', 'distances'];\n\n const translatedFilter = this.transformFilter(filter);\n const results = await collection.query<T>({\n queryEmbeddings: [queryVector],\n nResults: topK,\n where: translatedFilter ?? undefined,\n whereDocument: documentFilter ?? undefined,\n include: includeVector ? [...defaultInclude, 'embeddings'] : defaultInclude,\n });\n\n const space = collection.configuration?.hnsw?.space || collection.configuration?.spann?.space || 'cosine';\n const metric = spaceMappings[space] as 'cosine' | 'euclidean' | 'dotproduct';\n\n return (results.ids[0] || []).map((id: string, index: number) => {\n const distance = results.distances?.[0]?.[index];\n const score = distance == null ? 0 : distanceToScore(distance, metric);\n return {\n id,\n score,\n metadata: results.metadatas?.[0]?.[index] || {},\n document: results.documents?.[0]?.[index] ?? undefined,\n ...(includeVector && { vector: results.embeddings?.[0]?.[index] || [] }),\n };\n });\n } catch (error: any) {\n if (error instanceof MastraError) throw error;\n throw new MastraError(\n {\n id: createVectorErrorId('CHROMA', 'QUERY', 'FAILED'),\n domain: ErrorDomain.MASTRA_VECTOR,\n category: ErrorCategory.THIRD_PARTY,\n details: { indexName },\n },\n error,\n );\n }\n }\n\n async hybridSearch({ indexName, search }: { indexName: string; search: Search }): Promise<QueryResult[]> {\n try {\n const collection = await this.getCollection({ indexName });\n const results = await collection.search(search);\n return (results.rows()[0] ?? []).map(record => ({\n id: record.id,\n score: record.score ?? 0,\n metadata: record.metadata ?? undefined,\n vector: record.embedding ?? undefined,\n document: record.document ?? undefined,\n }));\n } catch (error: any) {\n if (error instanceof MastraError) throw error;\n throw new MastraError(\n {\n id: createVectorErrorId('CHROMA', 'SEARCH_API', 'FAILED'),\n domain: ErrorDomain.MASTRA_VECTOR,\n category: ErrorCategory.THIRD_PARTY,\n details: { indexName },\n },\n error,\n );\n }\n }\n\n async get<T extends Metadata = Metadata>({\n indexName,\n ids,\n filter,\n includeVector = false,\n documentFilter,\n offset,\n limit,\n }: ChromaGetRecordsParams) {\n try {\n const collection = await this.getCollection({ indexName });\n\n const defaultInclude: ['documents', 'metadatas'] = ['documents', 'metadatas'];\n const translatedFilter = this.transformFilter(filter);\n\n const result = await collection.get<T>({\n ids,\n where: translatedFilter ?? undefined,\n whereDocument: documentFilter ?? undefined,\n offset,\n limit,\n include: includeVector ? [...defaultInclude, 'embeddings'] : defaultInclude,\n });\n return result.rows();\n } catch (error: any) {\n if (error instanceof MastraError) throw error;\n throw new MastraError(\n {\n id: createVectorErrorId('CHROMA', 'GET', 'FAILED'),\n domain: ErrorDomain.MASTRA_VECTOR,\n category: ErrorCategory.THIRD_PARTY,\n details: { indexName },\n },\n error,\n );\n }\n }\n\n async listIndexes(): Promise<string[]> {\n try {\n const collections = await this.client.listCollections();\n return collections.map(collection => collection.name);\n } catch (error: any) {\n throw new MastraError(\n {\n id: createVectorErrorId('CHROMA', 'LIST_INDEXES', 'FAILED'),\n domain: ErrorDomain.MASTRA_VECTOR,\n category: ErrorCategory.THIRD_PARTY,\n },\n error,\n );\n }\n }\n\n /**\n * Retrieves statistics about a vector index.\n *\n * @param {string} indexName - The name of the index to describe\n * @returns A promise that resolves to the index statistics including dimension, count and metric\n */\n async describeIndex({ indexName }: DescribeIndexParams): Promise<IndexStats> {\n try {\n const collection = await this.getCollection({ indexName });\n const count = await collection.count();\n const metadata = collection.metadata as MastraMetadata | undefined;\n const space = collection.configuration.hnsw?.space || collection.configuration.spann?.space || undefined;\n\n return {\n dimension: metadata?.dimension || 0,\n count,\n metric: space ? (spaceMappings[space] as 'cosine' | 'euclidean' | 'dotproduct') : undefined,\n };\n } catch (error: any) {\n if (error instanceof MastraError) throw error;\n throw new MastraError(\n {\n id: createVectorErrorId('CHROMA', 'DESCRIBE_INDEX', 'FAILED'),\n domain: ErrorDomain.MASTRA_VECTOR,\n category: ErrorCategory.THIRD_PARTY,\n details: { indexName },\n },\n error,\n );\n }\n }\n\n async deleteIndex({ indexName }: DeleteIndexParams): Promise<void> {\n try {\n await this.client.deleteCollection({ name: indexName });\n this.collections.delete(indexName);\n } catch (error: any) {\n throw new MastraError(\n {\n id: createVectorErrorId('CHROMA', 'DELETE_INDEX', 'FAILED'),\n domain: ErrorDomain.MASTRA_VECTOR,\n category: ErrorCategory.THIRD_PARTY,\n details: { indexName },\n },\n error,\n );\n }\n }\n\n async forkIndex({ indexName, newIndexName }: { indexName: string; newIndexName: string }): Promise<void> {\n try {\n const collection = await this.getCollection({ indexName, forceUpdate: true });\n const forkedCollection = await collection.fork({ name: newIndexName });\n this.collections.set(newIndexName, forkedCollection);\n } catch (error: any) {\n if (error instanceof MastraError) throw error;\n throw new MastraError(\n {\n id: createVectorErrorId('CHROMA', 'FORK_INDEX', 'FAILED'),\n domain: ErrorDomain.MASTRA_VECTOR,\n category: ErrorCategory.THIRD_PARTY,\n details: { indexName },\n },\n error,\n );\n }\n }\n\n /**\n * Updates a vector by its ID or multiple vectors matching a filter.\n * @param indexName - The name of the index containing the vector(s).\n * @param id - The ID of the vector to update (mutually exclusive with filter).\n * @param filter - Filter to match multiple vectors to update (mutually exclusive with id).\n * @param update - An object containing the vector and/or metadata to update.\n * @param update.vector - An optional array of numbers representing the new vector.\n * @param update.metadata - An optional record containing the new metadata.\n * @returns A promise that resolves when the update is complete.\n * @throws Will throw an error if no updates are provided or if the update operation fails.\n */\n async updateVector({ indexName, id, filter, update }: UpdateVectorParams<ChromaVectorFilter>): Promise<void> {\n // Validate mutually exclusive parameters\n if (id && filter) {\n throw new MastraError({\n id: createVectorErrorId('CHROMA', 'UPDATE_VECTOR', 'MUTUALLY_EXCLUSIVE'),\n text: 'Cannot specify both id and filter - they are mutually exclusive',\n domain: ErrorDomain.MASTRA_VECTOR,\n category: ErrorCategory.USER,\n details: { indexName },\n });\n }\n\n if (!id && !filter) {\n throw new MastraError({\n id: createVectorErrorId('CHROMA', 'UPDATE_VECTOR', 'NO_TARGET'),\n text: 'Either id or filter must be provided',\n domain: ErrorDomain.MASTRA_VECTOR,\n category: ErrorCategory.USER,\n details: { indexName },\n });\n }\n\n if (!update.vector && !update.metadata) {\n throw new MastraError({\n id: createVectorErrorId('CHROMA', 'UPDATE_VECTOR', 'NO_PAYLOAD'),\n text: 'No updates provided',\n domain: ErrorDomain.MASTRA_VECTOR,\n category: ErrorCategory.USER,\n details: {\n indexName,\n ...(id && { id }),\n },\n });\n }\n\n // Validate filter is not empty\n if (filter && Object.keys(filter).length === 0) {\n throw new MastraError({\n id: createVectorErrorId('CHROMA', 'UPDATE_VECTOR', 'EMPTY_FILTER'),\n text: 'Filter cannot be an empty filter object',\n domain: ErrorDomain.MASTRA_VECTOR,\n category: ErrorCategory.USER,\n details: { indexName },\n });\n }\n\n try {\n const collection: Collection = await this.getCollection({ indexName });\n\n // Validate vector dimensions if provided\n if (update?.vector) {\n const stats = await this.describeIndex({ indexName });\n this.validateVectorDimensions([update.vector], stats.dimension);\n }\n\n if (id) {\n // Update single vector by ID\n const updateRecordSet: RecordSet = { ids: [id] };\n\n if (update?.vector) {\n updateRecordSet.embeddings = [update.vector];\n }\n\n if (update?.metadata) {\n updateRecordSet.metadatas = [update.metadata];\n }\n\n return await collection.update(updateRecordSet);\n } else if (filter) {\n // Update multiple vectors matching filter\n // First, get all vectors matching the filter\n const translatedFilter = this.transformFilter(filter);\n const matchingVectors = await collection.get({\n where: translatedFilter ?? undefined,\n include: ['embeddings', 'metadatas'],\n });\n\n const vectorRows = matchingVectors.rows();\n if (vectorRows.length === 0) {\n // No vectors to update - this is not an error\n return;\n }\n\n // Prepare update for all matching vectors\n const updateRecordSet: RecordSet = {\n ids: vectorRows.map(row => row.id),\n };\n\n if (update?.vector) {\n // Use the same new vector for all matching records\n updateRecordSet.embeddings = vectorRows.map(() => update.vector!);\n }\n\n if (update?.metadata) {\n // Use the same new metadata for all matching records\n updateRecordSet.metadatas = vectorRows.map(() => update.metadata!);\n }\n\n return await collection.update(updateRecordSet);\n }\n } catch (error: any) {\n if (error instanceof MastraError) throw error;\n throw new MastraError(\n {\n id: createVectorErrorId('CHROMA', 'UPDATE_VECTOR', 'FAILED'),\n domain: ErrorDomain.MASTRA_VECTOR,\n category: ErrorCategory.THIRD_PARTY,\n details: {\n indexName,\n ...(id && { id }),\n ...(filter && { filter: JSON.stringify(filter) }),\n },\n },\n error,\n );\n }\n }\n\n async deleteVector({ indexName, id }: DeleteVectorParams): Promise<void> {\n try {\n const collection: Collection = await this.getCollection({ indexName });\n await collection.delete({ ids: [id] });\n } catch (error: any) {\n if (error instanceof MastraError) throw error;\n throw new MastraError(\n {\n id: createVectorErrorId('CHROMA', 'DELETE_VECTOR', 'FAILED'),\n domain: ErrorDomain.MASTRA_VECTOR,\n category: ErrorCategory.THIRD_PARTY,\n details: {\n indexName,\n ...(id && { id }),\n },\n },\n error,\n );\n }\n }\n\n /**\n * Deletes multiple vectors by IDs or filter.\n * @param indexName - The name of the index containing the vectors.\n * @param ids - Array of vector IDs to delete (mutually exclusive with filter).\n * @param filter - Filter to match vectors to delete (mutually exclusive with ids).\n * @returns A promise that resolves when the deletion is complete.\n * @throws Will throw an error if both ids and filter are provided, or if neither is provided.\n */\n async deleteVectors({ indexName, filter, ids }: DeleteVectorsParams<ChromaVectorFilter>): Promise<void> {\n // Validate mutually exclusive parameters\n if (ids && filter) {\n throw new MastraError({\n id: createVectorErrorId('CHROMA', 'DELETE_VECTORS', 'MUTUALLY_EXCLUSIVE'),\n text: 'Cannot specify both ids and filter - they are mutually exclusive',\n domain: ErrorDomain.MASTRA_VECTOR,\n category: ErrorCategory.USER,\n details: { indexName },\n });\n }\n\n if (!ids && !filter) {\n throw new MastraError({\n id: createVectorErrorId('CHROMA', 'DELETE_VECTORS', 'NO_TARGET'),\n text: 'Either filter or ids must be provided',\n domain: ErrorDomain.MASTRA_VECTOR,\n category: ErrorCategory.USER,\n details: { indexName },\n });\n }\n\n // Validate ids array is not empty\n if (ids && ids.length === 0) {\n throw new MastraError({\n id: createVectorErrorId('CHROMA', 'DELETE_VECTORS', 'EMPTY_IDS'),\n text: 'Cannot delete with empty ids array',\n domain: ErrorDomain.MASTRA_VECTOR,\n category: ErrorCategory.USER,\n details: { indexName },\n });\n }\n\n // Validate filter is not empty\n if (filter && Object.keys(filter).length === 0) {\n throw new MastraError({\n id: createVectorErrorId('CHROMA', 'DELETE_VECTORS', 'EMPTY_FILTER'),\n text: 'Cannot delete with empty filter object',\n domain: ErrorDomain.MASTRA_VECTOR,\n category: ErrorCategory.USER,\n details: { indexName },\n });\n }\n\n try {\n const collection: Collection = await this.getCollection({ indexName });\n\n if (ids) {\n // Delete by IDs\n await collection.delete({ ids });\n } else if (filter) {\n // Delete by filter\n const translatedFilter = this.transformFilter(filter);\n await collection.delete({\n where: translatedFilter ?? undefined,\n });\n }\n } catch (error: any) {\n if (error instanceof MastraError) throw error;\n throw new MastraError(\n {\n id: createVectorErrorId('CHROMA', 'DELETE_VECTORS', 'FAILED'),\n domain: ErrorDomain.MASTRA_VECTOR,\n category: ErrorCategory.THIRD_PARTY,\n details: {\n indexName,\n ...(filter && { filter: JSON.stringify(filter) }),\n ...(ids && { idsCount: ids.length }),\n },\n },\n error,\n );\n }\n }\n}\n","/**\n * Vector store specific prompt that details supported operators and examples.\n * This prompt helps users construct valid filters for Chroma Vector.\n */\nexport const CHROMA_PROMPT = `When querying Chroma, 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\nLogical Operators:\n- $and: Logical AND\n Example: { \"$and\": [{ \"price\": { \"$gt\": 100 } }, { \"category\": \"electronics\" }] }\n- $or: Logical OR\n Example: { \"$or\": [{ \"price\": { \"$lt\": 50 } }, { \"category\": \"books\" }] }\n\nRestrictions:\n- Regex patterns are not supported\n- Element operators are not supported\n- Only $and and $or logical operators are supported\n- Nested fields are supported using dot notation\n- Multiple conditions on the same field are supported with both implicit and explicit $and\n- Empty arrays in $in/$nin will return no results\n- If multiple top-level fields exist, they're wrapped in $and\n- Only logical operators ($and, $or) can be used at the top level\n- All other operators must be used within a field condition\n Valid: { \"field\": { \"$gt\": 100 } }\n Valid: { \"$and\": [...] }\n Invalid: { \"$gt\": 100 }\n Invalid: { \"$in\": [...] }\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\": [{...}] } } }\n\nExample Complex Query:\n{\n \"$and\": [\n { \"category\": { \"$in\": [\"electronics\", \"computers\"] } },\n { \"price\": { \"$gte\": 100, \"$lte\": 1000 } },\n { \"$or\": [\n { \"inStock\": true },\n { \"preorder\": true }\n ]}\n ]\n}`;\n"],"mappings":";;;;;;;AAAA,SAAgB,gBAAgB,UAAkB,QAAuD;CACvG,QAAQ,QAAR;EACE,KAAK,aACH,OAAO,KAAK,IAAI,KAAK,KAAK,QAAQ;EAGpC,SACE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/D,MAAM;GACN,QAAQC,mBAAAA,YAAY;GACpB,UAAUC,mBAAAA,cAAc;GACxB,SAAS,EAAE,UAAU;EACvB,CAAC;EAIH,IAAI,UAAU,OAAO,KAAK,MAAM,CAAC,CAAC,WAAW,GAC3C,MAAM,IAAIH,mBAAAA,YAAY;GACpB,KAAA,GAAIC,qBAAAA,oBAAAA,CAAoB,UAAU,kBAAkB,cAAc;GAClE,MAAM;GACN,QAAQC,mBAAAA,YAAY;GACpB,UAAUC,mBAAAA,cAAc;GACxB,SAAS,EAAE,UAAU;EACvB,CAAC;EAGH,IAAI;GACF,MAAM,aAAyB,MAAM,KAAK,cAAc,EAAE,UAAU,CAAC;GAErE,IAAI,KAEF,MAAM,WAAW,OAAO,EAAE,IAAI,CAAC;QAC1B,IAAI,QAAQ;IAEjB,MAAM,mBAAmB,KAAK,gBAAgB,MAAM;IACpD,MAAM,WAAW,OAAO,EACtB,OAAO,oBAAoB,KAAA,EAC7B,CAAC;GACH;EACF,SAAS,OAAY;GACnB,IAAI,iBAAiBH,mBAAAA,aAAa,MAAM;GACxC,MAAM,IAAIA,mBAAAA,YACR;IACE,KAAA,GAAIC,qBAAAA,oBAAAA,CAAoB,UAAU,kBAAkB,QAAQ;IAC5D,QAAQC,mBAAAA,YAAY;IACpB,UAAUC,mBAAAA,cAAc;IACxB,SAAS;KACP;KACA,GAAI,UAAU,EAAE,QAAQ,KAAK,UAAU,MAAM,EAAE;KAC/C,GAAI,OAAO,EAAE,UAAU,IAAI,OAAO;IACpC;GACF,GACA,KACF;EACF;CACF;AACF;;;;;;ACpnBA,MAAa,gBAAgB"}
package/dist/index.js CHANGED
@@ -3,15 +3,14 @@ import { createVectorErrorId } from "@mastra/core/storage";
3
3
  import { MastraVector, validateTopK, validateUpsert } from "@mastra/core/vector";
4
4
  import { ChromaClient, CloudClient } from "chromadb";
5
5
  import { BaseFilterTranslator } from "@mastra/core/vector/filter";
6
- //#region src/vector/distance-to-score.ts
6
+ // src/vector/distance-to-score.ts
7
7
  function distanceToScore(distance, metric) {
8
8
  switch (metric) {
9
9
  case "euclidean": return 1 / (1 + Math.sqrt(distance));
10
10
  default: return 1 - distance;
11
11
  }
12
12
  }
13
- //#endregion
14
- //#region src/vector/filter.ts
13
+ // src/vector/filter.ts
15
14
  /**
16
15
  * Translator for Chroma filter queries.
17
16
  * Maintains MongoDB-compatible syntax while ensuring proper validation
@@ -83,8 +82,7 @@ var ChromaFilterTranslator = class extends BaseFilterTranslator {
83
82
  return this.normalizeComparisonValue(value);
84
83
  }
85
84
  };
86
- //#endregion
87
- //#region src/vector/index.ts
85
+ // src/vector/index.ts
88
86
  const spaceMappings = {
89
87
  cosine: "cosine",
90
88
  euclidean: "l2",
@@ -505,8 +503,7 @@ var ChromaVector = class extends MastraVector {
505
503
  }
506
504
  }
507
505
  };
508
- //#endregion
509
- //#region src/vector/prompt.ts
506
+ // src/vector/prompt.ts
510
507
  /**
511
508
  * Vector store specific prompt that details supported operators and examples.
512
509
  * This prompt helps users construct valid filters for Chroma Vector.
@@ -579,7 +576,6 @@ Example Complex Query:
579
576
  ]}
580
577
  ]
581
578
  }`;
582
- //#endregion
583
579
  export { CHROMA_PROMPT, ChromaVector };
584
580
 
585
581
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":[],"sources":["../src/vector/distance-to-score.ts","../src/vector/filter.ts","../src/vector/index.ts","../src/vector/prompt.ts"],"sourcesContent":["export function distanceToScore(distance: number, metric: 'cosine' | 'euclidean' | 'dotproduct'): number {\n switch (metric) {\n case 'euclidean':\n return 1 / (1 + Math.sqrt(distance));\n case 'dotproduct':\n case 'cosine':\n default:\n return 1 - distance;\n }\n}\n","import { BaseFilterTranslator } from '@mastra/core/vector/filter';\nimport type {\n VectorFilter,\n OperatorSupport,\n QueryOperator,\n OperatorValueMap,\n LogicalOperatorValueMap,\n BlacklistedRootOperators,\n} from '@mastra/core/vector/filter';\n\ntype ChromaOperatorValueMap = Omit<OperatorValueMap, '$exists' | '$elemMatch' | '$regex' | '$options'>;\n\ntype ChromaLogicalOperatorValueMap = Omit<LogicalOperatorValueMap, '$nor' | '$not'>;\n\ntype ChromaBlacklisted = BlacklistedRootOperators | '$nor' | '$not';\n\nexport type ChromaVectorFilter = VectorFilter<\n keyof ChromaOperatorValueMap,\n ChromaOperatorValueMap,\n ChromaLogicalOperatorValueMap,\n ChromaBlacklisted\n>;\n\n/**\n * Translator for Chroma filter queries.\n * Maintains MongoDB-compatible syntax while ensuring proper validation\n * and normalization of values.\n */\nexport class ChromaFilterTranslator extends BaseFilterTranslator<ChromaVectorFilter> {\n protected override getSupportedOperators(): OperatorSupport {\n return {\n ...BaseFilterTranslator.DEFAULT_OPERATORS,\n logical: ['$and', '$or'],\n array: ['$in', '$nin'],\n element: [],\n regex: [],\n custom: [],\n };\n }\n\n translate(filter?: ChromaVectorFilter): ChromaVectorFilter {\n if (this.isEmpty(filter)) return filter;\n this.validateFilter(filter);\n\n return this.translateNode(filter);\n }\n\n private translateNode(node: ChromaVectorFilter, currentPath: string = ''): any {\n // Handle primitive values and arrays\n if (this.isRegex(node)) {\n throw new Error('Regex is supported in Chroma via the `documentFilter` argument');\n }\n if (this.isPrimitive(node)) return this.normalizeComparisonValue(node);\n if (Array.isArray(node)) return { $in: this.normalizeArrayValues(node) };\n\n const entries = Object.entries(node as Record<string, any>);\n const firstEntry = entries[0];\n // Handle single operator case\n if (entries.length === 1 && firstEntry && this.isOperator(firstEntry[0])) {\n const [operator, value] = firstEntry;\n const translated = this.translateOperator(operator, value);\n if (this.isLogicalOperator(operator) && Array.isArray(translated) && translated.length === 1) {\n return translated[0];\n }\n return this.isLogicalOperator(operator) ? { [operator]: translated } : translated;\n }\n\n // Process each entry\n const result: Record<string, any> = {};\n const multiOperatorConditions: any[] = [];\n\n for (const [key, value] of entries) {\n const newPath = currentPath ? `${currentPath}.${key}` : key;\n\n if (this.isOperator(key)) {\n result[key] = this.translateOperator(key, value);\n continue;\n }\n\n if (typeof value === 'object' && value !== null && !Array.isArray(value)) {\n // Check for multiple operators on same field\n const valueEntries = Object.entries(value);\n if (valueEntries.every(([op]) => this.isOperator(op)) && valueEntries.length > 1) {\n valueEntries.forEach(([op, opValue]) => {\n multiOperatorConditions.push({\n [newPath]: { [op]: this.normalizeComparisonValue(opValue) },\n });\n });\n continue;\n }\n\n // Check if the nested object contains operators\n if (Object.keys(value).length === 0) {\n result[newPath] = this.translateNode(value);\n } else {\n const hasOperators = Object.keys(value).some(k => this.isOperator(k));\n if (hasOperators) {\n // For objects with operators, normalize each operator value\n const normalizedValue: Record<string, any> = {};\n for (const [op, opValue] of Object.entries(value)) {\n normalizedValue[op] = this.isOperator(op) ? this.translateOperator(op, opValue) : opValue;\n }\n result[newPath] = normalizedValue;\n } else {\n // For objects without operators, flatten them\n Object.assign(result, this.translateNode(value, newPath));\n }\n }\n } else {\n result[newPath] = this.translateNode(value);\n }\n }\n\n // Combine multiOperatorConditions with result if both exist\n if (multiOperatorConditions.length > 0) {\n // Convert result to array of conditions for $and\n const resultConditions = Object.entries(result).map(([key, value]) => ({ [key]: value }));\n const allConditions = [...multiOperatorConditions, ...resultConditions];\n\n if (allConditions.length === 1) {\n return allConditions[0];\n }\n return { $and: allConditions };\n }\n\n // Wrap in $and if there are multiple top-level fields\n if (Object.keys(result).length > 1 && !currentPath) {\n return {\n $and: Object.entries(result).map(([key, value]) => ({ [key]: value })),\n };\n }\n\n return result;\n }\n\n private translateOperator(operator: QueryOperator, value: any): any {\n // Handle logical operators\n if (this.isLogicalOperator(operator)) {\n return Array.isArray(value) ? value.map(item => this.translateNode(item)) : this.translateNode(value);\n }\n\n // Handle comparison and element operators\n return this.normalizeComparisonValue(value);\n }\n}\n","import { MastraError, ErrorDomain, ErrorCategory } from '@mastra/core/error';\nimport { createVectorErrorId } from '@mastra/core/storage';\nimport { MastraVector, validateUpsert, validateTopK } from '@mastra/core/vector';\nimport type {\n QueryResult,\n IndexStats,\n CreateIndexParams,\n UpsertVectorParams,\n QueryVectorParams,\n DescribeIndexParams,\n DeleteIndexParams,\n DeleteVectorParams,\n UpdateVectorParams,\n DeleteVectorsParams,\n} from '@mastra/core/vector';\nimport { ChromaClient, CloudClient } from 'chromadb';\nimport type { ChromaClientArgs, RecordSet, Where, WhereDocument, Collection, Metadata, Search } from 'chromadb';\nimport { distanceToScore } from './distance-to-score';\nimport type { ChromaVectorFilter } from './filter';\nimport { ChromaFilterTranslator } from './filter';\n\ninterface ChromaUpsertVectorParams extends UpsertVectorParams {\n documents?: string[];\n}\n\ninterface ChromaQueryVectorParams extends QueryVectorParams<ChromaVectorFilter> {\n documentFilter?: WhereDocument | null;\n}\n\ninterface ChromaGetRecordsParams {\n indexName: string;\n ids?: string[];\n filter?: ChromaVectorFilter;\n documentFilter?: WhereDocument | null;\n includeVector?: boolean;\n limit?: number;\n offset?: number;\n}\n\ntype MastraMetadata = {\n dimension?: number;\n};\n\ntype ChromaVectorArgs = ChromaClientArgs & { apiKey?: string };\n\nconst spaceMappings = {\n cosine: 'cosine',\n euclidean: 'l2',\n dotproduct: 'ip',\n l2: 'euclidean',\n ip: 'dotproduct',\n};\n\nexport class ChromaVector extends MastraVector<ChromaVectorFilter> {\n private client: ChromaClient;\n private collections: Map<string, Collection>;\n\n constructor({ id, ...chromaClientArgs }: ChromaVectorArgs & { id: string }) {\n super({ id });\n if (chromaClientArgs?.apiKey) {\n this.client = new CloudClient({\n apiKey: chromaClientArgs.apiKey,\n tenant: chromaClientArgs.tenant,\n database: chromaClientArgs.database,\n });\n } else {\n this.client = new ChromaClient(chromaClientArgs);\n }\n this.collections = new Map();\n }\n\n async getCollection({ indexName, forceUpdate = false }: { indexName: string; forceUpdate?: boolean }) {\n let collection = this.collections.get(indexName);\n if (forceUpdate || !collection) {\n try {\n collection = await this.client.getCollection({ name: indexName });\n this.collections.set(indexName, collection);\n return collection;\n } catch {\n throw new MastraError({\n id: createVectorErrorId('CHROMA', 'GET_COLLECTION', 'FAILED'),\n domain: ErrorDomain.MASTRA_VECTOR,\n category: ErrorCategory.THIRD_PARTY,\n details: { indexName },\n });\n }\n }\n return collection;\n }\n\n private validateVectorDimensions(vectors: number[][], dimension: number): void {\n for (let i = 0; i < vectors.length; i++) {\n if (vectors?.[i]?.length !== dimension) {\n throw new Error(\n `Vector at index ${i} has invalid dimension ${vectors?.[i]?.length}. Expected ${dimension} dimensions.`,\n );\n }\n }\n }\n\n async upsert({ indexName, vectors, metadata, ids, documents }: ChromaUpsertVectorParams): Promise<string[]> {\n // Validate input parameters and vector values\n validateUpsert('CHROMA', vectors, metadata, ids, true);\n\n try {\n const collection = await this.getCollection({ indexName });\n\n const stats = await this.describeIndex({ indexName });\n this.validateVectorDimensions(vectors, stats.dimension);\n const generatedIds = ids || vectors.map(() => crypto.randomUUID());\n\n await collection.upsert({\n ids: generatedIds,\n embeddings: vectors,\n metadatas: metadata,\n documents: documents,\n });\n\n return generatedIds;\n } catch (error: any) {\n if (error instanceof MastraError) throw error;\n throw new MastraError(\n {\n id: createVectorErrorId('CHROMA', 'UPSERT', 'FAILED'),\n domain: ErrorDomain.MASTRA_VECTOR,\n category: ErrorCategory.THIRD_PARTY,\n details: { indexName },\n },\n error,\n );\n }\n }\n\n async createIndex({ indexName, dimension, metric = 'cosine' }: CreateIndexParams): Promise<void> {\n if (!Number.isInteger(dimension) || dimension <= 0) {\n throw new MastraError({\n id: createVectorErrorId('CHROMA', 'CREATE_INDEX', 'INVALID_DIMENSION'),\n text: 'Dimension must be a positive integer',\n domain: ErrorDomain.MASTRA_VECTOR,\n category: ErrorCategory.USER,\n details: { dimension },\n });\n }\n\n const hnswSpace = spaceMappings[metric] as 'cosine' | 'l2' | 'ip' | undefined;\n\n if (!hnswSpace || !['cosine', 'l2', 'ip'].includes(hnswSpace)) {\n throw new MastraError({\n id: createVectorErrorId('CHROMA', 'CREATE_INDEX', 'INVALID_METRIC'),\n text: `Invalid metric: \"${metric}\". Must be one of: cosine, euclidean, dotproduct`,\n domain: ErrorDomain.MASTRA_VECTOR,\n category: ErrorCategory.USER,\n details: { metric },\n });\n }\n\n try {\n const collection = await this.client.createCollection({\n name: indexName,\n metadata: { dimension },\n configuration: { hnsw: { space: hnswSpace } },\n embeddingFunction: null,\n });\n this.collections.set(indexName, collection);\n } catch (error: any) {\n // Check for 'already exists' error\n const message = error?.message || error?.toString();\n if (message && message.toLowerCase().includes('already exists')) {\n // Fetch collection info and check dimension\n await this.validateExistingIndex(indexName, dimension, metric);\n return;\n }\n throw new MastraError(\n {\n id: createVectorErrorId('CHROMA', 'CREATE_INDEX', 'FAILED'),\n domain: ErrorDomain.MASTRA_VECTOR,\n category: ErrorCategory.THIRD_PARTY,\n details: { indexName },\n },\n error,\n );\n }\n }\n\n transformFilter(filter?: ChromaVectorFilter) {\n const translator = new ChromaFilterTranslator();\n const translatedFilter = translator.translate(filter);\n return translatedFilter ? (translatedFilter as Where) : undefined;\n }\n\n async query<T extends Metadata = Metadata>({\n indexName,\n queryVector,\n topK = 10,\n filter,\n includeVector = false,\n documentFilter,\n }: ChromaQueryVectorParams): Promise<QueryResult[]> {\n if (!queryVector) {\n throw new MastraError({\n id: createVectorErrorId('CHROMA', 'QUERY', 'MISSING_VECTOR'),\n text: 'queryVector is required for Chroma queries. Metadata-only queries are not supported by this vector store.',\n domain: ErrorDomain.MASTRA_VECTOR,\n category: ErrorCategory.USER,\n details: { indexName },\n });\n }\n\n // Validate topK parameter\n validateTopK('CHROMA', topK);\n\n try {\n const collection = await this.getCollection({ indexName });\n\n const defaultInclude: ['documents', 'metadatas', 'distances'] = ['documents', 'metadatas', 'distances'];\n\n const translatedFilter = this.transformFilter(filter);\n const results = await collection.query<T>({\n queryEmbeddings: [queryVector],\n nResults: topK,\n where: translatedFilter ?? undefined,\n whereDocument: documentFilter ?? undefined,\n include: includeVector ? [...defaultInclude, 'embeddings'] : defaultInclude,\n });\n\n const space = collection.configuration?.hnsw?.space || collection.configuration?.spann?.space || 'cosine';\n const metric = spaceMappings[space] as 'cosine' | 'euclidean' | 'dotproduct';\n\n return (results.ids[0] || []).map((id: string, index: number) => {\n const distance = results.distances?.[0]?.[index];\n const score = distance == null ? 0 : distanceToScore(distance, metric);\n return {\n id,\n score,\n metadata: results.metadatas?.[0]?.[index] || {},\n document: results.documents?.[0]?.[index] ?? undefined,\n ...(includeVector && { vector: results.embeddings?.[0]?.[index] || [] }),\n };\n });\n } catch (error: any) {\n if (error instanceof MastraError) throw error;\n throw new MastraError(\n {\n id: createVectorErrorId('CHROMA', 'QUERY', 'FAILED'),\n domain: ErrorDomain.MASTRA_VECTOR,\n category: ErrorCategory.THIRD_PARTY,\n details: { indexName },\n },\n error,\n );\n }\n }\n\n async hybridSearch({ indexName, search }: { indexName: string; search: Search }): Promise<QueryResult[]> {\n try {\n const collection = await this.getCollection({ indexName });\n const results = await collection.search(search);\n return (results.rows()[0] ?? []).map(record => ({\n id: record.id,\n score: record.score ?? 0,\n metadata: record.metadata ?? undefined,\n vector: record.embedding ?? undefined,\n document: record.document ?? undefined,\n }));\n } catch (error: any) {\n if (error instanceof MastraError) throw error;\n throw new MastraError(\n {\n id: createVectorErrorId('CHROMA', 'SEARCH_API', 'FAILED'),\n domain: ErrorDomain.MASTRA_VECTOR,\n category: ErrorCategory.THIRD_PARTY,\n details: { indexName },\n },\n error,\n );\n }\n }\n\n async get<T extends Metadata = Metadata>({\n indexName,\n ids,\n filter,\n includeVector = false,\n documentFilter,\n offset,\n limit,\n }: ChromaGetRecordsParams) {\n try {\n const collection = await this.getCollection({ indexName });\n\n const defaultInclude: ['documents', 'metadatas'] = ['documents', 'metadatas'];\n const translatedFilter = this.transformFilter(filter);\n\n const result = await collection.get<T>({\n ids,\n where: translatedFilter ?? undefined,\n whereDocument: documentFilter ?? undefined,\n offset,\n limit,\n include: includeVector ? [...defaultInclude, 'embeddings'] : defaultInclude,\n });\n return result.rows();\n } catch (error: any) {\n if (error instanceof MastraError) throw error;\n throw new MastraError(\n {\n id: createVectorErrorId('CHROMA', 'GET', 'FAILED'),\n domain: ErrorDomain.MASTRA_VECTOR,\n category: ErrorCategory.THIRD_PARTY,\n details: { indexName },\n },\n error,\n );\n }\n }\n\n async listIndexes(): Promise<string[]> {\n try {\n const collections = await this.client.listCollections();\n return collections.map(collection => collection.name);\n } catch (error: any) {\n throw new MastraError(\n {\n id: createVectorErrorId('CHROMA', 'LIST_INDEXES', 'FAILED'),\n domain: ErrorDomain.MASTRA_VECTOR,\n category: ErrorCategory.THIRD_PARTY,\n },\n error,\n );\n }\n }\n\n /**\n * Retrieves statistics about a vector index.\n *\n * @param {string} indexName - The name of the index to describe\n * @returns A promise that resolves to the index statistics including dimension, count and metric\n */\n async describeIndex({ indexName }: DescribeIndexParams): Promise<IndexStats> {\n try {\n const collection = await this.getCollection({ indexName });\n const count = await collection.count();\n const metadata = collection.metadata as MastraMetadata | undefined;\n const space = collection.configuration.hnsw?.space || collection.configuration.spann?.space || undefined;\n\n return {\n dimension: metadata?.dimension || 0,\n count,\n metric: space ? (spaceMappings[space] as 'cosine' | 'euclidean' | 'dotproduct') : undefined,\n };\n } catch (error: any) {\n if (error instanceof MastraError) throw error;\n throw new MastraError(\n {\n id: createVectorErrorId('CHROMA', 'DESCRIBE_INDEX', 'FAILED'),\n domain: ErrorDomain.MASTRA_VECTOR,\n category: ErrorCategory.THIRD_PARTY,\n details: { indexName },\n },\n error,\n );\n }\n }\n\n async deleteIndex({ indexName }: DeleteIndexParams): Promise<void> {\n try {\n await this.client.deleteCollection({ name: indexName });\n this.collections.delete(indexName);\n } catch (error: any) {\n throw new MastraError(\n {\n id: createVectorErrorId('CHROMA', 'DELETE_INDEX', 'FAILED'),\n domain: ErrorDomain.MASTRA_VECTOR,\n category: ErrorCategory.THIRD_PARTY,\n details: { indexName },\n },\n error,\n );\n }\n }\n\n async forkIndex({ indexName, newIndexName }: { indexName: string; newIndexName: string }): Promise<void> {\n try {\n const collection = await this.getCollection({ indexName, forceUpdate: true });\n const forkedCollection = await collection.fork({ name: newIndexName });\n this.collections.set(newIndexName, forkedCollection);\n } catch (error: any) {\n if (error instanceof MastraError) throw error;\n throw new MastraError(\n {\n id: createVectorErrorId('CHROMA', 'FORK_INDEX', 'FAILED'),\n domain: ErrorDomain.MASTRA_VECTOR,\n category: ErrorCategory.THIRD_PARTY,\n details: { indexName },\n },\n error,\n );\n }\n }\n\n /**\n * Updates a vector by its ID or multiple vectors matching a filter.\n * @param indexName - The name of the index containing the vector(s).\n * @param id - The ID of the vector to update (mutually exclusive with filter).\n * @param filter - Filter to match multiple vectors to update (mutually exclusive with id).\n * @param update - An object containing the vector and/or metadata to update.\n * @param update.vector - An optional array of numbers representing the new vector.\n * @param update.metadata - An optional record containing the new metadata.\n * @returns A promise that resolves when the update is complete.\n * @throws Will throw an error if no updates are provided or if the update operation fails.\n */\n async updateVector({ indexName, id, filter, update }: UpdateVectorParams<ChromaVectorFilter>): Promise<void> {\n // Validate mutually exclusive parameters\n if (id && filter) {\n throw new MastraError({\n id: createVectorErrorId('CHROMA', 'UPDATE_VECTOR', 'MUTUALLY_EXCLUSIVE'),\n text: 'Cannot specify both id and filter - they are mutually exclusive',\n domain: ErrorDomain.MASTRA_VECTOR,\n category: ErrorCategory.USER,\n details: { indexName },\n });\n }\n\n if (!id && !filter) {\n throw new MastraError({\n id: createVectorErrorId('CHROMA', 'UPDATE_VECTOR', 'NO_TARGET'),\n text: 'Either id or filter must be provided',\n domain: ErrorDomain.MASTRA_VECTOR,\n category: ErrorCategory.USER,\n details: { indexName },\n });\n }\n\n if (!update.vector && !update.metadata) {\n throw new MastraError({\n id: createVectorErrorId('CHROMA', 'UPDATE_VECTOR', 'NO_PAYLOAD'),\n text: 'No updates provided',\n domain: ErrorDomain.MASTRA_VECTOR,\n category: ErrorCategory.USER,\n details: {\n indexName,\n ...(id && { id }),\n },\n });\n }\n\n // Validate filter is not empty\n if (filter && Object.keys(filter).length === 0) {\n throw new MastraError({\n id: createVectorErrorId('CHROMA', 'UPDATE_VECTOR', 'EMPTY_FILTER'),\n text: 'Filter cannot be an empty filter object',\n domain: ErrorDomain.MASTRA_VECTOR,\n category: ErrorCategory.USER,\n details: { indexName },\n });\n }\n\n try {\n const collection: Collection = await this.getCollection({ indexName });\n\n // Validate vector dimensions if provided\n if (update?.vector) {\n const stats = await this.describeIndex({ indexName });\n this.validateVectorDimensions([update.vector], stats.dimension);\n }\n\n if (id) {\n // Update single vector by ID\n const updateRecordSet: RecordSet = { ids: [id] };\n\n if (update?.vector) {\n updateRecordSet.embeddings = [update.vector];\n }\n\n if (update?.metadata) {\n updateRecordSet.metadatas = [update.metadata];\n }\n\n return await collection.update(updateRecordSet);\n } else if (filter) {\n // Update multiple vectors matching filter\n // First, get all vectors matching the filter\n const translatedFilter = this.transformFilter(filter);\n const matchingVectors = await collection.get({\n where: translatedFilter ?? undefined,\n include: ['embeddings', 'metadatas'],\n });\n\n const vectorRows = matchingVectors.rows();\n if (vectorRows.length === 0) {\n // No vectors to update - this is not an error\n return;\n }\n\n // Prepare update for all matching vectors\n const updateRecordSet: RecordSet = {\n ids: vectorRows.map(row => row.id),\n };\n\n if (update?.vector) {\n // Use the same new vector for all matching records\n updateRecordSet.embeddings = vectorRows.map(() => update.vector!);\n }\n\n if (update?.metadata) {\n // Use the same new metadata for all matching records\n updateRecordSet.metadatas = vectorRows.map(() => update.metadata!);\n }\n\n return await collection.update(updateRecordSet);\n }\n } catch (error: any) {\n if (error instanceof MastraError) throw error;\n throw new MastraError(\n {\n id: createVectorErrorId('CHROMA', 'UPDATE_VECTOR', 'FAILED'),\n domain: ErrorDomain.MASTRA_VECTOR,\n category: ErrorCategory.THIRD_PARTY,\n details: {\n indexName,\n ...(id && { id }),\n ...(filter && { filter: JSON.stringify(filter) }),\n },\n },\n error,\n );\n }\n }\n\n async deleteVector({ indexName, id }: DeleteVectorParams): Promise<void> {\n try {\n const collection: Collection = await this.getCollection({ indexName });\n await collection.delete({ ids: [id] });\n } catch (error: any) {\n if (error instanceof MastraError) throw error;\n throw new MastraError(\n {\n id: createVectorErrorId('CHROMA', 'DELETE_VECTOR', 'FAILED'),\n domain: ErrorDomain.MASTRA_VECTOR,\n category: ErrorCategory.THIRD_PARTY,\n details: {\n indexName,\n ...(id && { id }),\n },\n },\n error,\n );\n }\n }\n\n /**\n * Deletes multiple vectors by IDs or filter.\n * @param indexName - The name of the index containing the vectors.\n * @param ids - Array of vector IDs to delete (mutually exclusive with filter).\n * @param filter - Filter to match vectors to delete (mutually exclusive with ids).\n * @returns A promise that resolves when the deletion is complete.\n * @throws Will throw an error if both ids and filter are provided, or if neither is provided.\n */\n async deleteVectors({ indexName, filter, ids }: DeleteVectorsParams<ChromaVectorFilter>): Promise<void> {\n // Validate mutually exclusive parameters\n if (ids && filter) {\n throw new MastraError({\n id: createVectorErrorId('CHROMA', 'DELETE_VECTORS', 'MUTUALLY_EXCLUSIVE'),\n text: 'Cannot specify both ids and filter - they are mutually exclusive',\n domain: ErrorDomain.MASTRA_VECTOR,\n category: ErrorCategory.USER,\n details: { indexName },\n });\n }\n\n if (!ids && !filter) {\n throw new MastraError({\n id: createVectorErrorId('CHROMA', 'DELETE_VECTORS', 'NO_TARGET'),\n text: 'Either filter or ids must be provided',\n domain: ErrorDomain.MASTRA_VECTOR,\n category: ErrorCategory.USER,\n details: { indexName },\n });\n }\n\n // Validate ids array is not empty\n if (ids && ids.length === 0) {\n throw new MastraError({\n id: createVectorErrorId('CHROMA', 'DELETE_VECTORS', 'EMPTY_IDS'),\n text: 'Cannot delete with empty ids array',\n domain: ErrorDomain.MASTRA_VECTOR,\n category: ErrorCategory.USER,\n details: { indexName },\n });\n }\n\n // Validate filter is not empty\n if (filter && Object.keys(filter).length === 0) {\n throw new MastraError({\n id: createVectorErrorId('CHROMA', 'DELETE_VECTORS', 'EMPTY_FILTER'),\n text: 'Cannot delete with empty filter object',\n domain: ErrorDomain.MASTRA_VECTOR,\n category: ErrorCategory.USER,\n details: { indexName },\n });\n }\n\n try {\n const collection: Collection = await this.getCollection({ indexName });\n\n if (ids) {\n // Delete by IDs\n await collection.delete({ ids });\n } else if (filter) {\n // Delete by filter\n const translatedFilter = this.transformFilter(filter);\n await collection.delete({\n where: translatedFilter ?? undefined,\n });\n }\n } catch (error: any) {\n if (error instanceof MastraError) throw error;\n throw new MastraError(\n {\n id: createVectorErrorId('CHROMA', 'DELETE_VECTORS', 'FAILED'),\n domain: ErrorDomain.MASTRA_VECTOR,\n category: ErrorCategory.THIRD_PARTY,\n details: {\n indexName,\n ...(filter && { filter: JSON.stringify(filter) }),\n ...(ids && { idsCount: ids.length }),\n },\n },\n error,\n );\n }\n }\n}\n","/**\n * Vector store specific prompt that details supported operators and examples.\n * This prompt helps users construct valid filters for Chroma Vector.\n */\nexport const CHROMA_PROMPT = `When querying Chroma, 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\nLogical Operators:\n- $and: Logical AND\n Example: { \"$and\": [{ \"price\": { \"$gt\": 100 } }, { \"category\": \"electronics\" }] }\n- $or: Logical OR\n Example: { \"$or\": [{ \"price\": { \"$lt\": 50 } }, { \"category\": \"books\" }] }\n\nRestrictions:\n- Regex patterns are not supported\n- Element operators are not supported\n- Only $and and $or logical operators are supported\n- Nested fields are supported using dot notation\n- Multiple conditions on the same field are supported with both implicit and explicit $and\n- Empty arrays in $in/$nin will return no results\n- If multiple top-level fields exist, they're wrapped in $and\n- Only logical operators ($and, $or) can be used at the top level\n- All other operators must be used within a field condition\n Valid: { \"field\": { \"$gt\": 100 } }\n Valid: { \"$and\": [...] }\n Invalid: { \"$gt\": 100 }\n Invalid: { \"$in\": [...] }\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\": [{...}] } } }\n\nExample Complex Query:\n{\n \"$and\": [\n { \"category\": { \"$in\": [\"electronics\", \"computers\"] } },\n { \"price\": { \"$gte\": 100, \"$lte\": 1000 } },\n { \"$or\": [\n { \"inStock\": true },\n { \"preorder\": true }\n ]}\n ]\n}`;\n"],"mappings":";;;;;;AAAA,SAAgB,gBAAgB,UAAkB,QAAuD;CACvG,QAAQ,QAAR;EACE,KAAK,aACH,OAAO,KAAK,IAAI,KAAK,KAAK,QAAQ;EAGpC,SACE,OAAO,IAAI;CACf;AACF;;;;;;;;ACmBA,IAAa,yBAAb,cAA4C,qBAAyC;CACnF,wBAA4D;EAC1D,OAAO;GACL,GAAG,qBAAqB;GACxB,SAAS,CAAC,QAAQ,KAAK;GACvB,OAAO,CAAC,OAAO,MAAM;GACrB,SAAS,CAAC;GACV,OAAO,CAAC;GACR,QAAQ,CAAC;EACX;CACF;CAEA,UAAU,QAAiD;EACzD,IAAI,KAAK,QAAQ,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,MAAM,KAAK,cAAc,EAAE,UAAU,CAAC;GAErE,IAAI,KAEF,MAAM,WAAW,OAAO,EAAE,IAAI,CAAC;QAC1B,IAAI,QAAQ;IAEjB,MAAM,mBAAmB,KAAK,gBAAgB,MAAM;IACpD,MAAM,WAAW,OAAO,EACtB,OAAO,oBAAoB,KAAA,EAC7B,CAAC;GACH;EACF,SAAS,OAAY;GACnB,IAAI,iBAAiB,aAAa,MAAM;GACxC,MAAM,IAAI,YACR;IACE,IAAI,oBAAoB,UAAU,kBAAkB,QAAQ;IAC5D,QAAQ,YAAY;IACpB,UAAU,cAAc;IACxB,SAAS;KACP;KACA,GAAI,UAAU,EAAE,QAAQ,KAAK,UAAU,MAAM,EAAE;KAC/C,GAAI,OAAO,EAAE,UAAU,IAAI,OAAO;IACpC;GACF,GACA,KACF;EACF;CACF;AACF;;;;;;;ACpnBA,MAAa,gBAAgB"}
1
+ {"version":3,"file":"index.js","names":[],"sources":["../src/vector/distance-to-score.ts","../src/vector/filter.ts","../src/vector/index.ts","../src/vector/prompt.ts"],"sourcesContent":["export function distanceToScore(distance: number, metric: 'cosine' | 'euclidean' | 'dotproduct'): number {\n switch (metric) {\n case 'euclidean':\n return 1 / (1 + Math.sqrt(distance));\n case 'dotproduct':\n case 'cosine':\n default:\n return 1 - distance;\n }\n}\n","import { BaseFilterTranslator } from '@mastra/core/vector/filter';\nimport type {\n VectorFilter,\n OperatorSupport,\n QueryOperator,\n OperatorValueMap,\n LogicalOperatorValueMap,\n BlacklistedRootOperators,\n} from '@mastra/core/vector/filter';\n\ntype ChromaOperatorValueMap = Omit<OperatorValueMap, '$exists' | '$elemMatch' | '$regex' | '$options'>;\n\ntype ChromaLogicalOperatorValueMap = Omit<LogicalOperatorValueMap, '$nor' | '$not'>;\n\ntype ChromaBlacklisted = BlacklistedRootOperators | '$nor' | '$not';\n\nexport type ChromaVectorFilter = VectorFilter<\n keyof ChromaOperatorValueMap,\n ChromaOperatorValueMap,\n ChromaLogicalOperatorValueMap,\n ChromaBlacklisted\n>;\n\n/**\n * Translator for Chroma filter queries.\n * Maintains MongoDB-compatible syntax while ensuring proper validation\n * and normalization of values.\n */\nexport class ChromaFilterTranslator extends BaseFilterTranslator<ChromaVectorFilter> {\n protected override getSupportedOperators(): OperatorSupport {\n return {\n ...BaseFilterTranslator.DEFAULT_OPERATORS,\n logical: ['$and', '$or'],\n array: ['$in', '$nin'],\n element: [],\n regex: [],\n custom: [],\n };\n }\n\n translate(filter?: ChromaVectorFilter): ChromaVectorFilter {\n if (this.isEmpty(filter)) return filter;\n this.validateFilter(filter);\n\n return this.translateNode(filter);\n }\n\n private translateNode(node: ChromaVectorFilter, currentPath: string = ''): any {\n // Handle primitive values and arrays\n if (this.isRegex(node)) {\n throw new Error('Regex is supported in Chroma via the `documentFilter` argument');\n }\n if (this.isPrimitive(node)) return this.normalizeComparisonValue(node);\n if (Array.isArray(node)) return { $in: this.normalizeArrayValues(node) };\n\n const entries = Object.entries(node as Record<string, any>);\n const firstEntry = entries[0];\n // Handle single operator case\n if (entries.length === 1 && firstEntry && this.isOperator(firstEntry[0])) {\n const [operator, value] = firstEntry;\n const translated = this.translateOperator(operator, value);\n if (this.isLogicalOperator(operator) && Array.isArray(translated) && translated.length === 1) {\n return translated[0];\n }\n return this.isLogicalOperator(operator) ? { [operator]: translated } : translated;\n }\n\n // Process each entry\n const result: Record<string, any> = {};\n const multiOperatorConditions: any[] = [];\n\n for (const [key, value] of entries) {\n const newPath = currentPath ? `${currentPath}.${key}` : key;\n\n if (this.isOperator(key)) {\n result[key] = this.translateOperator(key, value);\n continue;\n }\n\n if (typeof value === 'object' && value !== null && !Array.isArray(value)) {\n // Check for multiple operators on same field\n const valueEntries = Object.entries(value);\n if (valueEntries.every(([op]) => this.isOperator(op)) && valueEntries.length > 1) {\n valueEntries.forEach(([op, opValue]) => {\n multiOperatorConditions.push({\n [newPath]: { [op]: this.normalizeComparisonValue(opValue) },\n });\n });\n continue;\n }\n\n // Check if the nested object contains operators\n if (Object.keys(value).length === 0) {\n result[newPath] = this.translateNode(value);\n } else {\n const hasOperators = Object.keys(value).some(k => this.isOperator(k));\n if (hasOperators) {\n // For objects with operators, normalize each operator value\n const normalizedValue: Record<string, any> = {};\n for (const [op, opValue] of Object.entries(value)) {\n normalizedValue[op] = this.isOperator(op) ? this.translateOperator(op, opValue) : opValue;\n }\n result[newPath] = normalizedValue;\n } else {\n // For objects without operators, flatten them\n Object.assign(result, this.translateNode(value, newPath));\n }\n }\n } else {\n result[newPath] = this.translateNode(value);\n }\n }\n\n // Combine multiOperatorConditions with result if both exist\n if (multiOperatorConditions.length > 0) {\n // Convert result to array of conditions for $and\n const resultConditions = Object.entries(result).map(([key, value]) => ({ [key]: value }));\n const allConditions = [...multiOperatorConditions, ...resultConditions];\n\n if (allConditions.length === 1) {\n return allConditions[0];\n }\n return { $and: allConditions };\n }\n\n // Wrap in $and if there are multiple top-level fields\n if (Object.keys(result).length > 1 && !currentPath) {\n return {\n $and: Object.entries(result).map(([key, value]) => ({ [key]: value })),\n };\n }\n\n return result;\n }\n\n private translateOperator(operator: QueryOperator, value: any): any {\n // Handle logical operators\n if (this.isLogicalOperator(operator)) {\n return Array.isArray(value) ? value.map(item => this.translateNode(item)) : this.translateNode(value);\n }\n\n // Handle comparison and element operators\n return this.normalizeComparisonValue(value);\n }\n}\n","import { MastraError, ErrorDomain, ErrorCategory } from '@mastra/core/error';\nimport { createVectorErrorId } from '@mastra/core/storage';\nimport { MastraVector, validateUpsert, validateTopK } from '@mastra/core/vector';\nimport type {\n QueryResult,\n IndexStats,\n CreateIndexParams,\n UpsertVectorParams,\n QueryVectorParams,\n DescribeIndexParams,\n DeleteIndexParams,\n DeleteVectorParams,\n UpdateVectorParams,\n DeleteVectorsParams,\n} from '@mastra/core/vector';\nimport { ChromaClient, CloudClient } from 'chromadb';\nimport type { ChromaClientArgs, RecordSet, Where, WhereDocument, Collection, Metadata, Search } from 'chromadb';\nimport { distanceToScore } from './distance-to-score';\nimport type { ChromaVectorFilter } from './filter';\nimport { ChromaFilterTranslator } from './filter';\n\ninterface ChromaUpsertVectorParams extends UpsertVectorParams {\n documents?: string[];\n}\n\ninterface ChromaQueryVectorParams extends QueryVectorParams<ChromaVectorFilter> {\n documentFilter?: WhereDocument | null;\n}\n\ninterface ChromaGetRecordsParams {\n indexName: string;\n ids?: string[];\n filter?: ChromaVectorFilter;\n documentFilter?: WhereDocument | null;\n includeVector?: boolean;\n limit?: number;\n offset?: number;\n}\n\ntype MastraMetadata = {\n dimension?: number;\n};\n\ntype ChromaVectorArgs = ChromaClientArgs & { apiKey?: string };\n\nconst spaceMappings = {\n cosine: 'cosine',\n euclidean: 'l2',\n dotproduct: 'ip',\n l2: 'euclidean',\n ip: 'dotproduct',\n};\n\nexport class ChromaVector extends MastraVector<ChromaVectorFilter> {\n private client: ChromaClient;\n private collections: Map<string, Collection>;\n\n constructor({ id, ...chromaClientArgs }: ChromaVectorArgs & { id: string }) {\n super({ id });\n if (chromaClientArgs?.apiKey) {\n this.client = new CloudClient({\n apiKey: chromaClientArgs.apiKey,\n tenant: chromaClientArgs.tenant,\n database: chromaClientArgs.database,\n });\n } else {\n this.client = new ChromaClient(chromaClientArgs);\n }\n this.collections = new Map();\n }\n\n async getCollection({ indexName, forceUpdate = false }: { indexName: string; forceUpdate?: boolean }) {\n let collection = this.collections.get(indexName);\n if (forceUpdate || !collection) {\n try {\n collection = await this.client.getCollection({ name: indexName });\n this.collections.set(indexName, collection);\n return collection;\n } catch {\n throw new MastraError({\n id: createVectorErrorId('CHROMA', 'GET_COLLECTION', 'FAILED'),\n domain: ErrorDomain.MASTRA_VECTOR,\n category: ErrorCategory.THIRD_PARTY,\n details: { indexName },\n });\n }\n }\n return collection;\n }\n\n private validateVectorDimensions(vectors: number[][], dimension: number): void {\n for (let i = 0; i < vectors.length; i++) {\n if (vectors?.[i]?.length !== dimension) {\n throw new Error(\n `Vector at index ${i} has invalid dimension ${vectors?.[i]?.length}. Expected ${dimension} dimensions.`,\n );\n }\n }\n }\n\n async upsert({ indexName, vectors, metadata, ids, documents }: ChromaUpsertVectorParams): Promise<string[]> {\n // Validate input parameters and vector values\n validateUpsert('CHROMA', vectors, metadata, ids, true);\n\n try {\n const collection = await this.getCollection({ indexName });\n\n const stats = await this.describeIndex({ indexName });\n this.validateVectorDimensions(vectors, stats.dimension);\n const generatedIds = ids || vectors.map(() => crypto.randomUUID());\n\n await collection.upsert({\n ids: generatedIds,\n embeddings: vectors,\n metadatas: metadata,\n documents: documents,\n });\n\n return generatedIds;\n } catch (error: any) {\n if (error instanceof MastraError) throw error;\n throw new MastraError(\n {\n id: createVectorErrorId('CHROMA', 'UPSERT', 'FAILED'),\n domain: ErrorDomain.MASTRA_VECTOR,\n category: ErrorCategory.THIRD_PARTY,\n details: { indexName },\n },\n error,\n );\n }\n }\n\n async createIndex({ indexName, dimension, metric = 'cosine' }: CreateIndexParams): Promise<void> {\n if (!Number.isInteger(dimension) || dimension <= 0) {\n throw new MastraError({\n id: createVectorErrorId('CHROMA', 'CREATE_INDEX', 'INVALID_DIMENSION'),\n text: 'Dimension must be a positive integer',\n domain: ErrorDomain.MASTRA_VECTOR,\n category: ErrorCategory.USER,\n details: { dimension },\n });\n }\n\n const hnswSpace = spaceMappings[metric] as 'cosine' | 'l2' | 'ip' | undefined;\n\n if (!hnswSpace || !['cosine', 'l2', 'ip'].includes(hnswSpace)) {\n throw new MastraError({\n id: createVectorErrorId('CHROMA', 'CREATE_INDEX', 'INVALID_METRIC'),\n text: `Invalid metric: \"${metric}\". Must be one of: cosine, euclidean, dotproduct`,\n domain: ErrorDomain.MASTRA_VECTOR,\n category: ErrorCategory.USER,\n details: { metric },\n });\n }\n\n try {\n const collection = await this.client.createCollection({\n name: indexName,\n metadata: { dimension },\n configuration: { hnsw: { space: hnswSpace } },\n embeddingFunction: null,\n });\n this.collections.set(indexName, collection);\n } catch (error: any) {\n // Check for 'already exists' error\n const message = error?.message || error?.toString();\n if (message && message.toLowerCase().includes('already exists')) {\n // Fetch collection info and check dimension\n await this.validateExistingIndex(indexName, dimension, metric);\n return;\n }\n throw new MastraError(\n {\n id: createVectorErrorId('CHROMA', 'CREATE_INDEX', 'FAILED'),\n domain: ErrorDomain.MASTRA_VECTOR,\n category: ErrorCategory.THIRD_PARTY,\n details: { indexName },\n },\n error,\n );\n }\n }\n\n transformFilter(filter?: ChromaVectorFilter) {\n const translator = new ChromaFilterTranslator();\n const translatedFilter = translator.translate(filter);\n return translatedFilter ? (translatedFilter as Where) : undefined;\n }\n\n async query<T extends Metadata = Metadata>({\n indexName,\n queryVector,\n topK = 10,\n filter,\n includeVector = false,\n documentFilter,\n }: ChromaQueryVectorParams): Promise<QueryResult[]> {\n if (!queryVector) {\n throw new MastraError({\n id: createVectorErrorId('CHROMA', 'QUERY', 'MISSING_VECTOR'),\n text: 'queryVector is required for Chroma queries. Metadata-only queries are not supported by this vector store.',\n domain: ErrorDomain.MASTRA_VECTOR,\n category: ErrorCategory.USER,\n details: { indexName },\n });\n }\n\n // Validate topK parameter\n validateTopK('CHROMA', topK);\n\n try {\n const collection = await this.getCollection({ indexName });\n\n const defaultInclude: ['documents', 'metadatas', 'distances'] = ['documents', 'metadatas', 'distances'];\n\n const translatedFilter = this.transformFilter(filter);\n const results = await collection.query<T>({\n queryEmbeddings: [queryVector],\n nResults: topK,\n where: translatedFilter ?? undefined,\n whereDocument: documentFilter ?? undefined,\n include: includeVector ? [...defaultInclude, 'embeddings'] : defaultInclude,\n });\n\n const space = collection.configuration?.hnsw?.space || collection.configuration?.spann?.space || 'cosine';\n const metric = spaceMappings[space] as 'cosine' | 'euclidean' | 'dotproduct';\n\n return (results.ids[0] || []).map((id: string, index: number) => {\n const distance = results.distances?.[0]?.[index];\n const score = distance == null ? 0 : distanceToScore(distance, metric);\n return {\n id,\n score,\n metadata: results.metadatas?.[0]?.[index] || {},\n document: results.documents?.[0]?.[index] ?? undefined,\n ...(includeVector && { vector: results.embeddings?.[0]?.[index] || [] }),\n };\n });\n } catch (error: any) {\n if (error instanceof MastraError) throw error;\n throw new MastraError(\n {\n id: createVectorErrorId('CHROMA', 'QUERY', 'FAILED'),\n domain: ErrorDomain.MASTRA_VECTOR,\n category: ErrorCategory.THIRD_PARTY,\n details: { indexName },\n },\n error,\n );\n }\n }\n\n async hybridSearch({ indexName, search }: { indexName: string; search: Search }): Promise<QueryResult[]> {\n try {\n const collection = await this.getCollection({ indexName });\n const results = await collection.search(search);\n return (results.rows()[0] ?? []).map(record => ({\n id: record.id,\n score: record.score ?? 0,\n metadata: record.metadata ?? undefined,\n vector: record.embedding ?? undefined,\n document: record.document ?? undefined,\n }));\n } catch (error: any) {\n if (error instanceof MastraError) throw error;\n throw new MastraError(\n {\n id: createVectorErrorId('CHROMA', 'SEARCH_API', 'FAILED'),\n domain: ErrorDomain.MASTRA_VECTOR,\n category: ErrorCategory.THIRD_PARTY,\n details: { indexName },\n },\n error,\n );\n }\n }\n\n async get<T extends Metadata = Metadata>({\n indexName,\n ids,\n filter,\n includeVector = false,\n documentFilter,\n offset,\n limit,\n }: ChromaGetRecordsParams) {\n try {\n const collection = await this.getCollection({ indexName });\n\n const defaultInclude: ['documents', 'metadatas'] = ['documents', 'metadatas'];\n const translatedFilter = this.transformFilter(filter);\n\n const result = await collection.get<T>({\n ids,\n where: translatedFilter ?? undefined,\n whereDocument: documentFilter ?? undefined,\n offset,\n limit,\n include: includeVector ? [...defaultInclude, 'embeddings'] : defaultInclude,\n });\n return result.rows();\n } catch (error: any) {\n if (error instanceof MastraError) throw error;\n throw new MastraError(\n {\n id: createVectorErrorId('CHROMA', 'GET', 'FAILED'),\n domain: ErrorDomain.MASTRA_VECTOR,\n category: ErrorCategory.THIRD_PARTY,\n details: { indexName },\n },\n error,\n );\n }\n }\n\n async listIndexes(): Promise<string[]> {\n try {\n const collections = await this.client.listCollections();\n return collections.map(collection => collection.name);\n } catch (error: any) {\n throw new MastraError(\n {\n id: createVectorErrorId('CHROMA', 'LIST_INDEXES', 'FAILED'),\n domain: ErrorDomain.MASTRA_VECTOR,\n category: ErrorCategory.THIRD_PARTY,\n },\n error,\n );\n }\n }\n\n /**\n * Retrieves statistics about a vector index.\n *\n * @param {string} indexName - The name of the index to describe\n * @returns A promise that resolves to the index statistics including dimension, count and metric\n */\n async describeIndex({ indexName }: DescribeIndexParams): Promise<IndexStats> {\n try {\n const collection = await this.getCollection({ indexName });\n const count = await collection.count();\n const metadata = collection.metadata as MastraMetadata | undefined;\n const space = collection.configuration.hnsw?.space || collection.configuration.spann?.space || undefined;\n\n return {\n dimension: metadata?.dimension || 0,\n count,\n metric: space ? (spaceMappings[space] as 'cosine' | 'euclidean' | 'dotproduct') : undefined,\n };\n } catch (error: any) {\n if (error instanceof MastraError) throw error;\n throw new MastraError(\n {\n id: createVectorErrorId('CHROMA', 'DESCRIBE_INDEX', 'FAILED'),\n domain: ErrorDomain.MASTRA_VECTOR,\n category: ErrorCategory.THIRD_PARTY,\n details: { indexName },\n },\n error,\n );\n }\n }\n\n async deleteIndex({ indexName }: DeleteIndexParams): Promise<void> {\n try {\n await this.client.deleteCollection({ name: indexName });\n this.collections.delete(indexName);\n } catch (error: any) {\n throw new MastraError(\n {\n id: createVectorErrorId('CHROMA', 'DELETE_INDEX', 'FAILED'),\n domain: ErrorDomain.MASTRA_VECTOR,\n category: ErrorCategory.THIRD_PARTY,\n details: { indexName },\n },\n error,\n );\n }\n }\n\n async forkIndex({ indexName, newIndexName }: { indexName: string; newIndexName: string }): Promise<void> {\n try {\n const collection = await this.getCollection({ indexName, forceUpdate: true });\n const forkedCollection = await collection.fork({ name: newIndexName });\n this.collections.set(newIndexName, forkedCollection);\n } catch (error: any) {\n if (error instanceof MastraError) throw error;\n throw new MastraError(\n {\n id: createVectorErrorId('CHROMA', 'FORK_INDEX', 'FAILED'),\n domain: ErrorDomain.MASTRA_VECTOR,\n category: ErrorCategory.THIRD_PARTY,\n details: { indexName },\n },\n error,\n );\n }\n }\n\n /**\n * Updates a vector by its ID or multiple vectors matching a filter.\n * @param indexName - The name of the index containing the vector(s).\n * @param id - The ID of the vector to update (mutually exclusive with filter).\n * @param filter - Filter to match multiple vectors to update (mutually exclusive with id).\n * @param update - An object containing the vector and/or metadata to update.\n * @param update.vector - An optional array of numbers representing the new vector.\n * @param update.metadata - An optional record containing the new metadata.\n * @returns A promise that resolves when the update is complete.\n * @throws Will throw an error if no updates are provided or if the update operation fails.\n */\n async updateVector({ indexName, id, filter, update }: UpdateVectorParams<ChromaVectorFilter>): Promise<void> {\n // Validate mutually exclusive parameters\n if (id && filter) {\n throw new MastraError({\n id: createVectorErrorId('CHROMA', 'UPDATE_VECTOR', 'MUTUALLY_EXCLUSIVE'),\n text: 'Cannot specify both id and filter - they are mutually exclusive',\n domain: ErrorDomain.MASTRA_VECTOR,\n category: ErrorCategory.USER,\n details: { indexName },\n });\n }\n\n if (!id && !filter) {\n throw new MastraError({\n id: createVectorErrorId('CHROMA', 'UPDATE_VECTOR', 'NO_TARGET'),\n text: 'Either id or filter must be provided',\n domain: ErrorDomain.MASTRA_VECTOR,\n category: ErrorCategory.USER,\n details: { indexName },\n });\n }\n\n if (!update.vector && !update.metadata) {\n throw new MastraError({\n id: createVectorErrorId('CHROMA', 'UPDATE_VECTOR', 'NO_PAYLOAD'),\n text: 'No updates provided',\n domain: ErrorDomain.MASTRA_VECTOR,\n category: ErrorCategory.USER,\n details: {\n indexName,\n ...(id && { id }),\n },\n });\n }\n\n // Validate filter is not empty\n if (filter && Object.keys(filter).length === 0) {\n throw new MastraError({\n id: createVectorErrorId('CHROMA', 'UPDATE_VECTOR', 'EMPTY_FILTER'),\n text: 'Filter cannot be an empty filter object',\n domain: ErrorDomain.MASTRA_VECTOR,\n category: ErrorCategory.USER,\n details: { indexName },\n });\n }\n\n try {\n const collection: Collection = await this.getCollection({ indexName });\n\n // Validate vector dimensions if provided\n if (update?.vector) {\n const stats = await this.describeIndex({ indexName });\n this.validateVectorDimensions([update.vector], stats.dimension);\n }\n\n if (id) {\n // Update single vector by ID\n const updateRecordSet: RecordSet = { ids: [id] };\n\n if (update?.vector) {\n updateRecordSet.embeddings = [update.vector];\n }\n\n if (update?.metadata) {\n updateRecordSet.metadatas = [update.metadata];\n }\n\n return await collection.update(updateRecordSet);\n } else if (filter) {\n // Update multiple vectors matching filter\n // First, get all vectors matching the filter\n const translatedFilter = this.transformFilter(filter);\n const matchingVectors = await collection.get({\n where: translatedFilter ?? undefined,\n include: ['embeddings', 'metadatas'],\n });\n\n const vectorRows = matchingVectors.rows();\n if (vectorRows.length === 0) {\n // No vectors to update - this is not an error\n return;\n }\n\n // Prepare update for all matching vectors\n const updateRecordSet: RecordSet = {\n ids: vectorRows.map(row => row.id),\n };\n\n if (update?.vector) {\n // Use the same new vector for all matching records\n updateRecordSet.embeddings = vectorRows.map(() => update.vector!);\n }\n\n if (update?.metadata) {\n // Use the same new metadata for all matching records\n updateRecordSet.metadatas = vectorRows.map(() => update.metadata!);\n }\n\n return await collection.update(updateRecordSet);\n }\n } catch (error: any) {\n if (error instanceof MastraError) throw error;\n throw new MastraError(\n {\n id: createVectorErrorId('CHROMA', 'UPDATE_VECTOR', 'FAILED'),\n domain: ErrorDomain.MASTRA_VECTOR,\n category: ErrorCategory.THIRD_PARTY,\n details: {\n indexName,\n ...(id && { id }),\n ...(filter && { filter: JSON.stringify(filter) }),\n },\n },\n error,\n );\n }\n }\n\n async deleteVector({ indexName, id }: DeleteVectorParams): Promise<void> {\n try {\n const collection: Collection = await this.getCollection({ indexName });\n await collection.delete({ ids: [id] });\n } catch (error: any) {\n if (error instanceof MastraError) throw error;\n throw new MastraError(\n {\n id: createVectorErrorId('CHROMA', 'DELETE_VECTOR', 'FAILED'),\n domain: ErrorDomain.MASTRA_VECTOR,\n category: ErrorCategory.THIRD_PARTY,\n details: {\n indexName,\n ...(id && { id }),\n },\n },\n error,\n );\n }\n }\n\n /**\n * Deletes multiple vectors by IDs or filter.\n * @param indexName - The name of the index containing the vectors.\n * @param ids - Array of vector IDs to delete (mutually exclusive with filter).\n * @param filter - Filter to match vectors to delete (mutually exclusive with ids).\n * @returns A promise that resolves when the deletion is complete.\n * @throws Will throw an error if both ids and filter are provided, or if neither is provided.\n */\n async deleteVectors({ indexName, filter, ids }: DeleteVectorsParams<ChromaVectorFilter>): Promise<void> {\n // Validate mutually exclusive parameters\n if (ids && filter) {\n throw new MastraError({\n id: createVectorErrorId('CHROMA', 'DELETE_VECTORS', 'MUTUALLY_EXCLUSIVE'),\n text: 'Cannot specify both ids and filter - they are mutually exclusive',\n domain: ErrorDomain.MASTRA_VECTOR,\n category: ErrorCategory.USER,\n details: { indexName },\n });\n }\n\n if (!ids && !filter) {\n throw new MastraError({\n id: createVectorErrorId('CHROMA', 'DELETE_VECTORS', 'NO_TARGET'),\n text: 'Either filter or ids must be provided',\n domain: ErrorDomain.MASTRA_VECTOR,\n category: ErrorCategory.USER,\n details: { indexName },\n });\n }\n\n // Validate ids array is not empty\n if (ids && ids.length === 0) {\n throw new MastraError({\n id: createVectorErrorId('CHROMA', 'DELETE_VECTORS', 'EMPTY_IDS'),\n text: 'Cannot delete with empty ids array',\n domain: ErrorDomain.MASTRA_VECTOR,\n category: ErrorCategory.USER,\n details: { indexName },\n });\n }\n\n // Validate filter is not empty\n if (filter && Object.keys(filter).length === 0) {\n throw new MastraError({\n id: createVectorErrorId('CHROMA', 'DELETE_VECTORS', 'EMPTY_FILTER'),\n text: 'Cannot delete with empty filter object',\n domain: ErrorDomain.MASTRA_VECTOR,\n category: ErrorCategory.USER,\n details: { indexName },\n });\n }\n\n try {\n const collection: Collection = await this.getCollection({ indexName });\n\n if (ids) {\n // Delete by IDs\n await collection.delete({ ids });\n } else if (filter) {\n // Delete by filter\n const translatedFilter = this.transformFilter(filter);\n await collection.delete({\n where: translatedFilter ?? undefined,\n });\n }\n } catch (error: any) {\n if (error instanceof MastraError) throw error;\n throw new MastraError(\n {\n id: createVectorErrorId('CHROMA', 'DELETE_VECTORS', 'FAILED'),\n domain: ErrorDomain.MASTRA_VECTOR,\n category: ErrorCategory.THIRD_PARTY,\n details: {\n indexName,\n ...(filter && { filter: JSON.stringify(filter) }),\n ...(ids && { idsCount: ids.length }),\n },\n },\n error,\n );\n }\n }\n}\n","/**\n * Vector store specific prompt that details supported operators and examples.\n * This prompt helps users construct valid filters for Chroma Vector.\n */\nexport const CHROMA_PROMPT = `When querying Chroma, 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\nLogical Operators:\n- $and: Logical AND\n Example: { \"$and\": [{ \"price\": { \"$gt\": 100 } }, { \"category\": \"electronics\" }] }\n- $or: Logical OR\n Example: { \"$or\": [{ \"price\": { \"$lt\": 50 } }, { \"category\": \"books\" }] }\n\nRestrictions:\n- Regex patterns are not supported\n- Element operators are not supported\n- Only $and and $or logical operators are supported\n- Nested fields are supported using dot notation\n- Multiple conditions on the same field are supported with both implicit and explicit $and\n- Empty arrays in $in/$nin will return no results\n- If multiple top-level fields exist, they're wrapped in $and\n- Only logical operators ($and, $or) can be used at the top level\n- All other operators must be used within a field condition\n Valid: { \"field\": { \"$gt\": 100 } }\n Valid: { \"$and\": [...] }\n Invalid: { \"$gt\": 100 }\n Invalid: { \"$in\": [...] }\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\": [{...}] } } }\n\nExample Complex Query:\n{\n \"$and\": [\n { \"category\": { \"$in\": [\"electronics\", \"computers\"] } },\n { \"price\": { \"$gte\": 100, \"$lte\": 1000 } },\n { \"$or\": [\n { \"inStock\": true },\n { \"preorder\": true }\n ]}\n ]\n}`;\n"],"mappings":";;;;;;AAAA,SAAgB,gBAAgB,UAAkB,QAAuD;CACvG,QAAQ,QAAR;EACE,KAAK,aACH,OAAO,KAAK,IAAI,KAAK,KAAK,QAAQ;EAGpC,SACE,OAAO,IAAI;CACf;AACF;;;;;;;ACmBA,IAAa,yBAAb,cAA4C,qBAAyC;CACnF,wBAA4D;EAC1D,OAAO;GACL,GAAG,qBAAqB;GACxB,SAAS,CAAC,QAAQ,KAAK;GACvB,OAAO,CAAC,OAAO,MAAM;GACrB,SAAS,CAAC;GACV,OAAO,CAAC;GACR,QAAQ,CAAC;EACX;CACF;CAEA,UAAU,QAAiD;EACzD,IAAI,KAAK,QAAQ,MAAM,GAAG,OAAO;EACjC,KAAK,eAAe,MAAM;EAE1B,OAAO,KAAK,cAAc,MAAM;CAClC;CAEA,cAAsB,MAA0B,cAAsB,IAAS;EAE7E,IAAI,KAAK,QAAQ,IAAI,GACnB,MAAM,IAAI,MAAM,gEAAgE;EAElF,IAAI,KAAK,YAAY,IAAI,GAAG,OAAO,KAAK,yBAAyB,IAAI;EACrE,IAAI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BAAiB,aAAa,MAAM;GACxC,MAAM,IAAI,YACR;IACE,IAAI,oBAAoB,UAAU,kBAAkB,QAAQ;IAC5D,QAAQ,YAAY;IACpB,UAAU,cAAc;IACxB,SAAS;KACP;KACA,GAAI,UAAU,EAAE,QAAQ,KAAK,UAAU,MAAM,EAAE;KAC/C,GAAI,OAAO,EAAE,UAAU,IAAI,OAAO;IACpC;GACF,GACA,KACF;EACF;CACF;AACF;;;;;;ACpnBA,MAAa,gBAAgB"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mastra/chroma",
3
- "version": "1.1.4",
3
+ "version": "1.1.5-alpha.0",
4
4
  "description": "Chroma vector store provider for Mastra",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -23,17 +23,17 @@
23
23
  "chromadb": "^3.5.0"
24
24
  },
25
25
  "devDependencies": {
26
- "@types/node": "22.20.1",
27
- "@vitest/coverage-v8": "4.1.11",
28
- "@vitest/ui": "4.1.11",
29
- "tsdown": "0.22.9",
30
- "tsx": "^4.23.1",
26
+ "@types/node": "22.19.15",
27
+ "@vitest/coverage-v8": "4.1.12",
28
+ "@vitest/ui": "4.1.12",
29
+ "tsdown": "0.23.1",
30
+ "tsx": "^4.23.15",
31
31
  "typescript": "^7.0.2",
32
- "vitest": "4.1.11",
32
+ "vitest": "4.1.12",
33
33
  "@internal/lint": "0.0.145",
34
- "@internal/types-builder": "0.0.120",
35
34
  "@internal/storage-test-utils": "0.0.141",
36
- "@mastra/core": "1.79.0"
35
+ "@internal/types-builder": "0.0.120",
36
+ "@mastra/core": "1.80.0-alpha.4"
37
37
  },
38
38
  "peerDependencies": {
39
39
  "@mastra/core": ">=1.0.0-0 <2.0.0-0"