Skip to content

Commit

Permalink
Add duplicate elementId(node) as nodeId
Browse files Browse the repository at this point in the history
  • Loading branch information
willtai committed Oct 30, 2024
1 parent 8971ac6 commit b6b27f7
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 12 deletions.
6 changes: 3 additions & 3 deletions src/neo4j_graphrag/neo4j_queries.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ def get_search_query(
"""
warnings.warn(
"The default returned 'id' field in the search results will be renamed to 'node_id' in a future version.",
"The default returned 'id' field in the search results will be removed. Please switch to using 'nodeId' instead.",
DeprecationWarning,
stacklevel=2,
)
Expand Down Expand Up @@ -233,7 +233,7 @@ def get_search_query(
query_tail = get_query_tail(
retrieval_query,
return_properties,
fallback_return=f"RETURN node {{ .*, `{embedding_node_property}`: null }} AS node, labels(node) AS nodeLabels, elementId(node) AS id, score",
fallback_return=f"RETURN node {{ .*, `{embedding_node_property}`: null }} AS node, labels(node) AS nodeLabels, elementId(node) AS nodeId, elementId(node) AS id, score",
)
return f"{query} {query_tail}", params

Expand All @@ -259,5 +259,5 @@ def get_query_tail(
return retrieval_query
if return_properties:
return_properties_cypher = ", ".join([f".{prop}" for prop in return_properties])
return f"RETURN node {{{return_properties_cypher}}} AS node, labels(node) AS nodeLabels, elementId(node) AS id, score"
return f"RETURN node {{{return_properties_cypher}}} AS node, labels(node) AS nodeLabels, elementId(node) AS nodeId, elementId(node) AS id, score"
return fallback_return if fallback_return else ""
2 changes: 1 addition & 1 deletion tests/unit/retrievers/external/test_weaviate.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ def test_match_query_with_return_properties() -> None:
"WITH match_param[0] AS match_id_value, match_param[1] AS score "
"MATCH (node) "
"WHERE node[$id_property] = match_id_value "
"RETURN node {.name, .age} AS node, labels(node) AS nodeLabels, elementId(node) AS id, score"
"RETURN node {.name, .age} AS node, labels(node) AS nodeLabels, elementId(node) AS nodeId, elementId(node) AS id, score"
)
assert match_query.strip() == expected.strip()

Expand Down
16 changes: 8 additions & 8 deletions tests/unit/test_neo4j_queries.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def test_vector_search_basic() -> None:
expected = (
"CALL db.index.vector.queryNodes($vector_index_name, $top_k, $query_vector) "
"YIELD node, score "
"RETURN node { .*, `None`: null } AS node, labels(node) AS nodeLabels, elementId(node) AS id, score"
"RETURN node { .*, `None`: null } AS node, labels(node) AS nodeLabels, elementId(node) AS nodeId, elementId(node) AS id, score"
)
result, params = get_search_query(SearchType.VECTOR)
assert result.strip() == expected.strip()
Expand All @@ -45,7 +45,7 @@ def test_hybrid_search_basic() -> None:
"RETURN n.node AS node, (n.score / ft_index_max_score) AS score "
"} "
"WITH node, max(score) AS score ORDER BY score DESC LIMIT $top_k "
"RETURN node { .*, `None`: null } AS node, labels(node) AS nodeLabels, elementId(node) AS id, score"
"RETURN node { .*, `None`: null } AS node, labels(node) AS nodeLabels, elementId(node) AS nodeId, elementId(node) AS id, score"
)
result, _ = get_search_query(SearchType.HYBRID)
assert result.strip() == expected.strip()
Expand All @@ -56,7 +56,7 @@ def test_vector_search_with_properties() -> None:
expected = (
"CALL db.index.vector.queryNodes($vector_index_name, $top_k, $query_vector) "
"YIELD node, score "
"RETURN node {.name, .age} AS node, labels(node) AS nodeLabels, elementId(node) AS id, score"
"RETURN node {.name, .age} AS node, labels(node) AS nodeLabels, elementId(node) AS nodeId, elementId(node) AS id, score"
)
result, _ = get_search_query(SearchType.VECTOR, return_properties=properties)
assert result.strip() == expected.strip()
Expand All @@ -82,7 +82,7 @@ def test_vector_search_with_filters(_mock: Any) -> None:
"WITH node, "
"vector.similarity.cosine(node.`vector`, $query_vector) AS score "
"ORDER BY score DESC LIMIT $top_k "
"RETURN node { .*, `vector`: null } AS node, labels(node) AS nodeLabels, elementId(node) AS id, score"
"RETURN node { .*, `vector`: null } AS node, labels(node) AS nodeLabels, elementId(node) AS nodeId, elementId(node) AS id, score"
)
result, params = get_search_query(
SearchType.VECTOR,
Expand All @@ -108,7 +108,7 @@ def test_vector_search_with_params_from_filters(_mock: Any) -> None:
"WITH node, "
"vector.similarity.cosine(node.`vector`, $query_vector) AS score "
"ORDER BY score DESC LIMIT $top_k "
"RETURN node { .*, `vector`: null } AS node, labels(node) AS nodeLabels, elementId(node) AS id, score"
"RETURN node { .*, `vector`: null } AS node, labels(node) AS nodeLabels, elementId(node) AS nodeId, elementId(node) AS id, score"
)
result, params = get_search_query(
SearchType.VECTOR,
Expand Down Expand Up @@ -159,7 +159,7 @@ def test_hybrid_search_with_properties() -> None:
"RETURN n.node AS node, (n.score / ft_index_max_score) AS score "
"} "
"WITH node, max(score) AS score ORDER BY score DESC LIMIT $top_k "
"RETURN node {.name, .age} AS node, labels(node) AS nodeLabels, elementId(node) AS id, score"
"RETURN node {.name, .age} AS node, labels(node) AS nodeLabels, elementId(node) AS nodeId, elementId(node) AS id, score"
)
result, _ = get_search_query(SearchType.HYBRID, return_properties=properties)
assert result.strip() == expected.strip()
Expand All @@ -174,7 +174,7 @@ def test_get_query_tail_with_retrieval_query() -> None:

def test_get_query_tail_with_properties() -> None:
properties = ["name", "age"]
expected = "RETURN node {.name, .age} AS node, labels(node) AS nodeLabels, elementId(node) AS id, score"
expected = "RETURN node {.name, .age} AS node, labels(node) AS nodeLabels, elementId(node) AS nodeId, elementId(node) AS id, score"
result = get_query_tail(return_properties=properties)
assert result.strip() == expected.strip()

Expand Down Expand Up @@ -204,7 +204,7 @@ def test_get_query_tail_ordering_no_retrieval_query() -> None:
properties = ["name", "age"]
fallback = "HELLO"

expected = "RETURN node {.name, .age} AS node, labels(node) AS nodeLabels, elementId(node) AS id, score"
expected = "RETURN node {.name, .age} AS node, labels(node) AS nodeLabels, elementId(node) AS nodeId, elementId(node) AS id, score"
result = get_query_tail(
return_properties=properties,
fallback_return=fallback,
Expand Down

0 comments on commit b6b27f7

Please sign in to comment.