-
Notifications
You must be signed in to change notification settings - Fork 74
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
Add CypherRetriever for parameterized Cypher queries #307
base: main
Are you sure you want to change the base?
Conversation
This PR adds a new CypherRetriever that enables direct database access through parameterized Cypher queries. Key features include: - Type-safe parameter validation - Support for optional parameters - Custom result formatting - Documentation and examples 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
@CodiumAI-Agent /update_changelog |
Changelog updates: 🔄 2025-03-14Added
|
Graph Traversals | ||
--------------- | ||
|
||
The CypherRetriever is particularly useful for complex graph traversals: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure I see the point here, especially the example does not show a really complex graph traversal?
count = record["count"] if record else 0 | ||
|
||
if count == 0: | ||
print("No movie data found. Creating sample data...") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can use the neo4j+s://demo.neo4jlabs.com
database here, so we're sure it's already populated.
) | ||
except ValidationError as e: | ||
raise RetrieverInitializationError( | ||
[ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've never used this syntax but I think from e
will show the same informations (loc, etc)? In such case we do not need ErrorDestail
, which looks like an internal pydantic thing.
) | ||
|
||
# Validate the type of each parameter | ||
for param_name, param_value in parameters.items(): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can this be merged into a single loop?
"""Definition of a Cypher query parameter.""" | ||
|
||
type: CypherParameterType | ||
description: str |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can the description be optional? We're not using it (yet)
self, | ||
driver: neo4j.Driver, | ||
query: str, | ||
parameters: Dict[str, Dict[str, Any]], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we can use list[CypherParameterDefinition]
with the @validate_call
decorator (see for instance here)
from neo4j_graphrag.types import RetrieverResultItem | ||
|
||
|
||
class TestCypherRetriever(unittest.TestCase): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A bit nitpicking here but we do not use class-based tests in this code base, only functions. So unless there is a strong reason to use a class, I'd prefer we stick to using functions :)
This PR adds a new CypherRetriever that enables direct database access through parameterized Cypher queries. Key features include:
Description
Type of Change
How Has This Been Tested?
Checklist
The following requirements should have been met (depending on the changes in the branch):