mirror of
https://github.com/hwchase17/langchain.git
synced 2025-06-21 14:18:52 +00:00
community[patch]: Add driver config param for neo4j graph (#20772)
Co-authored-by: Bagatur <baskaryan@gmail.com>
This commit is contained in:
parent
13751c3297
commit
9efab3ed66
@ -151,6 +151,7 @@ class Neo4jGraph(GraphStore):
|
|||||||
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
|
refresh_schema (bool): A flag whether to refresh schema information
|
||||||
at initialization. Default is True.
|
at initialization. Default is True.
|
||||||
|
driver_config (Dict): Configuration passed to Neo4j Driver.
|
||||||
|
|
||||||
*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.
|
||||||
@ -173,6 +174,8 @@ class Neo4jGraph(GraphStore):
|
|||||||
timeout: Optional[float] = None,
|
timeout: Optional[float] = None,
|
||||||
sanitize: bool = False,
|
sanitize: bool = False,
|
||||||
refresh_schema: bool = True,
|
refresh_schema: bool = True,
|
||||||
|
*,
|
||||||
|
driver_config: Optional[Dict] = None,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Create a new Neo4j graph wrapper instance."""
|
"""Create a new Neo4j graph wrapper instance."""
|
||||||
try:
|
try:
|
||||||
@ -194,7 +197,9 @@ class Neo4jGraph(GraphStore):
|
|||||||
{"database": database}, "database", "NEO4J_DATABASE", "neo4j"
|
{"database": database}, "database", "NEO4J_DATABASE", "neo4j"
|
||||||
)
|
)
|
||||||
|
|
||||||
self._driver = neo4j.GraphDatabase.driver(url, auth=(username, password))
|
self._driver = neo4j.GraphDatabase.driver(
|
||||||
|
url, auth=(username, password), **(driver_config or {})
|
||||||
|
)
|
||||||
self._database = database
|
self._database = database
|
||||||
self.timeout = timeout
|
self.timeout = timeout
|
||||||
self.sanitize = sanitize
|
self.sanitize = sanitize
|
||||||
|
@ -273,3 +273,21 @@ def test_neo4j_filtering_labels() -> None:
|
|||||||
# Assert both are empty
|
# Assert both are empty
|
||||||
assert graph.structured_schema["node_props"] == {}
|
assert graph.structured_schema["node_props"] == {}
|
||||||
assert graph.structured_schema["relationships"] == []
|
assert graph.structured_schema["relationships"] == []
|
||||||
|
|
||||||
|
|
||||||
|
def test_driver_config() -> None:
|
||||||
|
"""Test that neo4j works with driver config."""
|
||||||
|
url = os.environ.get("NEO4J_URI")
|
||||||
|
username = os.environ.get("NEO4J_USERNAME")
|
||||||
|
password = os.environ.get("NEO4J_PASSWORD")
|
||||||
|
assert url is not None
|
||||||
|
assert username is not None
|
||||||
|
assert password is not None
|
||||||
|
|
||||||
|
graph = Neo4jGraph(
|
||||||
|
url=url,
|
||||||
|
username=username,
|
||||||
|
password=password,
|
||||||
|
driver_config={"max_connection_pool_size": 1},
|
||||||
|
)
|
||||||
|
graph.query("RETURN 'foo'")
|
||||||
|
Loading…
Reference in New Issue
Block a user