Skip to content

Commit ef0582e

Browse files
committed
[ENH] Add collection config to js client
1 parent 69ef0ab commit ef0582e

File tree

10 files changed

+589
-20
lines changed

10 files changed

+589
-20
lines changed

Dockerfile

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,57 +11,55 @@ RUN apt-get update --fix-missing && apt-get install -y --fix-missing \
1111
unzip \
1212
curl \
1313
make && \
14+
curl https://sh.rustup.rs -sSf | sh -s -- -y --default-toolchain stable && \
1415
rm -rf /var/lib/apt/lists/* && \
1516
mkdir /install
16-
17+
ENV PATH="/root/.cargo/bin:$PATH"
1718
# Install specific Protobuf compiler (v28.2)
1819
RUN curl -LO https://github.com/protocolbuffers/protobuf/releases/download/v${PROTOBUF_VERSION}/protoc-${PROTOBUF_VERSION}-linux-x86_64.zip && \
1920
unzip protoc-${PROTOBUF_VERSION}-linux-x86_64.zip -d /usr/local/ && \
2021
rm protoc-${PROTOBUF_VERSION}-linux-x86_64.zip && \
2122
chmod +x /usr/local/bin/protoc && \
2223
protoc --version # Verify installed version
23-
2424
WORKDIR /install
2525

2626
COPY ./requirements.txt requirements.txt
2727

28+
RUN --mount=type=cache,target=/root/.cache/pip pip install maturin cffi patchelf
2829
RUN --mount=type=cache,target=/root/.cache/pip pip install --upgrade --prefix="/install" -r requirements.txt
2930
RUN --mount=type=cache,target=/root/.cache/pip if [ "$REBUILD_HNSWLIB" = "true" ]; then pip install --no-binary :all: --force-reinstall --prefix="/install" chroma-hnswlib; fi
3031

3132
# Install gRPC tools for Python with fixed version
3233
RUN pip install grpcio==1.58.0 grpcio-tools==1.58.0
33-
3434
# Copy source files to build Protobufs
3535
COPY ./ /chroma
3636

3737
# Generate Protobufs
3838
WORKDIR /chroma
3939
RUN make -C idl proto_python
40+
RUN python3 -m maturin build
41+
RUN pip uninstall chromadb -y
42+
RUN pip install --prefix="/install" --find-links target/wheels/ --upgrade chromadb
4043

4144
FROM python:3.11-slim-bookworm AS final
4245

4346
# Create working directory
4447
RUN mkdir /chroma
4548
WORKDIR /chroma
46-
4749
# Copy entrypoint
4850
COPY ./bin/docker_entrypoint.sh /docker_entrypoint.sh
49-
5051
RUN apt-get update --fix-missing && apt-get install -y curl && \
5152
chmod +x /docker_entrypoint.sh && \
5253
rm -rf /var/lib/apt/lists/*
53-
5454
# Copy built dependencies and generated Protobufs
5555
COPY --from=builder /install /usr/local
5656
COPY --from=builder /chroma /chroma
57-
5857
ENV CHROMA_HOST_ADDR="0.0.0.0"
5958
ENV CHROMA_HOST_PORT=8000
6059
ENV CHROMA_WORKERS=1
6160
ENV CHROMA_LOG_CONFIG="chromadb/log_config.yml"
6261
ENV CHROMA_TIMEOUT_KEEP_ALIVE=30
63-
6462
EXPOSE 8000
6563

6664
ENTRYPOINT ["/docker_entrypoint.sh"]
67-
CMD [ "--workers ${CHROMA_WORKERS} --host ${CHROMA_HOST_ADDR} --port ${CHROMA_HOST_PORT} --proxy-headers --log-config ${CHROMA_LOG_CONFIG} --timeout-keep-alive ${CHROMA_TIMEOUT_KEEP_ALIVE}"]
65+
CMD [ "--workers ${CHROMA_WORKERS} --host ${CHROMA_HOST_ADDR} --port ${CHROMA_HOST_PORT} --proxy-headers --reload --log-config ${CHROMA_LOG_CONFIG} --timeout-keep-alive ${CHROMA_TIMEOUT_KEEP_ALIVE}"]

clients/js/package.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,14 +65,15 @@
6565
},
6666
"dependencies": {
6767
"cliui": "^8.0.1",
68-
"isomorphic-fetch": "^3.0.0"
68+
"isomorphic-fetch": "^3.0.0",
69+
"os": "^0.1.2"
6970
},
7071
"peerDependencies": {
7172
"@google/generative-ai": "^0.1.1",
7273
"cohere-ai": "^5.0.0 || ^6.0.0 || ^7.0.0",
74+
"ollama": "^0.5.0",
7375
"openai": "^3.0.0 || ^4.0.0",
74-
"voyageai": "^0.0.3-1",
75-
"ollama": "^0.5.0"
76+
"voyageai": "^0.0.3-1"
7677
},
7778
"peerDependenciesMeta": {
7879
"@google/generative-ai": {

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

Lines changed: 27 additions & 4 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,7 @@ import type {
1818
UserIdentity,
1919
} from "./types";
2020
import { validateTenantDatabase, wrapCollection } from "./utils";
21-
21+
import { loadApiCollectionConfigurationFromCreateCollectionConfiguration } from "./CollectionConfiguration";
2222
const DEFAULT_TENANT = "default_tenant";
2323
const DEFAULT_DATABASE = "default_database";
2424

@@ -224,25 +224,39 @@ export class ChromaClient {
224224
name,
225225
metadata,
226226
embeddingFunction = new DefaultEmbeddingFunction(),
227+
configuration,
227228
}: CreateCollectionParams): Promise<Collection> {
228229
await this.init();
230+
let collectionConfiguration: Api.CollectionConfiguration | undefined =
231+
undefined;
232+
if (configuration) {
233+
collectionConfiguration =
234+
loadApiCollectionConfigurationFromCreateCollectionConfiguration(
235+
configuration,
236+
);
237+
}
229238
const newCollection = await this.api.createCollection(
230239
this.tenant,
231240
this.database,
232241
{
233242
name,
234-
// @ts-ignore: we need to generate the client libraries again
235-
configuration: null, //TODO: Configuration type in JavaScript
243+
configuration: collectionConfiguration,
236244
metadata: metadata,
237245
},
238246
this.api.options,
239247
);
240248

249+
console.log(
250+
"NEW CREATE COLLECTION CONFIGURATION: ",
251+
newCollection.configuration_json,
252+
);
253+
241254
return wrapCollection(this, {
242255
name: newCollection.name,
243256
id: newCollection.id,
244257
metadata: newCollection.metadata as CollectionMetadata | undefined,
245258
embeddingFunction,
259+
configuration: newCollection.configuration_json,
246260
});
247261
}
248262

@@ -286,11 +300,18 @@ export class ChromaClient {
286300
this.api.options,
287301
);
288302

303+
console.log(
304+
"NEW GET_OR_CREATE COLLECTION CONFIGURATION: ",
305+
newCollection.configuration_json,
306+
);
307+
289308
return wrapCollection(this, {
290309
name: newCollection.name,
291310
id: newCollection.id,
292311
metadata: newCollection.metadata as CollectionMetadata | undefined,
293312
embeddingFunction,
313+
// TODO: once server returns configuration, add it here
314+
configuration: newCollection.configuration_json,
294315
});
295316
}
296317

@@ -412,6 +433,7 @@ export class ChromaClient {
412433
this.api.options,
413434
);
414435

436+
console.log("GET COLLECTION CONFIGURATION: ", response.configuration_json);
415437
return wrapCollection(this, {
416438
id: response.id,
417439
name: response.name,
@@ -420,6 +442,7 @@ export class ChromaClient {
420442
embeddingFunction !== undefined
421443
? embeddingFunction
422444
: new DefaultEmbeddingFunction(),
445+
configuration: response.configuration_json,
423446
});
424447
}
425448

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

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,11 @@ import {
1616
CollectionParams,
1717
} from "./types";
1818
import { prepareRecordRequest, toArray, toArrayOfArrays } from "./utils";
19-
import { Api as GeneratedApi } from "./generated";
19+
import { Api as GeneratedApi, Api } from "./generated";
20+
import {
21+
UpdateCollectionConfiguration,
22+
loadApiUpdateCollectionConfigurationFromUpdateCollectionConfiguration,
23+
} from "./CollectionConfiguration";
2024

2125
export class Collection {
2226
public name: string;
@@ -31,6 +35,8 @@ export class Collection {
3135
*/
3236
public embeddingFunction: IEmbeddingFunction;
3337

38+
public configuration: Api.CollectionConfiguration | undefined;
39+
3440
/**
3541
* @ignore
3642
*/
@@ -40,12 +46,14 @@ export class Collection {
4046
client: ChromaClient,
4147
embeddingFunction: IEmbeddingFunction,
4248
metadata?: CollectionMetadata,
49+
configuration?: Api.CollectionConfiguration,
4350
) {
4451
this.name = name;
4552
this.id = id;
4653
this.metadata = metadata;
4754
this.client = client;
4855
this.embeddingFunction = embeddingFunction;
56+
this.configuration = configuration;
4957
}
5058

5159
/**
@@ -318,19 +326,30 @@ export class Collection {
318326
async modify({
319327
name,
320328
metadata,
329+
configuration,
321330
}: {
322331
name?: string;
323332
metadata?: CollectionMetadata;
333+
configuration?: UpdateCollectionConfiguration;
324334
}): Promise<CollectionParams> {
325335
await this.client.init();
326-
336+
let updateCollectionConfiguration:
337+
| Api.UpdateCollectionConfiguration
338+
| undefined = undefined;
339+
if (configuration) {
340+
updateCollectionConfiguration =
341+
loadApiUpdateCollectionConfigurationFromUpdateCollectionConfiguration(
342+
configuration,
343+
);
344+
}
327345
const resp = (await this.client.api.updateCollection(
328346
this.client.tenant,
329347
this.client.database,
330348
this.id,
331349
{
332350
new_name: name,
333351
new_metadata: metadata,
352+
new_configuration: updateCollectionConfiguration,
334353
},
335354
this.client.api.options,
336355
)) as CollectionParams;

0 commit comments

Comments
 (0)