Skip to content

Commit

Permalink
Fix neo4j vector for multiple indexes (#4390)
Browse files Browse the repository at this point in the history
  • Loading branch information
tomasonjo committed Feb 13, 2024
1 parent ad2a078 commit 87cd549
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 2 deletions.
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);
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();
});

0 comments on commit 87cd549

Please sign in to comment.