Skip to content

Commit

Permalink
Include variable scope clause in deprecated Cypher query
Browse files Browse the repository at this point in the history
  • Loading branch information
willtai committed Nov 15, 2024
1 parent f58b60b commit 2a01b8f
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 2 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ __pycache__
.mypy_cache_test
.env
.venv*
.idea
2 changes: 1 addition & 1 deletion libs/neo4j/langchain_neo4j/vectorstores/neo4j_vector.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def _get_search_index_query(
"YIELD node, score "
),
SearchType.HYBRID: (
"CALL { "
"CALL () { "
"CALL db.index.vector.queryNodes($index, $k, $embedding) "
"YIELD node, score "
"WITH collect({node:node, score:score}) AS nodes, max(score) AS max "
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
texts = ["foo", "bar", "baz", "It is the end of the world. Take shelter!"]

"""
cd tests/integration_tests/vectorstores/docker-compose
cd tests/integration_tests/docker-compose
docker-compose -f neo4j.yml up
"""

Expand Down
25 changes: 25 additions & 0 deletions libs/neo4j/tests/unit_tests/vectorstores/test_neo4j.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
"""Test Neo4j functionality."""

from langchain_neo4j.vectorstores.neo4j_vector import (
IndexType,
SearchType,
_get_search_index_query,
dict_to_yaml_str,
remove_lucene_chars,
)
Expand Down Expand Up @@ -65,3 +68,25 @@ def test_converting_to_yaml() -> None:
)

assert yaml_str == expected_output


def test_get_search_index_query_hybrid_node() -> None:
expected_query = (
"CALL () { "
"CALL db.index.vector.queryNodes($index, $k, $embedding) "
"YIELD node, score "
"WITH collect({node:node, score:score}) AS nodes, max(score) AS max "
"UNWIND nodes AS n "
"RETURN n.node AS node, (n.score / max) AS score UNION "
"CALL db.index.fulltext.queryNodes($keyword_index, $query, "
"{limit: $k}) YIELD node, score "
"WITH collect({node:node, score:score}) AS nodes, max(score) AS max "
"UNWIND nodes AS n "
"RETURN n.node AS node, (n.score / max) AS score "
"} "
"WITH node, max(score) AS score ORDER BY score DESC LIMIT $k "
)

actual_query = _get_search_index_query(SearchType.HYBRID, IndexType.NODE)

assert actual_query == expected_query

0 comments on commit 2a01b8f

Please sign in to comment.