diff --git a/libs/community/langchain_community/graphs/networkx_graph.py b/libs/community/langchain_community/graphs/networkx_graph.py index 28e78fcc1a7ac..35fa34664cbae 100644 --- a/libs/community/langchain_community/graphs/networkx_graph.py +++ b/libs/community/langchain_community/graphs/networkx_graph.py @@ -89,7 +89,19 @@ def from_gml(cls, gml_path: str) -> NetworkxEntityGraph: ) graph = nx.read_gml(gml_path) return cls(graph) - + + @classmethod + def from_pickle(cls, pickle_path: str) -> NetworkxEntityGraph: + try: + import pickle + except ImportError: + raise ImportError( + "Could not import pickle python package. " + "Please install it with `pip install pickle`." + ) + graph = pickle.load(open(pickle_path, 'rb')) + return cls(graph) + def add_triple(self, knowledge_triple: KnowledgeTriple) -> None: """Add a triple to the graph.""" # Creates nodes if they don't exist