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: Bug Fix, in Neo4j VectorStore when having multiple indexes the sort is not working and the store that returned is random #17396

Merged
merged 7 commits into from
Feb 22, 2024
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