mirror of
https://github.com/hwchase17/langchain.git
synced 2025-06-28 09:28:48 +00:00
community[patch]: Bug Neo4j VectorStore when having multiple indexes the sort is not working and the store that returned is random (#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.
This commit is contained in:
parent
242981b8f0
commit
9e54c227f1
@ -77,7 +77,7 @@ def sort_by_index_name(
|
|||||||
lst: List[Dict[str, Any]], index_name: str
|
lst: List[Dict[str, Any]], index_name: str
|
||||||
) -> List[Dict[str, Any]]:
|
) -> List[Dict[str, Any]]:
|
||||||
"""Sort first element to match the index_name if exists"""
|
"""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:
|
def remove_lucene_chars(text: str) -> str:
|
||||||
|
@ -678,3 +678,46 @@ def test_hybrid_score_normalization() -> None:
|
|||||||
# Both FT and Vector must return 1.0 score
|
# Both FT and Vector must return 1.0 score
|
||||||
assert output == [{"text": "foo", "score": 1.0}, {"text": "foo", "score": 1.0}]
|
assert output == [{"text": "foo", "score": 1.0}, {"text": "foo", "score": 1.0}]
|
||||||
drop_vector_indexes(docsearch)
|
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
|
||||||
|
Loading…
Reference in New Issue
Block a user