NetworkxEntityGraph#

class langchain_community.graphs.networkx_graph.NetworkxEntityGraph(graph: Any | None = None)[source]#

Networkx wrapper for entity 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.

Create a new graph.

Methods

__init__([graph])

Create a new graph.

add_node(node)

Add node in the graph.

add_triple(knowledge_triple)

Add a triple to the graph.

clear()

Clear the graph.

clear_edges()

Clear the graph edges.

delete_triple(knowledge_triple)

Delete a triple from the graph.

draw_graphviz(**kwargs)

Provides better drawing

from_gml(gml_path)

get_entity_knowledge(entity[, depth])

Get information about an entity.

get_neighbors(node)

Return the neighbor nodes of the given node.

get_number_of_nodes()

Get number of nodes in the graph.

get_topological_sort()

Get a list of entity names in the graph sorted by causal dependence.

get_triples()

Get all triples in the graph.

has_edge(source_node, destination_node)

Return if graph has an edge between the given nodes.

has_node(node)

Return if graph has the given node.

remove_edge(source_node, destination_node)

Remove edge from the graph.

remove_node(node)

Remove node from the graph.

write_to_gml(path)

Parameters:

graph (Optional[Any])

__init__(graph: Any | None = None) None[source]#

Create a new graph.

Parameters:

graph (Any | None)

Return type:

None

add_node(node: str) None[source]#

Add node in the graph.

Parameters:

node (str)

Return type:

None

add_triple(knowledge_triple: KnowledgeTriple) None[source]#

Add a triple to the graph.

Parameters:

knowledge_triple (KnowledgeTriple)

Return type:

None

clear() None[source]#

Clear the graph.

Return type:

None

clear_edges() None[source]#

Clear the graph edges.

Return type:

None

delete_triple(knowledge_triple: KnowledgeTriple) None[source]#

Delete a triple from the graph.

Parameters:

knowledge_triple (KnowledgeTriple)

Return type:

None

draw_graphviz(**kwargs: Any) None[source]#

Provides better drawing

Usage in a jupyter notebook:

>>> from IPython.display import SVG
>>> self.draw_graphviz_svg(layout="dot", filename="web.svg")
>>> SVG('web.svg')
Parameters:

kwargs (Any)

Return type:

None

classmethod from_gml(gml_path: str) NetworkxEntityGraph[source]#
Parameters:

gml_path (str)

Return type:

NetworkxEntityGraph

get_entity_knowledge(entity: str, depth: int = 1) List[str][source]#

Get information about an entity.

Parameters:
  • entity (str)

  • depth (int)

Return type:

List[str]

get_neighbors(node: str) List[str][source]#

Return the neighbor nodes of the given node.

Parameters:

node (str)

Return type:

List[str]

get_number_of_nodes() int[source]#

Get number of nodes in the graph.

Return type:

int

get_topological_sort() List[str][source]#

Get a list of entity names in the graph sorted by causal dependence.

Return type:

List[str]

get_triples() List[Tuple[str, str, str]][source]#

Get all triples in the graph.

Return type:

List[Tuple[str, str, str]]

has_edge(source_node: str, destination_node: str) bool[source]#

Return if graph has an edge between the given nodes.

Parameters:
  • source_node (str)

  • destination_node (str)

Return type:

bool

has_node(node: str) bool[source]#

Return if graph has the given node.

Parameters:

node (str)

Return type:

bool

remove_edge(source_node: str, destination_node: str) None[source]#

Remove edge from the graph.

Parameters:
  • source_node (str)

  • destination_node (str)

Return type:

None

remove_node(node: str) None[source]#

Remove node from the graph.

Parameters:

node (str)

Return type:

None

write_to_gml(path: str) None[source]#
Parameters:

path (str)

Return type:

None

Examples using NetworkxEntityGraph