File size: 1,241 Bytes
5374a2d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
from enum import Enum
from abc import ABC, abstractmethod
from typing import List, Any, Dict, Optional

from llama_index.core.storage import StorageContext
from llama_index.core.indices.base import BaseIndex


class IndexType(str, Enum):
    VECTOR = "vector"
    GRAPH = "graph"
    SUMMARY = "summary"
    TREE = "tree"

class BaseIndexWrapper(ABC):
    """Base interface for index wrappers."""

    @abstractmethod
    def _create_storage_context(self) -> StorageContext:
        """Create the LlamaIndex-compatible stroage"""
        pass

    @abstractmethod
    def get_index(self) -> BaseIndex:
        """Return the LlamaIndex-compatible index."""
        pass

    @abstractmethod
    def insert_nodes(self, nodes: List[Any]):
        """Insert nodes into the index."""
        pass

    @abstractmethod
    def delete_nodes(self, node_ids: Optional[List[str]] = None, metadata_filters: Optional[Dict[str, Any]] = None) -> None:
        """Delete nodes from the index by node IDs or metadata filters."""
        pass

    @abstractmethod
    def load(self) -> None:
        """Load all nodes from the index."""
        pass

    @abstractmethod
    def clear(self) -> None:
        """Clear all nodes from the index."""
        pass