跳到内容

Redis

RedisDocumentStore #

基类: KVDocumentStore

Redis 文档(节点)存储。

一个用于存储 Document 和 Node 对象的 Redis 存储。

参数

名称 类型 描述 默认值
redis_kvstore RedisKVStore

Redis 键值存储

必填
namespace str

docstore 的命名空间

源代码位于 llama-index-integrations/storage/docstore/llama-index-storage-docstore-redis/llama_index/storage/docstore/redis/base.py
 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
47
48
49
50
class RedisDocumentStore(KVDocumentStore):
    """
    Redis Document (Node) store.

    A Redis store for Document and Node objects.

    Args:
        redis_kvstore (RedisKVStore): Redis key-value store
        namespace (str): namespace for the docstore

    """

    def __init__(
        self,
        redis_kvstore: RedisKVStore,
        namespace: Optional[str] = None,
        batch_size: int = DEFAULT_BATCH_SIZE,
    ) -> None:
        """Init a RedisDocumentStore."""
        super().__init__(redis_kvstore, namespace=namespace, batch_size=batch_size)
        # avoid conflicts with redis index store
        self._node_collection = f"{self._namespace}/doc"

    @classmethod
    def from_redis_client(
        cls,
        redis_client: Any,
        namespace: Optional[str] = None,
    ) -> "RedisDocumentStore":
        """Load a RedisDocumentStore from a Redis Client."""
        redis_kvstore = RedisKVStore.from_redis_client(redis_client=redis_client)
        return cls(redis_kvstore, namespace)

    @classmethod
    def from_host_and_port(
        cls,
        host: str,
        port: int,
        namespace: Optional[str] = None,
    ) -> "RedisDocumentStore":
        """Load a RedisDocumentStore from a Redis host and port."""
        redis_kvstore = RedisKVStore.from_host_and_port(host, port)
        return cls(redis_kvstore, namespace)

from_redis_client classmethod #

from_redis_client(redis_client: Any, namespace: Optional[str] = None) -> RedisDocumentStore

从 Redis 客户端加载 RedisDocumentStore。

源代码位于 llama-index-integrations/storage/docstore/llama-index-storage-docstore-redis/llama_index/storage/docstore/redis/base.py
31
32
33
34
35
36
37
38
39
@classmethod
def from_redis_client(
    cls,
    redis_client: Any,
    namespace: Optional[str] = None,
) -> "RedisDocumentStore":
    """Load a RedisDocumentStore from a Redis Client."""
    redis_kvstore = RedisKVStore.from_redis_client(redis_client=redis_client)
    return cls(redis_kvstore, namespace)

from_host_and_port classmethod #

from_host_and_port(host: str, port: int, namespace: Optional[str] = None) -> RedisDocumentStore

从 Redis 主机和端口加载 RedisDocumentStore。

源代码位于 llama-index-integrations/storage/docstore/llama-index-storage-docstore-redis/llama_index/storage/docstore/redis/base.py
41
42
43
44
45
46
47
48
49
50
@classmethod
def from_host_and_port(
    cls,
    host: str,
    port: int,
    namespace: Optional[str] = None,
) -> "RedisDocumentStore":
    """Load a RedisDocumentStore from a Redis host and port."""
    redis_kvstore = RedisKVStore.from_host_and_port(host, port)
    return cls(redis_kvstore, namespace)