From f8ffdb4df5ad50409dadc94f9dc61d3f0d1bd270 Mon Sep 17 00:00:00 2001 From: hajdul88 <52442977+hajdul88@users.noreply.github.com> Date: Tue, 12 Nov 2024 16:47:34 +0100 Subject: [PATCH] feat: Adds cognee abstract graph class --- .../graph/cognee_graph/CogneeAbstractGraph.py | 44 +++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 cognee/modules/graph/cognee_graph/CogneeAbstractGraph.py diff --git a/cognee/modules/graph/cognee_graph/CogneeAbstractGraph.py b/cognee/modules/graph/cognee_graph/CogneeAbstractGraph.py new file mode 100644 index 000000000..7c8db8ac3 --- /dev/null +++ b/cognee/modules/graph/cognee_graph/CogneeAbstractGraph.py @@ -0,0 +1,44 @@ +from abc import ABC, abstractmethod +from typing import List, Dict, Union +from CogneeGraphElements import Node, Edge +from cognee.infrastructure.databases.graph.neo4j_driver.adapter import Neo4jAdapter +from cognee.infrastructure.databases.graph.networkx.adapter import NetworkXAdapter + +class CogneeAbstractGraph(ABC): + """ + Abstract base class for representing a graph structure. + + Attributes: + nodes (Dict[str, Node]): A dictionary of nodes in the graph, keyed by their ID. + edges (List[Edge]): A list of edges in the graph. + """ + + def __init__(self): + self.nodes: Dict[str, Node] = {} + self.edges: List[Edge] = [] # :TODO do we need it in hashtable? Do we want to index? + + @abstractmethod + def add_node(self, node: Node) -> None: + """Add a node to the graph.""" + pass + + # :TODO Add dimension + @abstractmethod + def add_edge(self, edge: Edge) -> None: + """Add an edge to the graph.""" + pass + + @abstractmethod + def get_node(self, node_id: str) -> Node: + """Retrieve a node by its ID.""" + pass + + @abstractmethod + def get_edges(self, node_id: str) -> List[Edge]: + """Retrieve edges connected to a specific node.""" + pass + + @abstractmethod + async def project_graph_from_db(self, adapter: Union[Neo4jAdapter, NetworkXAdapter]) -> None: + """Project the graph structure from a database using the provided adapter.""" + pass