KuzuGraph#

class langchain_community.graphs.kuzu_graph.KuzuGraph(db: Any, database: str = 'kuzu', allow_dangerous_requests: bool = False)[source]#

Kùzu wrapper for graph operations.

Security note: Make sure that the database connection uses credentials

that are narrowly-scoped to only include necessary permissions. Failure to do so may result in data corruption or loss, since the calling code may attempt commands that would result in deletion, mutation of data if appropriately prompted or reading sensitive data if such data is present in the database. The best way to guard against such negative outcomes is to (as appropriate) limit the permissions granted to the credentials used with this tool.

See https://python.langchain.com/docs/security for more information.

Initializes the Kùzu graph database connection.

Attributes

get_schema

Returns the schema of the Kùzu database

Methods

__init__(db[, database, ...])

Initializes the Kùzu graph database connection.

add_graph_documents(graph_documents, ...[, ...])

Adds a list of GraphDocument objects that represent nodes and relationships in a graph to a Kùzu backend.

query(query[, params])

Query Kùzu database

refresh_schema()

Refreshes the Kùzu graph schema information

Parameters:
  • db (Any)

  • database (str)

  • allow_dangerous_requests (bool)

__init__(db: Any, database: str = 'kuzu', allow_dangerous_requests: bool = False) None[source]#

Initializes the Kùzu graph database connection.

Parameters:
  • db (Any)

  • database (str)

  • allow_dangerous_requests (bool)

Return type:

None

add_graph_documents(graph_documents: List[GraphDocument], allowed_relationships: List[Tuple[str, str, str]], include_source: bool = False) None[source]#

Adds a list of GraphDocument objects that represent nodes and relationships in a graph to a Kùzu backend.

Parameters:
  • graph_documents (-) – A list of GraphDocument objects that contain the nodes and relationships to be added to the graph. Each GraphDocument should encapsulate the structure of part of the graph, including nodes, relationships, and the source document information.

  • allowed_relationships (-) – A list of allowed relationships that exist in the graph. Each tuple contains three elements: the source node type, the relationship type, and the target node type. Required for Kùzu, as the names of the relationship tables that need to pre-exist are derived from these tuples.

  • include_source (-) – If True, stores the source document and links it to nodes in the graph using the MENTIONS relationship. This is useful for tracing back the origin of data. Merges source documents based on the id property from the source document metadata if available; otherwise it calculates the MD5 hash of page_content for merging process. Defaults to False.

Return type:

None

query(query: str, params: dict = {}) List[Dict[str, Any]][source]#

Query Kùzu database

Parameters:
  • query (str)

  • params (dict)

Return type:

List[Dict[str, Any]]

refresh_schema() None[source]#

Refreshes the Kùzu graph schema information

Return type:

None

Examples using KuzuGraph