Skip to content

Commit

Permalink
fix(community): ElasticVectorSearch: exclude metadata filters not wor…
Browse files Browse the repository at this point in the history
…king due changing to term instead of terms (#6688)

Co-authored-by: Laurens Tsestigh <[email protected]>
  • Loading branch information
jacoblee93 and LaurensTsestigh authored Sep 4, 2024
1 parent 6febc0c commit 2d57260
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
7 changes: 4 additions & 3 deletions libs/langchain-community/src/vectorstores/elasticsearch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -343,10 +343,11 @@ export class ElasticVectorSearch extends VectorStore {
},
});
} else if (condition.operator === "exclude") {
const toExclude = { [metadataField]: condition.value };
must_not.push({
term: {
[metadataField]: condition.value,
},
...(Array.isArray(condition.value)
? { terms: toExclude }
: { term: toExclude }),
});
} else if (condition.operator === "or") {
should.push({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,14 @@ describe("ElasticVectorSearch", () => {
},
]);
expect(results2).toHaveLength(1);
const results3 = await store.similaritySearch("*", 11, [
{
field: "a",
value: [createdAt],
operator: "exclude",
},
]);
expect(results3).toHaveLength(1);
});

test.skip("ElasticVectorSearch integration with text splitting metadata", async () => {
Expand Down

0 comments on commit 2d57260

Please sign in to comment.