Skip to content

Commit f8328d7

Browse files
committed
[ENH] Add collection config to js client
1 parent ad0609b commit f8328d7

26 files changed

+1171
-768
lines changed

chromadb/types.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ def get_configuration(self) -> CollectionConfiguration:
148148
return load_collection_configuration_from_json(self.configuration_json)
149149
except Exception as e:
150150
warnings.warn(
151-
f"server does not respond with configuration_json. Please update server: {e}",
151+
f"Server does not respond with configuration_json. Please update server: {e}",
152152
DeprecationWarning,
153153
stacklevel=2,
154154
)
@@ -181,7 +181,7 @@ def from_json(cls, json_map: Dict[str, Any]) -> Self:
181181
configuration = load_collection_configuration_from_json(configuration_json)
182182
except Exception as e:
183183
warnings.warn(
184-
f"server does not respond with configuration_json. Please update server: {e}",
184+
f"Server does not respond with configuration_json. Please update server: {e}",
185185
DeprecationWarning,
186186
stacklevel=2,
187187
)

clients/js/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ Chroma is the open-source embedding database. Chroma makes it easy to build LLM
44

55
This package gives you a JS/TS interface to talk to a backend Chroma DB over REST.
66

7+
**Note:** JS client version 3._ is only compatible with chromadb v1.0.6 and newer or Chroma Cloud. For prior version compatiblity, please use JS client version 2._.
8+
79
[Learn more about Chroma](https://github.com/chroma-core/chroma)
810

911
- [💬 Community Discord](https://discord.gg/MMeYNTmh3x)

clients/js/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "chromadb-root",
33
"private": true,
4-
"version": "2.2.1",
4+
"version": "3.0.0",
55
"description": "A JavaScript interface for chroma",
66
"keywords": [],
77
"author": "",
@@ -70,9 +70,9 @@
7070
"peerDependencies": {
7171
"@google/generative-ai": "^0.1.1",
7272
"cohere-ai": "^5.0.0 || ^6.0.0 || ^7.0.0",
73+
"ollama": "^0.5.0",
7374
"openai": "^3.0.0 || ^4.0.0",
74-
"voyageai": "^0.0.3-1",
75-
"ollama": "^0.5.0"
75+
"voyageai": "^0.0.3-1"
7676
},
7777
"peerDependenciesMeta": {
7878
"@google/generative-ai": {

clients/js/packages/chromadb-client/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
Chroma is the open-source embedding database. Chroma makes it easy to build LLM apps by making knowledge, facts, and skills pluggable for LLMs.
44

5+
**Note:** JS client version 3._ is only compatible with chromadb v1.0.6 and newer or Chroma Cloud. For prior version compatiblity, please use JS client version 2._.
6+
57
**This package provides embedding libraries as peer dependencies**, allowing you to manage your own versions of embedding libraries and keep your dependency tree lean by not bundling dependencies you don't use. For a thick client with bundled embedding functions, install `chromadb`.
68

79
## Features

clients/js/packages/chromadb-client/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "chromadb-client",
3-
"version": "2.2.1",
3+
"version": "3.0.0",
44
"description": "A JavaScript interface for chroma with embedding functions as peer dependencies",
55
"license": "Apache-2.0",
66
"type": "module",

clients/js/packages/chromadb-core/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@internal/chromadb-core",
3-
"version": "2.2.1",
3+
"version": "3.0.0",
44
"private": true,
55
"description": "Core functionality for ChromaDB JavaScript client",
66
"license": "Apache-2.0",

clients/js/packages/chromadb-core/src/ChromaClient.ts

Lines changed: 56 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { authOptionsToAuthProvider, ClientAuthProvider } from "./auth";
44
import { chromaFetch } from "./ChromaFetch";
55
import { Collection } from "./Collection";
66
import { DefaultEmbeddingFunction } from "./embeddings/DefaultEmbeddingFunction";
7-
import { Configuration, ApiApi as DefaultApi } from "./generated";
7+
import { Configuration, ApiApi as DefaultApi, Api } from "./generated";
88
import type {
99
ChromaClientParams,
1010
CollectionMetadata,
@@ -18,7 +18,8 @@ import type {
1818
UserIdentity,
1919
} from "./types";
2020
import { validateTenantDatabase, wrapCollection } from "./utils";
21-
21+
import { loadApiCollectionConfigurationFromCreateCollectionConfiguration } from "./CollectionConfiguration";
22+
import { warn } from "console";
2223
const DEFAULT_TENANT = "default_tenant";
2324
const DEFAULT_DATABASE = "default_database";
2425

@@ -224,25 +225,43 @@ export class ChromaClient {
224225
name,
225226
metadata,
226227
embeddingFunction = new DefaultEmbeddingFunction(),
228+
configuration,
227229
}: CreateCollectionParams): Promise<Collection> {
228230
await this.init();
231+
let collectionConfiguration: Api.CollectionConfiguration | undefined =
232+
undefined;
233+
if (configuration) {
234+
collectionConfiguration =
235+
loadApiCollectionConfigurationFromCreateCollectionConfiguration(
236+
configuration,
237+
);
238+
}
229239
const newCollection = await this.api.createCollection(
230240
this.tenant,
231241
this.database,
232242
{
233243
name,
234-
// @ts-ignore: we need to generate the client libraries again
235-
configuration: null, //TODO: Configuration type in JavaScript
244+
configuration: collectionConfiguration,
236245
metadata: metadata,
237246
},
238247
this.api.options,
239248
);
240249

250+
let config: Api.CollectionConfiguration = {};
251+
try {
252+
config = newCollection.configuration_json;
253+
} catch {
254+
warn(
255+
"Server does not respond with configuration_json. Please update server",
256+
);
257+
}
258+
241259
return wrapCollection(this, {
242260
name: newCollection.name,
243261
id: newCollection.id,
244262
metadata: newCollection.metadata as CollectionMetadata | undefined,
245263
embeddingFunction,
264+
configuration: config,
246265
});
247266
}
248267

@@ -271,26 +290,47 @@ export class ChromaClient {
271290
name,
272291
metadata,
273292
embeddingFunction = new DefaultEmbeddingFunction(),
293+
configuration,
274294
}: GetOrCreateCollectionParams): Promise<Collection> {
275295
await this.init();
296+
297+
let collectionConfiguration: Api.CollectionConfiguration | undefined =
298+
undefined;
299+
300+
if (configuration) {
301+
collectionConfiguration =
302+
loadApiCollectionConfigurationFromCreateCollectionConfiguration(
303+
configuration,
304+
);
305+
}
306+
276307
const newCollection = await this.api.createCollection(
277308
this.tenant,
278309
this.database,
279310
{
280311
name,
281-
// @ts-ignore: we need to generate the client libraries again
282-
configuration: null, //TODO: Configuration type in JavaScript
312+
configuration: collectionConfiguration,
283313
metadata: metadata,
284314
get_or_create: true,
285315
},
286316
this.api.options,
287317
);
288318

319+
let config: Api.CollectionConfiguration = {};
320+
try {
321+
config = newCollection.configuration_json;
322+
} catch {
323+
warn(
324+
"Server does not respond with configuration_json. Please update server",
325+
);
326+
}
327+
289328
return wrapCollection(this, {
290329
name: newCollection.name,
291330
id: newCollection.id,
292331
metadata: newCollection.metadata as CollectionMetadata | undefined,
293332
embeddingFunction,
333+
configuration: config,
294334
});
295335
}
296336

@@ -412,6 +452,15 @@ export class ChromaClient {
412452
this.api.options,
413453
);
414454

455+
let config: Api.CollectionConfiguration = {};
456+
try {
457+
config = response.configuration_json;
458+
} catch {
459+
warn(
460+
"Server does not respond with configuration_json. Please update server",
461+
);
462+
}
463+
415464
return wrapCollection(this, {
416465
id: response.id,
417466
name: response.name,
@@ -420,6 +469,7 @@ export class ChromaClient {
420469
embeddingFunction !== undefined
421470
? embeddingFunction
422471
: new DefaultEmbeddingFunction(),
472+
configuration: config,
423473
});
424474
}
425475

clients/js/packages/chromadb-core/src/Collection.ts

Lines changed: 46 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,15 @@ import {
1414
DeleteParams,
1515
Embeddings,
1616
CollectionParams,
17+
IncludeEnum,
18+
Metadata,
1719
} from "./types";
1820
import { prepareRecordRequest, toArray, toArrayOfArrays } from "./utils";
19-
import { Api as GeneratedApi } from "./generated";
21+
import { Api as GeneratedApi, Api } from "./generated";
22+
import {
23+
UpdateCollectionConfiguration,
24+
loadApiUpdateCollectionConfigurationFromUpdateCollectionConfiguration,
25+
} from "./CollectionConfiguration";
2026

2127
export class Collection {
2228
public name: string;
@@ -31,6 +37,8 @@ export class Collection {
3137
*/
3238
public embeddingFunction: IEmbeddingFunction;
3339

40+
public configuration: Api.CollectionConfiguration | undefined;
41+
3442
/**
3543
* @ignore
3644
*/
@@ -40,12 +48,14 @@ export class Collection {
4048
client: ChromaClient,
4149
embeddingFunction: IEmbeddingFunction,
4250
metadata?: CollectionMetadata,
51+
configuration?: Api.CollectionConfiguration,
4352
) {
4453
this.name = name;
4554
this.id = id;
4655
this.metadata = metadata;
4756
this.client = client;
4857
this.embeddingFunction = embeddingFunction;
58+
this.configuration = configuration;
4959
}
5060

5161
/**
@@ -172,7 +182,7 @@ export class Collection {
172182

173183
const idsArray = ids ? toArray(ids) : undefined;
174184

175-
const resp = (await this.client.api.collectionGet(
185+
const resp = await this.client.api.collectionGet(
176186
this.client.tenant,
177187
this.client.database,
178188
this.id,
@@ -185,9 +195,17 @@ export class Collection {
185195
where_document: whereDocument,
186196
},
187197
this.client.api.options,
188-
)) as unknown as GetResponse;
198+
);
189199

190-
return resp;
200+
const finalResp: GetResponse = {
201+
...resp,
202+
metadatas: resp.metadatas as (Metadata | null)[],
203+
documents: resp.documents as (string | null)[],
204+
embeddings: resp.embeddings as Embeddings | null,
205+
included: resp.include as unknown as IncludeEnum[],
206+
};
207+
208+
return finalResp;
191209
}
192210

193211
/**
@@ -281,7 +299,7 @@ export class Collection {
281299
);
282300
}
283301

284-
const resp = (await this.client.api.collectionQuery(
302+
const resp = await this.client.api.collectionQuery(
285303
this.client.tenant,
286304
this.client.database,
287305
this.id,
@@ -295,9 +313,18 @@ export class Collection {
295313
include: include as GeneratedApi.Include[] | undefined,
296314
},
297315
this.client.api.options,
298-
)) as unknown as MultiQueryResponse;
316+
);
299317

300-
return resp;
318+
const finalResp: MultiQueryResponse = {
319+
...resp,
320+
metadatas: resp.metadatas as (Metadata | null)[][],
321+
documents: resp.documents as (string | null)[][],
322+
embeddings: resp.embeddings as Embeddings[] | null,
323+
distances: resp.distances as number[][] | null,
324+
included: resp.include as unknown as IncludeEnum[],
325+
};
326+
327+
return finalResp;
301328
}
302329

303330
/**
@@ -318,19 +345,30 @@ export class Collection {
318345
async modify({
319346
name,
320347
metadata,
348+
configuration,
321349
}: {
322350
name?: string;
323351
metadata?: CollectionMetadata;
352+
configuration?: UpdateCollectionConfiguration;
324353
}): Promise<CollectionParams> {
325354
await this.client.init();
326-
355+
let updateCollectionConfiguration:
356+
| Api.UpdateCollectionConfiguration
357+
| undefined = undefined;
358+
if (configuration) {
359+
updateCollectionConfiguration =
360+
loadApiUpdateCollectionConfigurationFromUpdateCollectionConfiguration(
361+
configuration,
362+
);
363+
}
327364
const resp = (await this.client.api.updateCollection(
328365
this.client.tenant,
329366
this.client.database,
330367
this.id,
331368
{
332369
new_name: name,
333370
new_metadata: metadata,
371+
new_configuration: updateCollectionConfiguration,
334372
},
335373
this.client.api.options,
336374
)) as CollectionParams;

0 commit comments

Comments
 (0)