feat(graph): add GraphBackend abstract interface

This commit is contained in:
Ubuntu 2026-04-25 11:11:06 +00:00
parent a6437df335
commit a75b7cf75a
6 changed files with 57 additions and 0 deletions

0
backend/__init__.py Normal file
View File

View File

@ -0,0 +1 @@
# Populated in Task 4 once factory.py exists

38
backend/app/graph/base.py Normal file
View File

@ -0,0 +1,38 @@
"""Abstract graph backend interface."""
from abc import ABC, abstractmethod
from typing import Any, Dict, List, Optional
class GraphBackend(ABC):
@abstractmethod
def create_graph(self, graph_id: str, name: str, description: str = "") -> None: ...
@abstractmethod
def set_ontology(self, graph_ids: List[str], entities: Dict[str, Any], edges: Dict[str, Any]) -> None: ...
@abstractmethod
def add_batch(self, graph_id: str, episodes: List[Any]) -> List[str]: ...
@abstractmethod
def get_episode(self, uuid_: str) -> Any: ...
@abstractmethod
def get_all_nodes(self, graph_id: str) -> List[Dict[str, Any]]: ...
@abstractmethod
def get_all_edges(self, graph_id: str) -> List[Dict[str, Any]]: ...
@abstractmethod
def get_node(self, uuid_: str) -> Dict[str, Any]: ...
@abstractmethod
def get_node_edges(self, node_uuid: str) -> List[Dict[str, Any]]: ...
@abstractmethod
def search(self, graph_id: str, query: str, limit: int = 10, scope: str = "edges") -> Dict[str, Any]: ...
@abstractmethod
def add_text(self, graph_id: str, data: str) -> None: ...
@abstractmethod
def delete_graph(self, graph_id: str) -> None: ...

View File

View File

@ -0,0 +1,13 @@
import pytest
from unittest.mock import MagicMock, patch
def test_graph_backend_has_required_methods():
from backend.app.graph.base import GraphBackend
required = [
"create_graph", "set_ontology", "add_batch", "get_episode",
"get_all_nodes", "get_all_edges", "get_node", "get_node_edges",
"search", "add_text", "delete_graph",
]
for method in required:
assert hasattr(GraphBackend, method), f"GraphBackend missing: {method}"

5
conftest.py Normal file
View File

@ -0,0 +1,5 @@
import sys
import os
# Allow `import backend.app.*` from the project root
sys.path.insert(0, os.path.dirname(__file__))