From 62e36f60ac12dfbcdc666210dd1abc70184039ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christoph=20H=C3=B6ller?= Date: Thu, 15 Aug 2024 12:46:30 +0200 Subject: [PATCH 1/2] community[patch]: fix: ElasticVectorSearch: exclude metadata filters not working due to syntax error in filter creation --- libs/langchain-community/src/vectorstores/elasticsearch.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/langchain-community/src/vectorstores/elasticsearch.ts b/libs/langchain-community/src/vectorstores/elasticsearch.ts index 81f480c3f1fc..14a4ee12ac03 100644 --- a/libs/langchain-community/src/vectorstores/elasticsearch.ts +++ b/libs/langchain-community/src/vectorstores/elasticsearch.ts @@ -344,7 +344,7 @@ export class ElasticVectorSearch extends VectorStore { }); } else if (condition.operator === "exclude") { must_not.push({ - terms: { + term: { [metadataField]: condition.value, }, }); From e9a8e24de86731f33d822c4143923fac31bc3dc6 Mon Sep 17 00:00:00 2001 From: jacoblee93 Date: Fri, 16 Aug 2024 01:45:28 -0700 Subject: [PATCH 2/2] Adds integration test --- .../src/vectorstores/tests/elasticsearch.int.test.ts | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/libs/langchain-community/src/vectorstores/tests/elasticsearch.int.test.ts b/libs/langchain-community/src/vectorstores/tests/elasticsearch.int.test.ts index cc22163c7763..08ec39ac0f57 100644 --- a/libs/langchain-community/src/vectorstores/tests/elasticsearch.int.test.ts +++ b/libs/langchain-community/src/vectorstores/tests/elasticsearch.int.test.ts @@ -106,6 +106,14 @@ describe("ElasticVectorSearch", () => { ]); const results = await store.similaritySearch("*", 11); expect(results).toHaveLength(11); + const results2 = await store.similaritySearch("*", 11, [ + { + field: "a", + value: createdAt, + operator: "exclude", + }, + ]); + expect(results2).toHaveLength(1); }); test.skip("ElasticVectorSearch integration with text splitting metadata", async () => {