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

community[patch]: Fix neo4j vector for multiple indexes #4390

Merged
merged 1 commit into from
Feb 13, 2024
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
3 changes: 1 addition & 2 deletions libs/langchain-community/src/vectorstores/neo4j_vector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -519,8 +519,7 @@ export class Neo4jVectorStore extends VectorStore {
): Array<{ [key: string]: any }> {
return values.sort(
(a, b) =>
(a.index_name === indexName ? -1 : 0) -
(b.index_name === indexName ? -1 : 0)
(a.name === indexName ? -1 : 0) - (b.name === indexName ? -1 : 0)
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -516,3 +516,83 @@ test.skip("Test escape lucene characters", async () => {
await dropVectorIndexes(neo4jVectorStore);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey there! I noticed that this PR includes changes that access and use environment variables via process.env. I've flagged this for maintainers to review and ensure that the handling of environment variables aligns with best practices. Great work on the PR!

await neo4jVectorStore.close();
});

test.skip("Test multiple index", async () => {
const url = process.env.NEO4J_URI as string;
const username = process.env.NEO4J_USERNAME as string;
const password = process.env.NEO4J_PASSWORD as string;

expect(url).toBeDefined();
expect(username).toBeDefined();
expect(password).toBeDefined();

const embeddings = new FakeEmbeddingsWithOsDimension();
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const metadatas: any[] = [];

const foo = await Neo4jVectorStore.fromTexts(["foo"], metadatas, embeddings, {
url,
username,
password,
indexName: "Foo",
nodeLabel: "Foo",
});

const bar = await Neo4jVectorStore.fromTexts(["bar"], metadatas, embeddings, {
url,
username,
password,
indexName: "Bar",
nodeLabel: "Bar",
});

const fooExistingIndex = await Neo4jVectorStore.fromExistingIndex(
embeddings,
{
url,
username,
password,
indexName: "Foo",
}
);

const fooOutput = await fooExistingIndex.similaritySearch(
"This is the end of the world!",
1
);
const fooExpectedResult = [
new Document({
pageContent: "foo",
metadata: {},
}),
];
expect(fooOutput).toStrictEqual(fooExpectedResult);

const barExistingIndex = await Neo4jVectorStore.fromExistingIndex(
embeddings,
{
url,
username,
password,
indexName: "Bar",
}
);

const barOutput = await barExistingIndex.similaritySearch(
"This is the end of the world!",
1
);
const barExpectedResult = [
new Document({
pageContent: "bar",
metadata: {},
}),
];
expect(barOutput).toStrictEqual(barExpectedResult);

await dropVectorIndexes(barExistingIndex);
await foo.close();
await bar.close();
await barExistingIndex.close();
await fooExistingIndex.close();
});
Loading