langchain_community.graphs.age_graph.AGEGraph¶

class langchain_community.graphs.age_graph.AGEGraph(graph_name: str, conf: Dict[str, Any], create: bool = True)[source]¶

Apache AGE wrapper for graph operations.

Parameters
  • graph_name (str) – the name of the graph to connect to or create

  • conf (Dict[str, Any]) – the pgsql connection config passed directly to psycopg2.connect

  • create (bool) – if True and graph doesn’t exist, attempt to create it

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.

Create a new AGEGraph instance.

Attributes

get_schema

Returns the schema of the Graph

get_structured_schema

Returns the structured schema of the Graph

label_regex

types

Methods

__init__(graph_name, conf[, create])

Create a new AGEGraph instance.

add_graph_documents(graph_documents[, ...])

insert a list of graph documents into the graph

clean_graph_labels(label)

remove any disallowed characters from a label and replace with '_'

query(query[, params])

Query the graph by taking a cypher query, converting it to an age compatible query, executing it and converting the result

refresh_schema()

Refresh the graph schema information by updating the available labels, relationships, and properties

__init__(graph_name: str, conf: Dict[str, Any], create: bool = True) None[source]¶

Create a new AGEGraph instance.

Parameters
  • graph_name (str) –

  • conf (Dict[str, Any]) –

  • create (bool) –

Return type

None

add_graph_documents(graph_documents: List[GraphDocument], include_source: bool = False) None[source]¶

insert a list of graph documents into the graph

Parameters
  • graph_documents (List[GraphDocument]) – the list of documents to be inserted

  • include_source (bool) – if True add nodes for the sources with MENTIONS edges to the entities they mention

Returns

None

Return type

None

static clean_graph_labels(label: str) str[source]¶

remove any disallowed characters from a label and replace with ‘_’

Parameters

label (str) – the original label

Returns

the sanitized version of the label

Return type

str

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

Query the graph by taking a cypher query, converting it to an age compatible query, executing it and converting the result

Parameters
  • query (str) – a cypher query to be executed

  • params (dict) – parameters for the query (not used in this implementation)

Returns

a list of dictionaries containing the result set

Return type

List[Dict[str, Any]]

refresh_schema() None[source]¶

Refresh the graph schema information by updating the available labels, relationships, and properties

Return type

None

Examples using AGEGraph¶