From 4191f808e2073700c77993723a321603d2d783d7 Mon Sep 17 00:00:00 2001 From: guyifeng Date: Thu, 1 Aug 2024 16:35:53 +0800 Subject: [PATCH] [community]fix: #6296 add clientParams for chromadb. --- libs/langchain-community/package.json | 2 +- .../src/vectorstores/chroma.ts | 8 +++++-- yarn.lock | 23 ++++++++++++++++++- 3 files changed, 29 insertions(+), 4 deletions(-) diff --git a/libs/langchain-community/package.json b/libs/langchain-community/package.json index cfd3a5a12113d..b65dd49c6a2e9 100644 --- a/libs/langchain-community/package.json +++ b/libs/langchain-community/package.json @@ -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", diff --git a/libs/langchain-community/src/vectorstores/chroma.ts b/libs/langchain-community/src/vectorstores/chroma.ts index b8db6da5d125e..a78164bd50dcf 100644 --- a/libs/langchain-community/src/vectorstores/chroma.ts +++ b/libs/langchain-community/src/vectorstores/chroma.ts @@ -1,5 +1,5 @@ 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"; @@ -59,6 +59,8 @@ export class Chroma extends VectorStore { numDimensions?: number; + clientParams?: Omit; + url: string; filter?: object; @@ -67,12 +69,13 @@ export class Chroma extends VectorStore { return "chroma"; } - constructor(embeddings: EmbeddingsInterface, args: ChromaLibArgs) { + constructor(embeddings: EmbeddingsInterface, args: ChromaLibArgs & {clientParams?: Omit}) { super(embeddings, args); this.numDimensions = args.numDimensions; 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) { @@ -109,6 +112,7 @@ export class Chroma extends VectorStore { if (!this.index) { const chromaClient = new (await Chroma.imports()).ChromaClient({ path: this.url, + ...(this.clientParams ?? {}) }); this.index = chromaClient; } diff --git a/yarn.lock b/yarn.lock index 0d55295d7d8a5..009db606f20fc 100644 --- a/yarn.lock +++ b/yarn.lock @@ -11179,7 +11179,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 @@ -21917,6 +21917,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"