From c5f336be5f3b95cde35f4154add245d1e44ab8cc Mon Sep 17 00:00:00 2001 From: commenthol Date: Tue, 12 Nov 2024 01:44:24 +0100 Subject: [PATCH] fix(community): chroma search without filter (#7183) --- libs/langchain-community/src/vectorstores/chroma.ts | 3 ++- libs/langchain-community/src/vectorstores/tests/chroma.test.ts | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/libs/langchain-community/src/vectorstores/chroma.ts b/libs/langchain-community/src/vectorstores/chroma.ts index f7dd250872b2..fd9cc08eaa9f 100644 --- a/libs/langchain-community/src/vectorstores/chroma.ts +++ b/libs/langchain-community/src/vectorstores/chroma.ts @@ -354,6 +354,7 @@ export class Chroma extends VectorStore { throw new Error("cannot provide both `filter` and `this.filter`"); } const _filter = filter ?? this.filter; + const where = _filter === undefined ? undefined : { ..._filter }; const collection = await this.ensureCollection(); @@ -362,7 +363,7 @@ export class Chroma extends VectorStore { const result = await collection.query({ queryEmbeddings: query, nResults: k, - where: { ..._filter }, + where, }); const { ids, distances, documents, metadatas } = result; diff --git a/libs/langchain-community/src/vectorstores/tests/chroma.test.ts b/libs/langchain-community/src/vectorstores/tests/chroma.test.ts index 023c36560df1..3fc58c3bedcc 100644 --- a/libs/langchain-community/src/vectorstores/tests/chroma.test.ts +++ b/libs/langchain-community/src/vectorstores/tests/chroma.test.ts @@ -128,7 +128,7 @@ describe("Chroma", () => { expect(mockCollection.query).toHaveBeenCalledWith({ queryEmbeddings: query, nResults: expectedResultCount, - where: {}, + where: undefined, }); expect(results).toHaveLength(5); });