diff --git a/.gitignore b/.gitignore index 45d553b..716a06f 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,4 @@ __pycache__ .mypy_cache_test .env .venv* +.idea \ No newline at end of file diff --git a/libs/neo4j/langchain_neo4j/vectorstores/neo4j_vector.py b/libs/neo4j/langchain_neo4j/vectorstores/neo4j_vector.py index 863de6d..ffbd8e7 100644 --- a/libs/neo4j/langchain_neo4j/vectorstores/neo4j_vector.py +++ b/libs/neo4j/langchain_neo4j/vectorstores/neo4j_vector.py @@ -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 " diff --git a/libs/neo4j/tests/integration_tests/vectorstores/test_neo4jvector.py b/libs/neo4j/tests/integration_tests/vectorstores/test_neo4jvector.py index f9c92c2..ccf62c6 100644 --- a/libs/neo4j/tests/integration_tests/vectorstores/test_neo4jvector.py +++ b/libs/neo4j/tests/integration_tests/vectorstores/test_neo4jvector.py @@ -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 """ diff --git a/libs/neo4j/tests/unit_tests/vectorstores/test_neo4j.py b/libs/neo4j/tests/unit_tests/vectorstores/test_neo4j.py index 72b371f..a98c622 100644 --- a/libs/neo4j/tests/unit_tests/vectorstores/test_neo4j.py +++ b/libs/neo4j/tests/unit_tests/vectorstores/test_neo4j.py @@ -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, ) @@ -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