跳到内容

索引

DEFAULT_PERSIST_DIR module-attribute #

DEFAULT_PERSIST_DIR = './storage'

DEFAULT_PERSIST_FNAME module-attribute #

DEFAULT_PERSIST_FNAME = 'graph_store.json'

GraphStore #

基类:Protocol

抽象图存储协议。

此协议定义了图存储的接口,负责存储和检索知识图谱数据。

属性

名称 类型 描述
client Any

Any: 用于连接图存储的客户端。

get 列表[列表[字符串]]

Callable[[str], List[List[str]]]: 获取给定主题的三元组。

get_rel_map 字典[字符串, 列表[列表[字符串]]]

Callable[[Optional[List[str]], int], Dict[str, List[List[str]]]]: 获取最大深度的所有主题关系映射。

upsert_triplet

Callable[[str, str, str], None]: 插入或更新三元组。

delete

Callable[[str, str, str], None]: 删除三元组。

persist

Callable[[str, Optional[fsspec.AbstractFileSystem]], None]: 将图存储持久化到文件。

get_schema str

Callable[[bool], str]: 获取图存储的模式。

源代码位于 llama-index-core/llama_index/core/graph_stores/types.py
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
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
@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 #

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

获取三元组。

源代码位于 llama-index-core/llama_index/core/graph_stores/types.py
243
244
245
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]]]

获取深度感知关系映射。

源代码位于 llama-index-core/llama_index/core/graph_stores/types.py
247
248
249
250
251
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

添加三元组。

源代码位于 llama-index-core/llama_index/core/graph_stores/types.py
253
254
255
def upsert_triplet(self, subj: str, rel: str, obj: str) -> None:
    """Add triplet."""
    ...

delete #

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

删除三元组。

源代码位于 llama-index-core/llama_index/core/graph_stores/types.py
257
258
259
def delete(self, subj: str, rel: str, obj: str) -> None:
    """Delete triplet."""
    ...

persist #

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

将图存储持久化到文件。

源代码位于 llama-index-core/llama_index/core/graph_stores/types.py
261
262
263
264
265
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

获取图存储的模式。

源代码位于 llama-index-core/llama_index/core/graph_stores/types.py
267
268
269
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

使用语句和参数查询图存储。

源代码位于 llama-index-core/llama_index/core/graph_stores/types.py
271
272
273
def query(self, query: str, param_map: Optional[Dict[str, Any]] = {}) -> Any:
    """Query the graph store with statement and parameters."""
    ...

PropertyGraphStore #

基类:ABC

抽象标注图存储协议。

此协议定义了图存储的接口,负责存储和检索知识图谱数据。

属性

名称 类型 描述
client Any

Any: 用于连接图存储的客户端。

get 列表[LabelledNode]

Callable[[str], List[List[str]]]: 获取给定主题的三元组。

get_rel_map 列表[三元组]

Callable[[Optional[List[str]], int], Dict[str, List[List[str]]]]: 获取最大深度的所有主题关系映射。

upsert_triplet 列表[三元组]

Callable[[str, str, str], None]: 插入或更新三元组。

delete

Callable[[str, str, str], None]: 删除三元组。

persist

Callable[[str, Optional[fsspec.AbstractFileSystem]], None]: 将图存储持久化到文件。

源代码位于 llama-index-core/llama_index/core/graph_stores/types.py
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
class PropertyGraphStore(ABC):
    """
    Abstract labelled 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.

    """

    supports_structured_queries: bool = False
    supports_vector_queries: bool = False
    text_to_cypher_template: PromptTemplate = DEFAULT_CYPHER_TEMPALTE

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

    @abstractmethod
    def get(
        self,
        properties: Optional[dict] = None,
        ids: Optional[List[str]] = None,
    ) -> List[LabelledNode]:
        """Get nodes with matching values."""
        ...

    @abstractmethod
    def get_triplets(
        self,
        entity_names: Optional[List[str]] = None,
        relation_names: Optional[List[str]] = None,
        properties: Optional[dict] = None,
        ids: Optional[List[str]] = None,
    ) -> List[Triplet]:
        """Get triplets with matching values."""
        ...

    @abstractmethod
    def get_rel_map(
        self,
        graph_nodes: List[LabelledNode],
        depth: int = 2,
        limit: int = 30,
        ignore_rels: Optional[List[str]] = None,
    ) -> List[Triplet]:
        """Get depth-aware rel map."""
        ...

    def get_llama_nodes(self, node_ids: List[str]) -> List[BaseNode]:
        """Get llama-index nodes."""
        nodes = self.get(ids=node_ids)
        converted_nodes = []
        for node in nodes:
            try:
                converted_nodes.append(metadata_dict_to_node(node.properties))
                converted_nodes[-1].set_content(node.text)  # type: ignore
            except Exception:
                continue

        return converted_nodes

    @abstractmethod
    def upsert_nodes(self, nodes: Sequence[LabelledNode]) -> None:
        """Upsert nodes."""
        ...

    @abstractmethod
    def upsert_relations(self, relations: List[Relation]) -> None:
        """Upsert relations."""
        ...

    def upsert_llama_nodes(self, llama_nodes: List[BaseNode]) -> None:
        """Add llama-index nodes."""
        converted_nodes = []
        for llama_node in llama_nodes:
            metadata_dict = node_to_metadata_dict(llama_node, remove_text=True)
            converted_nodes.append(
                ChunkNode(
                    text=llama_node.get_content(metadata_mode=MetadataMode.NONE),
                    id_=llama_node.id_,
                    properties=metadata_dict,
                    embedding=llama_node.embedding,
                )
            )
        self.upsert_nodes(converted_nodes)

    @abstractmethod
    def delete(
        self,
        entity_names: Optional[List[str]] = None,
        relation_names: Optional[List[str]] = None,
        properties: Optional[dict] = None,
        ids: Optional[List[str]] = None,
    ) -> None:
        """Delete matching data."""
        ...

    def delete_llama_nodes(
        self,
        node_ids: Optional[List[str]] = None,
        ref_doc_ids: Optional[List[str]] = None,
    ) -> None:
        """
        Delete llama-index nodes.

        Intended to delete any nodes in the graph store associated
        with the given llama-index node_ids or ref_doc_ids.
        """
        nodes = []

        node_ids = node_ids or []
        for id_ in node_ids:
            nodes.extend(self.get(properties={TRIPLET_SOURCE_KEY: id_}))

        if len(node_ids) > 0:
            nodes.extend(self.get(ids=node_ids))

        ref_doc_ids = ref_doc_ids or []
        for id_ in ref_doc_ids:
            nodes.extend(self.get(properties={"ref_doc_id": id_}))

        if len(ref_doc_ids) > 0:
            nodes.extend(self.get(ids=ref_doc_ids))

        self.delete(ids=[node.id for node in nodes])

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

    @abstractmethod
    def vector_query(
        self, query: VectorStoreQuery, **kwargs: Any
    ) -> Tuple[List[LabelledNode], List[float]]:
        """Query the graph store with a vector store query."""
        ...

    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) -> Any:
        """Get the schema of the graph store."""
        return None

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

    ### ----- Async Methods ----- ###

    async def aget(
        self,
        properties: Optional[dict] = None,
        ids: Optional[List[str]] = None,
    ) -> List[LabelledNode]:
        """Asynchronously get nodes with matching values."""
        return self.get(properties, ids)

    async def aget_triplets(
        self,
        entity_names: Optional[List[str]] = None,
        relation_names: Optional[List[str]] = None,
        properties: Optional[dict] = None,
        ids: Optional[List[str]] = None,
    ) -> List[Triplet]:
        """Asynchronously get triplets with matching values."""
        return self.get_triplets(entity_names, relation_names, properties, ids)

    async def aget_rel_map(
        self,
        graph_nodes: List[LabelledNode],
        depth: int = 2,
        limit: int = 30,
        ignore_rels: Optional[List[str]] = None,
    ) -> List[Triplet]:
        """Asynchronously get depth-aware rel map."""
        return self.get_rel_map(graph_nodes, depth, limit, ignore_rels)

    async def aget_llama_nodes(self, node_ids: List[str]) -> List[BaseNode]:
        """Asynchronously get nodes."""
        nodes = await self.aget(ids=node_ids)
        converted_nodes = []
        for node in nodes:
            try:
                converted_nodes.append(metadata_dict_to_node(node.properties))
                converted_nodes[-1].set_content(node.text)  # type: ignore
            except Exception:
                continue

        return converted_nodes

    async def aupsert_nodes(self, nodes: List[LabelledNode]) -> None:
        """Asynchronously add nodes."""
        return self.upsert_nodes(nodes)

    async def aupsert_relations(self, relations: List[Relation]) -> None:
        """Asynchronously add relations."""
        return self.upsert_relations(relations)

    async def adelete(
        self,
        entity_names: Optional[List[str]] = None,
        relation_names: Optional[List[str]] = None,
        properties: Optional[dict] = None,
        ids: Optional[List[str]] = None,
    ) -> None:
        """Asynchronously delete matching data."""
        return self.delete(entity_names, relation_names, properties, ids)

    async def adelete_llama_nodes(
        self,
        node_ids: Optional[List[str]] = None,
        ref_doc_ids: Optional[List[str]] = None,
    ) -> None:
        """Asynchronously delete llama-index nodes."""
        return self.delete_llama_nodes(node_ids, ref_doc_ids)

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

    async def avector_query(
        self, query: VectorStoreQuery, **kwargs: Any
    ) -> Tuple[List[LabelledNode], List[float]]:
        """Asynchronously query the graph store with a vector store query."""
        return self.vector_query(query, **kwargs)

    async def aget_schema(self, refresh: bool = False) -> str:
        """Asynchronously get the schema of the graph store."""
        return self.get_schema(refresh=refresh)

    async def aget_schema_str(self, refresh: bool = False) -> str:
        """Asynchronously get the schema of the graph store as a string."""
        return str(await self.aget_schema(refresh=refresh))

client 属性 #

client: Any

获取客户端。

get 抽象方法 #

get(properties: Optional[dict] = None, ids: Optional[List[str]] = None) -> List[LabelledNode]

获取值匹配的节点。

源代码位于 llama-index-core/llama_index/core/graph_stores/types.py
303
304
305
306
307
308
309
310
@abstractmethod
def get(
    self,
    properties: Optional[dict] = None,
    ids: Optional[List[str]] = None,
) -> List[LabelledNode]:
    """Get nodes with matching values."""
    ...

get_triplets 抽象方法 #

get_triplets(entity_names: Optional[List[str]] = None, relation_names: Optional[List[str]] = None, properties: Optional[dict] = None, ids: Optional[List[str]] = None) -> List[Triplet]

获取值匹配的三元组。

源代码位于 llama-index-core/llama_index/core/graph_stores/types.py
312
313
314
315
316
317
318
319
320
321
@abstractmethod
def get_triplets(
    self,
    entity_names: Optional[List[str]] = None,
    relation_names: Optional[List[str]] = None,
    properties: Optional[dict] = None,
    ids: Optional[List[str]] = None,
) -> List[Triplet]:
    """Get triplets with matching values."""
    ...

get_rel_map 抽象方法 #

get_rel_map(graph_nodes: List[LabelledNode], depth: int = 2, limit: int = 30, ignore_rels: Optional[List[str]] = None) -> List[Triplet]

获取深度感知关系映射。

源代码位于 llama-index-core/llama_index/core/graph_stores/types.py
323
324
325
326
327
328
329
330
331
332
@abstractmethod
def get_rel_map(
    self,
    graph_nodes: List[LabelledNode],
    depth: int = 2,
    limit: int = 30,
    ignore_rels: Optional[List[str]] = None,
) -> List[Triplet]:
    """Get depth-aware rel map."""
    ...

get_llama_nodes #

get_llama_nodes(node_ids: List[str]) -> List[BaseNode]

获取 llama-index 节点。

源代码位于 llama-index-core/llama_index/core/graph_stores/types.py
334
335
336
337
338
339
340
341
342
343
344
345
def get_llama_nodes(self, node_ids: List[str]) -> List[BaseNode]:
    """Get llama-index nodes."""
    nodes = self.get(ids=node_ids)
    converted_nodes = []
    for node in nodes:
        try:
            converted_nodes.append(metadata_dict_to_node(node.properties))
            converted_nodes[-1].set_content(node.text)  # type: ignore
        except Exception:
            continue

    return converted_nodes

upsert_nodes 抽象方法 #

upsert_nodes(nodes: Sequence[LabelledNode]) -> None

插入或更新节点。

源代码位于 llama-index-core/llama_index/core/graph_stores/types.py
347
348
349
350
@abstractmethod
def upsert_nodes(self, nodes: Sequence[LabelledNode]) -> None:
    """Upsert nodes."""
    ...

upsert_relations 抽象方法 #

upsert_relations(relations: List[Relation]) -> None

插入或更新关系。

源代码位于 llama-index-core/llama_index/core/graph_stores/types.py
352
353
354
355
@abstractmethod
def upsert_relations(self, relations: List[Relation]) -> None:
    """Upsert relations."""
    ...

upsert_llama_nodes #

upsert_llama_nodes(llama_nodes: List[BaseNode]) -> None

添加 llama-index 节点。

源代码位于 llama-index-core/llama_index/core/graph_stores/types.py
357
358
359
360
361
362
363
364
365
366
367
368
369
370
def upsert_llama_nodes(self, llama_nodes: List[BaseNode]) -> None:
    """Add llama-index nodes."""
    converted_nodes = []
    for llama_node in llama_nodes:
        metadata_dict = node_to_metadata_dict(llama_node, remove_text=True)
        converted_nodes.append(
            ChunkNode(
                text=llama_node.get_content(metadata_mode=MetadataMode.NONE),
                id_=llama_node.id_,
                properties=metadata_dict,
                embedding=llama_node.embedding,
            )
        )
    self.upsert_nodes(converted_nodes)

delete 抽象方法 #

delete(entity_names: Optional[List[str]] = None, relation_names: Optional[List[str]] = None, properties: Optional[dict] = None, ids: Optional[List[str]] = None) -> None

删除匹配数据。

源代码位于 llama-index-core/llama_index/core/graph_stores/types.py
372
373
374
375
376
377
378
379
380
381
@abstractmethod
def delete(
    self,
    entity_names: Optional[List[str]] = None,
    relation_names: Optional[List[str]] = None,
    properties: Optional[dict] = None,
    ids: Optional[List[str]] = None,
) -> None:
    """Delete matching data."""
    ...

delete_llama_nodes #

delete_llama_nodes(node_ids: Optional[List[str]] = None, ref_doc_ids: Optional[List[str]] = None) -> None

删除 llama-index 节点。

旨在删除与给定 llama-index 的 node_ids 或 ref_doc_ids 相关联的图存储中的任何节点。

源代码位于 llama-index-core/llama_index/core/graph_stores/types.py
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
def delete_llama_nodes(
    self,
    node_ids: Optional[List[str]] = None,
    ref_doc_ids: Optional[List[str]] = None,
) -> None:
    """
    Delete llama-index nodes.

    Intended to delete any nodes in the graph store associated
    with the given llama-index node_ids or ref_doc_ids.
    """
    nodes = []

    node_ids = node_ids or []
    for id_ in node_ids:
        nodes.extend(self.get(properties={TRIPLET_SOURCE_KEY: id_}))

    if len(node_ids) > 0:
        nodes.extend(self.get(ids=node_ids))

    ref_doc_ids = ref_doc_ids or []
    for id_ in ref_doc_ids:
        nodes.extend(self.get(properties={"ref_doc_id": id_}))

    if len(ref_doc_ids) > 0:
        nodes.extend(self.get(ids=ref_doc_ids))

    self.delete(ids=[node.id for node in nodes])

structured_query 抽象方法 #

structured_query(query: str, param_map: Optional[Dict[str, Any]] = None) -> Any

使用语句和参数查询图存储。

源代码位于 llama-index-core/llama_index/core/graph_stores/types.py
412
413
414
415
416
417
@abstractmethod
def structured_query(
    self, query: str, param_map: Optional[Dict[str, Any]] = None
) -> Any:
    """Query the graph store with statement and parameters."""
    ...

vector_query 抽象方法 #

vector_query(query: VectorStoreQuery, **kwargs: Any) -> Tuple[List[LabelledNode], List[float]]

使用向量存储查询图存储。

源代码位于 llama-index-core/llama_index/core/graph_stores/types.py
419
420
421
422
423
424
@abstractmethod
def vector_query(
    self, query: VectorStoreQuery, **kwargs: Any
) -> Tuple[List[LabelledNode], List[float]]:
    """Query the graph store with a vector store query."""
    ...

persist #

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

将图存储持久化到文件。

源代码位于 llama-index-core/llama_index/core/graph_stores/types.py
426
427
428
429
430
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) -> Any

获取图存储的模式。

源代码位于 llama-index-core/llama_index/core/graph_stores/types.py
432
433
434
def get_schema(self, refresh: bool = False) -> Any:
    """Get the schema of the graph store."""
    return None

get_schema_str #

get_schema_str(refresh: bool = False) -> str

获取图存储的模式字符串表示。

源代码位于 llama-index-core/llama_index/core/graph_stores/types.py
436
437
438
def get_schema_str(self, refresh: bool = False) -> str:
    """Get the schema of the graph store as a string."""
    return str(self.get_schema(refresh=refresh))

aget 异步 #

aget(properties: Optional[dict] = None, ids: Optional[List[str]] = None) -> List[LabelledNode]

异步获取值匹配的节点。

源代码位于 llama-index-core/llama_index/core/graph_stores/types.py
442
443
444
445
446
447
448
async def aget(
    self,
    properties: Optional[dict] = None,
    ids: Optional[List[str]] = None,
) -> List[LabelledNode]:
    """Asynchronously get nodes with matching values."""
    return self.get(properties, ids)

aget_triplets 异步 #

aget_triplets(entity_names: Optional[List[str]] = None, relation_names: Optional[List[str]] = None, properties: Optional[dict] = None, ids: Optional[List[str]] = None) -> List[Triplet]

异步获取值匹配的三元组。

源代码位于 llama-index-core/llama_index/core/graph_stores/types.py
450
451
452
453
454
455
456
457
458
async def aget_triplets(
    self,
    entity_names: Optional[List[str]] = None,
    relation_names: Optional[List[str]] = None,
    properties: Optional[dict] = None,
    ids: Optional[List[str]] = None,
) -> List[Triplet]:
    """Asynchronously get triplets with matching values."""
    return self.get_triplets(entity_names, relation_names, properties, ids)

aget_rel_map 异步 #

aget_rel_map(graph_nodes: List[LabelledNode], depth: int = 2, limit: int = 30, ignore_rels: Optional[List[str]] = None) -> List[Triplet]

异步获取深度感知关系映射。

源代码位于 llama-index-core/llama_index/core/graph_stores/types.py
460
461
462
463
464
465
466
467
468
async def aget_rel_map(
    self,
    graph_nodes: List[LabelledNode],
    depth: int = 2,
    limit: int = 30,
    ignore_rels: Optional[List[str]] = None,
) -> List[Triplet]:
    """Asynchronously get depth-aware rel map."""
    return self.get_rel_map(graph_nodes, depth, limit, ignore_rels)

aget_llama_nodes 异步 #

aget_llama_nodes(node_ids: List[str]) -> List[BaseNode]

异步获取节点。

源代码位于 llama-index-core/llama_index/core/graph_stores/types.py
470
471
472
473
474
475
476
477
478
479
480
481
async def aget_llama_nodes(self, node_ids: List[str]) -> List[BaseNode]:
    """Asynchronously get nodes."""
    nodes = await self.aget(ids=node_ids)
    converted_nodes = []
    for node in nodes:
        try:
            converted_nodes.append(metadata_dict_to_node(node.properties))
            converted_nodes[-1].set_content(node.text)  # type: ignore
        except Exception:
            continue

    return converted_nodes

aupsert_nodes 异步 #

aupsert_nodes(nodes: List[LabelledNode]) -> None

异步添加节点。

源代码位于 llama-index-core/llama_index/core/graph_stores/types.py
483
484
485
async def aupsert_nodes(self, nodes: List[LabelledNode]) -> None:
    """Asynchronously add nodes."""
    return self.upsert_nodes(nodes)

aupsert_relations 异步 #

aupsert_relations(relations: List[Relation]) -> None

异步添加关系。

源代码位于 llama-index-core/llama_index/core/graph_stores/types.py
487
488
489
async def aupsert_relations(self, relations: List[Relation]) -> None:
    """Asynchronously add relations."""
    return self.upsert_relations(relations)

adelete 异步 #

adelete(entity_names: Optional[List[str]] = None, relation_names: Optional[List[str]] = None, properties: Optional[dict] = None, ids: Optional[List[str]] = None) -> None

异步删除匹配数据。

源代码位于 llama-index-core/llama_index/core/graph_stores/types.py
491
492
493
494
495
496
497
498
499
async def adelete(
    self,
    entity_names: Optional[List[str]] = None,
    relation_names: Optional[List[str]] = None,
    properties: Optional[dict] = None,
    ids: Optional[List[str]] = None,
) -> None:
    """Asynchronously delete matching data."""
    return self.delete(entity_names, relation_names, properties, ids)

adelete_llama_nodes 异步 #

adelete_llama_nodes(node_ids: Optional[List[str]] = None, ref_doc_ids: Optional[List[str]] = None) -> None

异步删除 llama-index 节点。

源代码位于 llama-index-core/llama_index/core/graph_stores/types.py
501
502
503
504
505
506
507
async def adelete_llama_nodes(
    self,
    node_ids: Optional[List[str]] = None,
    ref_doc_ids: Optional[List[str]] = None,
) -> None:
    """Asynchronously delete llama-index nodes."""
    return self.delete_llama_nodes(node_ids, ref_doc_ids)

astructured_query 异步 #

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

异步使用语句和参数查询图存储。

源代码位于 llama-index-core/llama_index/core/graph_stores/types.py
509
510
511
512
513
async def astructured_query(
    self, query: str, param_map: Optional[Dict[str, Any]] = {}
) -> Any:
    """Asynchronously query the graph store with statement and parameters."""
    return self.structured_query(query, param_map)

avector_query 异步 #

avector_query(query: VectorStoreQuery, **kwargs: Any) -> Tuple[List[LabelledNode], List[float]]

异步使用向量存储查询图存储。

源代码位于 llama-index-core/llama_index/core/graph_stores/types.py
515
516
517
518
519
async def avector_query(
    self, query: VectorStoreQuery, **kwargs: Any
) -> Tuple[List[LabelledNode], List[float]]:
    """Asynchronously query the graph store with a vector store query."""
    return self.vector_query(query, **kwargs)

aget_schema 异步 #

aget_schema(refresh: bool = False) -> str

异步获取图存储的模式。

源代码位于 llama-index-core/llama_index/core/graph_stores/types.py
521
522
523
async def aget_schema(self, refresh: bool = False) -> str:
    """Asynchronously get the schema of the graph store."""
    return self.get_schema(refresh=refresh)

aget_schema_str 异步 #

aget_schema_str(refresh: bool = False) -> str

异步获取图存储的模式字符串表示。

源代码位于 llama-index-core/llama_index/core/graph_stores/types.py
525
526
527
async def aget_schema_str(self, refresh: bool = False) -> str:
    """Asynchronously get the schema of the graph store as a string."""
    return str(await self.aget_schema(refresh=refresh))