Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(community): ElasticVectorSearch: add a not_exists filter #7036

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions libs/langchain-community/src/vectorstores/elasticsearch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,12 @@ export class ElasticVectorSearch extends VectorStore {
field: metadataField,
},
});
} else if (condition.operator === "not_exists") {
must_not.push({
exists: {
field: metadataField,
},
});
} else if (condition.operator === "exclude") {
const toExclude = { [metadataField]: condition.value };
must_not.push({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,8 @@ describe("ElasticVectorSearch", () => {
{ pageContent: "responsible", metadata: { a: createdAt } },
{ pageContent: "friendly", metadata: { a: createdAt } },
{ pageContent: "confident", metadata: { a: createdAt } },
{ pageContent: "generous", metadata: { a: createdAt } },
{ pageContent: "compassionate", metadata: { a: createdAt } },
{ pageContent: "generous", metadata: { a: null } },
{ pageContent: "compassionate", metadata: {} },
]);
const results = await store.similaritySearch("*", 11);
expect(results).toHaveLength(11);
Expand All @@ -113,15 +113,22 @@ describe("ElasticVectorSearch", () => {
operator: "exclude",
},
]);
expect(results2).toHaveLength(1);
expect(results2).toHaveLength(3);
const results3 = await store.similaritySearch("*", 11, [
{
field: "a",
value: [createdAt],
operator: "exclude",
},
]);
expect(results3).toHaveLength(1);
expect(results3).toHaveLength(3);
const results4 = await store.similaritySearch("*", 11, [
{
field: "a",
operator: "not_exists",
},
]);
expect(results4).toHaveLength(2);
});

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