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 86bee58
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
Expand Up @@ -5,6 +5,8 @@
remove_lucene_chars,
)

from langchain_neo4j.vectorstores.neo4j_vector import _get_search_index_query, SearchType, IndexType

Check failure on line 8 in libs/neo4j/tests/unit_tests/vectorstores/test_neo4j.py

View workflow job for this annotation

GitHub Actions / cd libs/neo4j / make lint #3.9

Ruff (E501)

tests/unit_tests/vectorstores/test_neo4j.py:8:89: E501 Line too long (100 > 88)


def test_escaping_lucene() -> None:

Check failure on line 11 in libs/neo4j/tests/unit_tests/vectorstores/test_neo4j.py

View workflow job for this annotation

GitHub Actions / cd libs/neo4j / make lint #3.9

Ruff (I001)

tests/unit_tests/vectorstores/test_neo4j.py:3:1: I001 Import block is un-sorted or un-formatted
"""Test escaping lucene characters"""
Expand Down Expand Up @@ -65,3 +67,26 @@ def test_converting_to_yaml() -> None:
)

assert yaml_str == expected_output


def test_get_search_index_query_hybrid_node():
"""Test that the hybrid search query is constructed correctly with node index type."""

Check failure on line 73 in libs/neo4j/tests/unit_tests/vectorstores/test_neo4j.py

View workflow job for this annotation

GitHub Actions / cd libs/neo4j / make lint #3.9

Ruff (E501)

tests/unit_tests/vectorstores/test_neo4j.py:73:89: E501 Line too long (90 > 88)
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 86bee58

Please sign in to comment.