Skip to content

Commit

Permalink
community[patch]: Bug Neo4j VectorStore when having multiple indexes …
Browse files Browse the repository at this point in the history
…the sort is not working and the store that returned is random (langchain-ai#17396)

Bug fix: when having multiple indexes the sort is not working and the
store that returned is random.
The following small fix resolves the issue.
  • Loading branch information
ehude authored and al1p-R committed Feb 27, 2024
1 parent 6b1e41b commit 9f06aaa
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def sort_by_index_name(
lst: List[Dict[str, Any]], index_name: str
) -> List[Dict[str, Any]]:
"""Sort first element to match the index_name if exists"""
return sorted(lst, key=lambda x: x.get("index_name") != index_name)
return sorted(lst, key=lambda x: x.get("name") != index_name)


def remove_lucene_chars(text: str) -> str:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -678,3 +678,46 @@ def test_hybrid_score_normalization() -> None:
# Both FT and Vector must return 1.0 score
assert output == [{"text": "foo", "score": 1.0}, {"text": "foo", "score": 1.0}]
drop_vector_indexes(docsearch)


def test_index_fetching() -> None:
"""testing correct index creation and fetching"""
embeddings = FakeEmbeddings()

def create_store(
node_label: str, index: str, text_properties: List[str]
) -> Neo4jVector:
return Neo4jVector.from_existing_graph(
embedding=embeddings,
url=url,
username=username,
password=password,
index_name=index,
node_label=node_label,
text_node_properties=text_properties,
embedding_node_property="embedding",
)

def fetch_store(index_name: str) -> Neo4jVector:
store = Neo4jVector.from_existing_index(
embedding=embeddings,
url=url,
username=username,
password=password,
index_name=index_name,
)
return store

# create index 0
index_0_str = "index0"
create_store("label0", index_0_str, ["text"])

# create index 1
index_1_str = "index1"
create_store("label1", index_1_str, ["text"])

index_1_store = fetch_store(index_1_str)
assert index_1_store.index_name == index_1_str

index_0_store = fetch_store(index_0_str)
assert index_0_store.index_name == index_0_str

0 comments on commit 9f06aaa

Please sign in to comment.