MCPcopy
hub / github.com/langchain-ai/langchain / Neo4jGraph

Class Neo4jGraph

libs/community/langchain_community/graphs/neo4j_graph.py:294–771  ·  view source on GitHub ↗

Neo4j database wrapper for various graph operations. Parameters: url (Optional[str]): The URL of the Neo4j database server. username (Optional[str]): The username for database authentication. password (Optional[str]): The password for database authentication. database (str): The

Source from the content-addressed store, hash-verified

292
293
294class Neo4jGraph(GraphStore):
295 """Neo4j database wrapper for various graph operations.
296
297 Parameters:
298 url (Optional[str]): The URL of the Neo4j database server.
299 username (Optional[str]): The username for database authentication.
300 password (Optional[str]): The password for database authentication.
301 database (str): The name of the database to connect to. Default is 'neo4j'.
302 timeout (Optional[float]): The timeout for transactions in seconds.
303 Useful for terminating long-running queries.
304 By default, there is no timeout set.
305 sanitize (bool): A flag to indicate whether to remove lists with
306 more than 128 elements from results. Useful for removing
307 embedding-like properties from database responses. Default is False.
308 refresh_schema (bool): A flag whether to refresh schema information
309 at initialization. Default is True.
310 enhanced_schema (bool): A flag whether to scan the database for
311 example values and use them in the graph schema. Default is False.
312 driver_config (Dict): Configuration passed to Neo4j Driver.
313
314 *Security note*: Make sure that the database connection uses credentials
315 that are narrowly-scoped to only include necessary permissions.
316 Failure to do so may result in data corruption or loss, since the calling
317 code may attempt commands that would result in deletion, mutation
318 of data if appropriately prompted or reading sensitive data if such
319 data is present in the database.
320 The best way to guard against such negative outcomes is to (as appropriate)
321 limit the permissions granted to the credentials used with this tool.
322
323 See https://python.langchain.com/docs/security for more information.
324 """
325
326 def __init__(
327 self,
328 url: Optional[str] = None,
329 username: Optional[str] = None,
330 password: Optional[str] = None,
331 database: Optional[str] = None,
332 timeout: Optional[float] = None,
333 sanitize: bool = False,
334 refresh_schema: bool = True,
335 *,
336 driver_config: Optional[Dict] = None,
337 enhanced_schema: bool = False,
338 ) -> None:
339 """Create a new Neo4j graph wrapper instance."""
340 try:
341 import neo4j
342 except ImportError:
343 raise ImportError(
344 "Could not import neo4j python package. "
345 "Please install it with `pip install neo4j`."
346 )
347
348 url = get_from_dict_or_env({"url": url}, "url", "NEO4J_URI")
349 username = get_from_dict_or_env(
350 {"username": username}, "username", "NEO4J_USERNAME"
351 )

Callers 15

ingest.pyFile · 0.90
ingest.pyFile · 0.90
ingest.pyFile · 0.90
utils.pyFile · 0.90
ingest.pyFile · 0.90
utils.pyFile · 0.90
ingest.pyFile · 0.90
chain.pyFile · 0.90
ingest.pyFile · 0.90
chain.pyFile · 0.90
ingest.pyFile · 0.90
chain.pyFile · 0.90

Calls

no outgoing calls

Tested by 15

test_neo4j_timeoutFunction · 0.72
test_neo4j_add_dataFunction · 0.72
test_neo4j_add_data_baseFunction · 0.72
test_driver_configFunction · 0.72
test_enhanced_schemaFunction · 0.72