Skip to content

Commit

Permalink
community[patch]: add clientParams option to Chroma vectorstore init …
Browse files Browse the repository at this point in the history
…args (#6308)

* [community]fix: #6296 add clientParams for chromadb.

* add clientParams fields to ChromaLibArgs type

---------

Co-authored-by: Brace Sproul <[email protected]>
Co-authored-by: Jacob Lee <[email protected]>
  • Loading branch information
3 people authored Aug 3, 2024
1 parent 4fb4613 commit c8b2ffb
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 15 deletions.
2 changes: 1 addition & 1 deletion libs/langchain-community/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@
"cassandra-driver": "^4.7.2",
"cborg": "^4.1.1",
"cheerio": "^1.0.0-rc.12",
"chromadb": "^1.5.3",
"chromadb": "^1.9.1",
"closevector-common": "0.1.3",
"closevector-node": "0.1.6",
"closevector-web": "0.1.6",
Expand Down
34 changes: 21 additions & 13 deletions libs/langchain-community/src/vectorstores/chroma.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,23 @@
import * as uuid from "uuid";
import type { ChromaClient as ChromaClientT, Collection } from "chromadb";
import type {
ChromaClient as ChromaClientT,
Collection,
ChromaClientParams,
} from "chromadb";
import type { CollectionMetadata, Where } from "chromadb/dist/main/types.js";

import type { EmbeddingsInterface } from "@langchain/core/embeddings";
import { VectorStore } from "@langchain/core/vectorstores";
import { Document } from "@langchain/core/documents";

type SharedChromaLibArgs = {
numDimensions?: number;
collectionName?: string;
filter?: object;
collectionMetadata?: CollectionMetadata;
clientParams?: Omit<ChromaClientParams, "path">;
};

/**
* Defines the arguments that can be passed to the `Chroma` class
* constructor. It can either contain a `url` for the Chroma database, the
Expand All @@ -16,20 +28,12 @@ import { Document } from "@langchain/core/documents";
* `filter`.
*/
export type ChromaLibArgs =
| {
| ({
url?: string;
numDimensions?: number;
collectionName?: string;
filter?: object;
collectionMetadata?: CollectionMetadata;
}
| {
} & SharedChromaLibArgs)
| ({
index?: ChromaClientT;
numDimensions?: number;
collectionName?: string;
filter?: object;
collectionMetadata?: CollectionMetadata;
};
} & SharedChromaLibArgs);

/**
* Defines the parameters for the `delete` method in the `Chroma` class.
Expand Down Expand Up @@ -59,6 +63,8 @@ export class Chroma extends VectorStore {

numDimensions?: number;

clientParams?: Omit<ChromaClientParams, "path">;

url: string;

filter?: object;
Expand All @@ -73,6 +79,7 @@ export class Chroma extends VectorStore {
this.embeddings = embeddings;
this.collectionName = ensureCollectionName(args.collectionName);
this.collectionMetadata = args.collectionMetadata;
this.clientParams = args.clientParams;
if ("index" in args) {
this.index = args.index;
} else if ("url" in args) {
Expand Down Expand Up @@ -109,6 +116,7 @@ export class Chroma extends VectorStore {
if (!this.index) {
const chromaClient = new (await Chroma.imports()).ChromaClient({
path: this.url,
...(this.clientParams ?? {}),
});
this.index = chromaClient;
}
Expand Down
23 changes: 22 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -11178,7 +11178,7 @@ __metadata:
cassandra-driver: ^4.7.2
cborg: ^4.1.1
cheerio: ^1.0.0-rc.12
chromadb: ^1.5.3
chromadb: ^1.9.1
closevector-common: 0.1.3
closevector-node: 0.1.6
closevector-web: 0.1.6
Expand Down Expand Up @@ -21924,6 +21924,27 @@ __metadata:
languageName: node
linkType: hard

"chromadb@npm:^1.9.1":
version: 1.9.1
resolution: "chromadb@npm:1.9.1"
dependencies:
cliui: ^8.0.1
isomorphic-fetch: ^3.0.0
peerDependencies:
"@google/generative-ai": ^0.1.1
cohere-ai: ^5.0.0 || ^6.0.0 || ^7.0.0
openai: ^3.0.0 || ^4.0.0
peerDependenciesMeta:
"@google/generative-ai":
optional: true
cohere-ai:
optional: true
openai:
optional: true
checksum: 9903891ee5811ec5a50d9c94057ea54d8f09d528749478f6ce1cbed4831544788f96d2c1301f7c3453f4ac5a2dd38380f1383686003d80a09e4e7dbc0d8b11f5
languageName: node
linkType: hard

"chrome-trace-event@npm:^1.0.2":
version: 1.0.3
resolution: "chrome-trace-event@npm:1.0.3"
Expand Down

0 comments on commit c8b2ffb

Please sign in to comment.