Skip to content

Fixed issue with bool props when generating an enhanced schema #333

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

Merged
merged 4 commits into from
May 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
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
8 changes: 5 additions & 3 deletions src/neo4j_graphrag/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ def get_structured_schema(
],
'metadata': {
'constraint': [
{'id': 7, 'name': 'person_id', 'type': 'UNIQUENESS', 'entityType': 'NODE', 'labelsOrTypes': ['Persno'], 'properties': ['id'], 'ownedIndex': 'person_id', 'propertyType': None},
{'id': 7, 'name': 'person_id', 'type': 'UNIQUENESS', 'entityType': 'NODE', 'labelsOrTypes': ['Person'], 'properties': ['id'], 'ownedIndex': 'person_id', 'propertyType': None},
],
'index': [
{'label': 'Person', 'properties': ['name'], 'size': 2, 'type': 'RANGE', 'valuesSelectivity': 1.0, 'distinctValues': 2.0},
Expand Down Expand Up @@ -565,7 +565,7 @@ def _build_str_clauses(
else:
return_clauses.append(
(
f"values:`{prop_name}_values`[..{DISTINCT_VALUE_LIMIT}],"
f"values: `{prop_name}_values`[..{DISTINCT_VALUE_LIMIT}],"
f" distinct_count: size(`{prop_name}_values`)"
)
)
Expand Down Expand Up @@ -753,8 +753,10 @@ def get_enhanced_schema_cypher(
elif prop_type in ["BOOLEAN", "POINT", "DURATION"]:
continue
output_dict[prop_name] = "{" + return_clauses.pop() + "}"
if not output_dict:
return f"{match_clause}\nRETURN {{}} AS output"
# Combine with and return clauses
with_clause = "WITH " + ",\n ".join(with_clauses)
with_clause = "WITH " + ",\n ".join(with_clauses) if with_clauses else ""
Comment on lines +756 to +759
Copy link
Member

Choose a reason for hiding this comment

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

Can you add a test that covers this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've updated the unit tests to check the full query string returned by the get_enhanced_schema_cypher function.

The first two lines here are covered by the boolean, point, and duration cases of the test_get_enhanced_schema_cypher test.

The third line here is covered by the test_enhanced_schema_cypher_string_exhaustive_false_with_index test, previously the query generated by this test was:

MATCH (n:`Person`) WITH n LIMIT 5
WITH 
RETURN {`status`: {values: ['Single', 'Married', 'Divorced'], distinct_count: 3}} AS output

Which is incorrect Cypher. As we didn't check the full query we didn't catch this.

return_clause = (
"RETURN {"
+ ", ".join(f"`{k}`: {v}" for k, v in output_dict.items())
Expand Down
Loading