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

Include variable scope clause in deprecated Cypher query #6

Merged
merged 2 commits into from
Nov 18, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 () { "
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we supporting only neo4j >= 5.23 ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point, I should include the old queries for older versions

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I created another ticket to add support for Neo4j < 5.23 across the package. Feel free to add in support here but ideally we should think about exactly which versions we want to support and come up with a strategy that works across the package.

"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
Loading