Skip to content

Index

DEFAULT_PERSIST_DIR module-attribute #

DEFAULT_PERSIST_DIR = './storage'

DEFAULT_PERSIST_FNAME module-attribute #

DEFAULT_PERSIST_FNAME = 'graph_store.json'

GraphStore #

Bases: Protocol

Abstract graph store protocol.

This protocol defines the interface for a graph store, which is responsible for storing and retrieving knowledge graph data.

Attributes:

Name Type Description
client Any

Any: The client used to connect to the graph store.

get List[List[str]]

Callable[[str], List[List[str]]]: Get triplets for a given subject.

get_rel_map Dict[str, List[List[str]]]

Callable[[Optional[List[str]], int], Dict[str, List[List[str]]]]: Get subjects' rel map in max depth.

upsert_triplet None

Callable[[str, str, str], None]: Upsert a triplet.

delete None

Callable[[str, str, str], None]: Delete a triplet.

persist None

Callable[[str, Optional[fsspec.AbstractFileSystem]], None]: Persist the graph store to a file.

get_schema str

Callable[[bool], str]: Get the schema of the graph store.

Source code in llama-index-core/llama_index/core/graph_stores/types.py
 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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
@runtime_checkable
class GraphStore(Protocol):
    """Abstract graph store protocol.

    This protocol defines the interface for a graph store, which is responsible
    for storing and retrieving knowledge graph data.

    Attributes:
        client: Any: The client used to connect to the graph store.
        get: Callable[[str], List[List[str]]]: Get triplets for a given subject.
        get_rel_map: Callable[[Optional[List[str]], int], Dict[str, List[List[str]]]]:
            Get subjects' rel map in max depth.
        upsert_triplet: Callable[[str, str, str], None]: Upsert a triplet.
        delete: Callable[[str, str, str], None]: Delete a triplet.
        persist: Callable[[str, Optional[fsspec.AbstractFileSystem]], None]:
            Persist the graph store to a file.
        get_schema: Callable[[bool], str]: Get the schema of the graph store.
    """

    schema: str = ""

    @property
    def client(self) -> Any:
        """Get client."""
        ...

    def get(self, subj: str) -> List[List[str]]:
        """Get triplets."""
        ...

    def get_rel_map(
        self, subjs: Optional[List[str]] = None, depth: int = 2, limit: int = 30
    ) -> Dict[str, List[List[str]]]:
        """Get depth-aware rel map."""
        ...

    def upsert_triplet(self, subj: str, rel: str, obj: str) -> None:
        """Add triplet."""
        ...

    def delete(self, subj: str, rel: str, obj: str) -> None:
        """Delete triplet."""
        ...

    def persist(
        self, persist_path: str, fs: Optional[fsspec.AbstractFileSystem] = None
    ) -> None:
        """Persist the graph store to a file."""
        return

    def get_schema(self, refresh: bool = False) -> str:
        """Get the schema of the graph store."""
        ...

    def query(self, query: str, param_map: Optional[Dict[str, Any]] = {}) -> Any:
        """Query the graph store with statement and parameters."""
        ...

client property #

client: Any

Get client.

get #

get(subj: str) -> List[List[str]]

Get triplets.

Source code in llama-index-core/llama_index/core/graph_stores/types.py
35
36
37
def get(self, subj: str) -> List[List[str]]:
    """Get triplets."""
    ...

get_rel_map #

get_rel_map(subjs: Optional[List[str]] = None, depth: int = 2, limit: int = 30) -> Dict[str, List[List[str]]]

Get depth-aware rel map.

Source code in llama-index-core/llama_index/core/graph_stores/types.py
39
40
41
42
43
def get_rel_map(
    self, subjs: Optional[List[str]] = None, depth: int = 2, limit: int = 30
) -> Dict[str, List[List[str]]]:
    """Get depth-aware rel map."""
    ...

upsert_triplet #

upsert_triplet(subj: str, rel: str, obj: str) -> None

Add triplet.

Source code in llama-index-core/llama_index/core/graph_stores/types.py
45
46
47
def upsert_triplet(self, subj: str, rel: str, obj: str) -> None:
    """Add triplet."""
    ...

delete #

delete(subj: str, rel: str, obj: str) -> None

Delete triplet.

Source code in llama-index-core/llama_index/core/graph_stores/types.py
49
50
51
def delete(self, subj: str, rel: str, obj: str) -> None:
    """Delete triplet."""
    ...

persist #

persist(persist_path: str, fs: Optional[AbstractFileSystem] = None) -> None

Persist the graph store to a file.

Source code in llama-index-core/llama_index/core/graph_stores/types.py
53
54
55
56
57
def persist(
    self, persist_path: str, fs: Optional[fsspec.AbstractFileSystem] = None
) -> None:
    """Persist the graph store to a file."""
    return

get_schema #

get_schema(refresh: bool = False) -> str

Get the schema of the graph store.

Source code in llama-index-core/llama_index/core/graph_stores/types.py
59
60
61
def get_schema(self, refresh: bool = False) -> str:
    """Get the schema of the graph store."""
    ...

query #

query(query: str, param_map: Optional[Dict[str, Any]] = {}) -> Any

Query the graph store with statement and parameters.

Source code in llama-index-core/llama_index/core/graph_stores/types.py
63
64
65
def query(self, query: str, param_map: Optional[Dict[str, Any]] = {}) -> Any:
    """Query the graph store with statement and parameters."""
    ...