community[minor]: Add the option to omit schema refresh in Neo4jGraph (#19654)

This commit is contained in:
Tomaz Bratanic 2024-03-27 19:20:12 +01:00 committed by GitHub
parent 5fc6531c74
commit 87d2a6b777
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -149,6 +149,8 @@ class Neo4jGraph(GraphStore):
sanitize (bool): A flag to indicate whether to remove lists with sanitize (bool): A flag to indicate whether to remove lists with
more than 128 elements from results. Useful for removing more than 128 elements from results. Useful for removing
embedding-like properties from database responses. Default is False. embedding-like properties from database responses. Default is False.
refresh_schema (bool): A flag whether to refresh schema information
at initialization. Default is True.
*Security note*: Make sure that the database connection uses credentials *Security note*: Make sure that the database connection uses credentials
that are narrowly-scoped to only include necessary permissions. that are narrowly-scoped to only include necessary permissions.
@ -170,6 +172,7 @@ class Neo4jGraph(GraphStore):
database: Optional[str] = None, database: Optional[str] = None,
timeout: Optional[float] = None, timeout: Optional[float] = None,
sanitize: bool = False, sanitize: bool = False,
refresh_schema: bool = True,
) -> None: ) -> None:
"""Create a new Neo4j graph wrapper instance.""" """Create a new Neo4j graph wrapper instance."""
try: try:
@ -211,16 +214,17 @@ class Neo4jGraph(GraphStore):
"Please ensure that the username and password are correct" "Please ensure that the username and password are correct"
) )
# Set schema # Set schema
try: if refresh_schema:
self.refresh_schema() try:
except neo4j.exceptions.ClientError as e: self.refresh_schema()
if e.code == "Neo.ClientError.Procedure.ProcedureNotFound": except neo4j.exceptions.ClientError as e:
raise ValueError( if e.code == "Neo.ClientError.Procedure.ProcedureNotFound":
"Could not use APOC procedures. " raise ValueError(
"Please ensure the APOC plugin is installed in Neo4j and that " "Could not use APOC procedures. "
"'apoc.meta.data()' is allowed in Neo4j configuration " "Please ensure the APOC plugin is installed in Neo4j and that "
) "'apoc.meta.data()' is allowed in Neo4j configuration "
raise e )
raise e
@property @property
def get_schema(self) -> str: def get_schema(self) -> str: