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
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
@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
227
228
229
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
231
232
233
234
235
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
237
238
239
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
241
242
243
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
245
246
247
248
249
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
251
252
253
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
255
256
257
def query(self, query: str, param_map: Optional[Dict[str, Any]] = {}) -> Any:
    """Query the graph store with statement and parameters."""
    ...