mirror of
https://github.com/hwchase17/langchain.git
synced 2025-08-09 21:08:59 +00:00
Add session expired retry to neo4j graph (#26182)
Co-authored-by: Erick Friis <erick@langchain.dev>
This commit is contained in:
parent
b3c7ed4913
commit
181e4fc0e0
@ -410,7 +410,9 @@ class Neo4jGraph(GraphStore):
|
|||||||
"""Returns the structured schema of the Graph"""
|
"""Returns the structured schema of the Graph"""
|
||||||
return self.structured_schema
|
return self.structured_schema
|
||||||
|
|
||||||
def query(self, query: str, params: dict = {}) -> List[Dict[str, Any]]:
|
def query(
|
||||||
|
self, query: str, params: dict = {}, retry_on_session_expired: bool = True
|
||||||
|
) -> List[Dict[str, Any]]:
|
||||||
"""Query Neo4j database.
|
"""Query Neo4j database.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
@ -421,7 +423,7 @@ class Neo4jGraph(GraphStore):
|
|||||||
List[Dict[str, Any]]: The list of dictionaries containing the query results.
|
List[Dict[str, Any]]: The list of dictionaries containing the query results.
|
||||||
"""
|
"""
|
||||||
from neo4j import Query
|
from neo4j import Query
|
||||||
from neo4j.exceptions import CypherSyntaxError
|
from neo4j.exceptions import CypherSyntaxError, SessionExpired
|
||||||
|
|
||||||
with self._driver.session(database=self._database) as session:
|
with self._driver.session(database=self._database) as session:
|
||||||
try:
|
try:
|
||||||
@ -432,6 +434,15 @@ class Neo4jGraph(GraphStore):
|
|||||||
return json_data
|
return json_data
|
||||||
except CypherSyntaxError as e:
|
except CypherSyntaxError as e:
|
||||||
raise ValueError(f"Generated Cypher Statement is not valid\n{e}")
|
raise ValueError(f"Generated Cypher Statement is not valid\n{e}")
|
||||||
|
except (
|
||||||
|
SessionExpired
|
||||||
|
) as e: # Session expired is a transient error that can be retried
|
||||||
|
if retry_on_session_expired:
|
||||||
|
return self.query(
|
||||||
|
query, params=params, retry_on_session_expired=False
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
raise e
|
||||||
|
|
||||||
def refresh_schema(self) -> None:
|
def refresh_schema(self) -> None:
|
||||||
"""
|
"""
|
||||||
|
Loading…
Reference in New Issue
Block a user