@mastra/chroma 0.1.6-alpha.1 → 0.1.6-alpha.4

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.
@@ -1,13 +1,23 @@
1
- import type { Filter } from '@mastra/core/filter';
2
1
  import { MastraVector } from '@mastra/core/vector';
3
- import type { QueryResult, IndexStats } from '@mastra/core/vector';
2
+ import type {
3
+ QueryResult,
4
+ IndexStats,
5
+ CreateIndexParams,
6
+ UpsertVectorParams,
7
+ QueryVectorParams,
8
+ ParamsToArgs,
9
+ } from '@mastra/core/vector';
10
+ import type { VectorFilter } from '@mastra/core/vector/filter';
4
11
  import { ChromaClient } from 'chromadb';
5
12
 
6
13
  import { ChromaFilterTranslator } from './filter';
7
14
 
8
- export interface DocumentMetadata {
9
- content?: string;
10
- metadata?: Record<string, any>;
15
+ interface ChromaUpsertVectorParams extends UpsertVectorParams {
16
+ documents?: string[];
17
+ }
18
+
19
+ interface ChromaQueryVectorParams extends QueryVectorParams {
20
+ documentFilter?: VectorFilter;
11
21
  }
12
22
 
13
23
  export class ChromaVector extends MastraVector {
@@ -55,13 +65,11 @@ export class ChromaVector extends MastraVector {
55
65
  }
56
66
  }
57
67
 
58
- async upsert(
59
- indexName: string,
60
- vectors: number[][],
61
- metadata?: Record<string, any>[],
62
- ids?: string[],
63
- documents?: string[],
64
- ): Promise<string[]> {
68
+ async upsert(...args: ParamsToArgs<ChromaUpsertVectorParams>): Promise<string[]> {
69
+ const params = this.normalizeArgs<ChromaUpsertVectorParams>('upsert', args, ['documents']);
70
+
71
+ const { indexName, vectors, metadata, ids, documents } = params;
72
+
65
73
  const collection = await this.getCollection(indexName);
66
74
 
67
75
  // Get index stats to check dimension
@@ -94,11 +102,11 @@ export class ChromaVector extends MastraVector {
94
102
  ip: 'dotproduct',
95
103
  };
96
104
 
97
- async createIndex(
98
- indexName: string,
99
- dimension: number,
100
- metric: 'cosine' | 'euclidean' | 'dotproduct' = 'cosine',
101
- ): Promise<void> {
105
+ async createIndex(...args: ParamsToArgs<CreateIndexParams>): Promise<void> {
106
+ const params = this.normalizeArgs<CreateIndexParams>('createIndex', args);
107
+
108
+ const { indexName, dimension, metric = 'cosine' } = params;
109
+
102
110
  if (!Number.isInteger(dimension) || dimension <= 0) {
103
111
  throw new Error('Dimension must be a positive integer');
104
112
  }
@@ -115,19 +123,15 @@ export class ChromaVector extends MastraVector {
115
123
  });
116
124
  }
117
125
 
118
- transformFilter(filter?: Filter) {
119
- const chromaFilter = new ChromaFilterTranslator();
120
- const translatedFilter = chromaFilter.translate(filter);
121
- return translatedFilter;
126
+ transformFilter(filter?: VectorFilter) {
127
+ const translator = new ChromaFilterTranslator();
128
+ return translator.translate(filter);
122
129
  }
123
- async query(
124
- indexName: string,
125
- queryVector: number[],
126
- topK: number = 10,
127
- filter?: Filter,
128
- includeVector: boolean = false,
129
- documentFilter?: Filter,
130
- ): Promise<QueryResult[]> {
130
+ async query(...args: ParamsToArgs<ChromaQueryVectorParams>): Promise<QueryResult[]> {
131
+ const params = this.normalizeArgs<ChromaQueryVectorParams>('query', args, ['documentFilter']);
132
+
133
+ const { indexName, queryVector, topK = 10, filter, includeVector = false, documentFilter } = params;
134
+
131
135
  const collection = await this.getCollection(indexName, true);
132
136
 
133
137
  const defaultInclude = ['documents', 'metadatas', 'distances'];