Skip to content

Commit 5a7a640

Browse files
ZacZac
authored andcommitted
fix linting
1 parent 32b614b commit 5a7a640

File tree

1 file changed

+16
-14
lines changed

1 file changed

+16
-14
lines changed

examples/retrieve/tools/cypher_template_to_tool_example.py

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -50,17 +50,20 @@
5050
actor_names
5151
"""
5252

53+
5354
class CypherTemplateRetriever(Retriever):
5455
"""
5556
Custom retriever that executes a parameterized Cypher query template.
5657
"""
57-
58+
5859
def __init__(
5960
self,
6061
driver: neo4j.Driver,
6162
cypher_template: str,
6263
neo4j_database: Optional[str] = None,
63-
result_formatter: Optional[callable] = None
64+
result_formatter: Optional[
65+
Callable[[neo4j.Record], RetrieverResultItem]
66+
] = None,
6467
):
6568
"""
6669
Args:
@@ -72,36 +75,36 @@ def __init__(
7275
super().__init__(driver, neo4j_database)
7376
self.cypher_template = cypher_template
7477
self.result_formatter = result_formatter
75-
78+
7679
def get_search_results(
7780
self,
7881
query_vector: Optional[list[float]] = None,
7982
query_text: Optional[str] = None,
8083
top_k: int = 5,
8184
query_params: Optional[Dict[str, Any]] = None,
82-
**kwargs
85+
**kwargs: Any,
8386
) -> RawSearchResult:
8487
"""
8588
Execute the Cypher template with provided parameters.
86-
89+
8790
Args:
8891
query_text: Can be used as a parameter (e.g., for movie title)
8992
query_params: Dictionary of parameters for the Cypher query
9093
**kwargs: Additional parameters
91-
94+
9295
Returns:
9396
RawSearchResult containing neo4j.Record objects
9497
"""
9598
# Prepare parameters for the Cypher query
9699
parameters = query_params or {}
97-
100+
98101
# Optionally use query_text as a parameter
99102
if query_text and "query_text" not in parameters:
100103
parameters["query_text"] = query_text
101-
104+
102105
# Add any additional kwargs as parameters
103106
parameters.update(kwargs)
104-
107+
105108
# Execute the query
106109
try:
107110
records, summary, keys = self.driver.execute_query(
@@ -110,19 +113,18 @@ def get_search_results(
110113
database_=self.neo4j_database,
111114
routing_=neo4j.RoutingControl.READ,
112115
)
113-
116+
114117
return RawSearchResult(
115118
records=records,
116119
metadata={
117120
"cypher_query": self.cypher_template,
118-
"parameters": parameters
119-
}
121+
"parameters": parameters,
122+
},
120123
)
121124
except Exception as e:
122125
raise RuntimeError(f"Failed to execute Cypher template: {e}") from e
123126

124127

125-
126128
def main() -> None:
127129
"""Run the example."""
128130
driver = neo4j.GraphDatabase.driver(URI, auth=AUTH)
@@ -145,7 +147,7 @@ def main() -> None:
145147
"Dictionary containing 'title' key with the movie title to analyze. "
146148
"Example: {'title': 'The Matrix'}"
147149
)
148-
}
150+
},
149151
)
150152

151153
llm = OpenAILLM(

0 commit comments

Comments
 (0)