Skip to content

Azure

AzureDocumentStore #

Bases: KVDocumentStore

Azure文档(Node)存储。 用于文档和节点对象的Azure表存储。

Source code in llama_index/storage/docstore/azure/base.py
 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
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
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
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
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
class AzureDocumentStore(KVDocumentStore):
    """Azure文档(Node)存储。
用于文档和节点对象的Azure表存储。"""

    _kvstore: AzureKVStore

    def __init__(
        self,
        azure_kvstore: AzureKVStore,
        namespace: Optional[str] = None,
        node_collection_suffix: Optional[str] = None,
        ref_doc_collection_suffix: Optional[str] = None,
        metadata_collection_suffix: Optional[str] = None,
        batch_size: int = DEFAULT_BATCH_SIZE,
    ) -> None:
        """初始化一个AzureDocumentStore。"""
        super().__init__(
            azure_kvstore,
            namespace,
            batch_size,
            node_collection_suffix,
            ref_doc_collection_suffix,
            metadata_collection_suffix,
        )

    @classmethod
    def from_connection_string(
        cls,
        connection_string: str,
        namespace: Optional[str] = None,
        node_collection_suffix: Optional[str] = None,
        ref_doc_collection_suffix: Optional[str] = None,
        metadata_collection_suffix: Optional[str] = None,
        service_mode: ServiceMode = ServiceMode.STORAGE,
        partition_key: Optional[str] = None,
    ) -> "AzureDocumentStore":
        """使用Azure连接字符串初始化AzureDocumentStore。"""
        azure_kvstore = AzureKVStore.from_connection_string(
            connection_string,
            service_mode=service_mode,
            partition_key=partition_key,
        )
        return cls(
            azure_kvstore,
            namespace,
            node_collection_suffix,
            ref_doc_collection_suffix,
            metadata_collection_suffix,
        )

    @classmethod
    def from_account_and_key(
        cls,
        account_name: str,
        account_key: str,
        namespace: Optional[str] = None,
        node_collection_suffix: Optional[str] = None,
        ref_doc_collection_suffix: Optional[str] = None,
        metadata_collection_suffix: Optional[str] = None,
        service_mode: ServiceMode = ServiceMode.STORAGE,
        partition_key: Optional[str] = None,
    ) -> "AzureDocumentStore":
        """从帐户名称和密钥初始化一个AzureDocumentStore。"""
        azure_kvstore = AzureKVStore.from_account_and_key(
            account_name,
            account_key,
            service_mode=service_mode,
            partition_key=partition_key,
        )
        return cls(
            azure_kvstore,
            namespace,
            node_collection_suffix,
            ref_doc_collection_suffix,
            metadata_collection_suffix,
        )

    @classmethod
    def from_sas_token(
        cls,
        endpoint: str,
        sas_token: str,
        namespace: Optional[str] = None,
        node_collection_suffix: Optional[str] = None,
        ref_doc_collection_suffix: Optional[str] = None,
        metadata_collection_suffix: Optional[str] = None,
        service_mode: ServiceMode = ServiceMode.STORAGE,
        partition_key: Optional[str] = None,
    ) -> "AzureDocumentStore":
        """使用SAS令牌初始化AzureDocumentStore。"""
        azure_kvstore = AzureKVStore.from_sas_token(
            endpoint,
            sas_token,
            service_mode=service_mode,
            partition_key=partition_key,
        )
        return cls(
            azure_kvstore,
            namespace,
            node_collection_suffix,
            ref_doc_collection_suffix,
            metadata_collection_suffix,
        )

    @classmethod
    def from_aad_token(
        cls,
        endpoint: str,
        namespace: Optional[str] = None,
        node_collection_suffix: Optional[str] = None,
        ref_doc_collection_suffix: Optional[str] = None,
        metadata_collection_suffix: Optional[str] = None,
        service_mode: ServiceMode = ServiceMode.STORAGE,
        partition_key: Optional[str] = None,
    ) -> "AzureDocumentStore":
        """使用AAD令牌初始化AzureDocumentStore。"""
        azure_kvstore = AzureKVStore.from_aad_token(
            endpoint,
            service_mode=service_mode,
            partition_key=partition_key,
        )
        return cls(
            azure_kvstore,
            namespace,
            node_collection_suffix,
            ref_doc_collection_suffix,
            metadata_collection_suffix,
        )

    def _extract_doc_metadatas(
        self, ref_doc_kv_pairs: List[Tuple[str, dict]]
    ) -> List[Tuple[str, Optional[dict]]]:
        """准备参考文档的键值对。"""
        doc_metadatas: List[Tuple[str, dict]] = [
            (doc_id, {"metadata": doc_dict.get("metadata")})
            for doc_id, doc_dict in ref_doc_kv_pairs
        ]
        return doc_metadatas

    def add_documents(
        self,
        nodes: Sequence[BaseNode],
        allow_update: bool = True,
        batch_size: Optional[int] = None,
        store_text: bool = True,
    ) -> None:
        """向存储添加文档。"""
        batch_size = batch_size or self._batch_size

        node_kv_pairs, metadata_kv_pairs, ref_doc_kv_pairs = super()._prepare_kv_pairs(
            nodes, allow_update, store_text
        )

        # Change ref_doc_kv_pairs
        ref_doc_kv_pairs = self._extract_doc_metadatas(ref_doc_kv_pairs)

        self._kvstore.put_all(
            node_kv_pairs,
            collection=self._node_collection,
            batch_size=batch_size,
        )

        self._kvstore.put_all(
            metadata_kv_pairs,
            collection=self._metadata_collection,
            batch_size=batch_size,
        )

        self._kvstore.put_all(
            ref_doc_kv_pairs,
            collection=self._ref_doc_collection,
            batch_size=batch_size,
        )

    async def async_add_documents(
        self,
        nodes: Sequence[BaseNode],
        allow_update: bool = True,
        batch_size: Optional[int] = None,
        store_text: bool = True,
    ) -> None:
        """向存储添加文档。"""
        batch_size = batch_size or self._batch_size

        (
            node_kv_pairs,
            metadata_kv_pairs,
            ref_doc_kv_pairs,
        ) = await super()._async_prepare_kv_pairs(nodes, allow_update, store_text)

        # Change ref_doc_kv_pairs
        ref_doc_kv_pairs = self._extract_doc_metadatas(ref_doc_kv_pairs)

        await asyncio.gather(
            self._kvstore.aput_all(
                node_kv_pairs,
                collection=self._node_collection,
                batch_size=batch_size,
            ),
            self._kvstore.aput_all(
                metadata_kv_pairs,
                collection=self._metadata_collection,
                batch_size=batch_size,
            ),
            self._kvstore.aput_all(
                ref_doc_kv_pairs,
                collection=self._ref_doc_collection,
                batch_size=batch_size,
            ),
        )

    def get_ref_doc_info(self, ref_doc_id: str) -> Optional[RefDocInfo]:
        """获取给定ref_doc_id的RefDocInfo。"""
        ref_doc_infos = self._kvstore.query(
            f"PartitionKey eq '{self._kvstore.partition_key}' and ref_doc_id eq '{ref_doc_id}'",
            self._metadata_collection,
            select="RowKey",
        )

        node_ids = [doc["RowKey"] for doc in ref_doc_infos]
        if not node_ids:
            return None

        doc_metadata = self._kvstore.get(
            ref_doc_id, collection=self._ref_doc_collection, select="metadata"
        )

        ref_doc_info_dict = {
            "node_ids": node_ids,
            "metadata": doc_metadata.get("metadata"),
        }

        # TODO: deprecated legacy support
        return self._remove_legacy_info(ref_doc_info_dict)

    async def aget_ref_doc_info(self, ref_doc_id: str) -> Optional[RefDocInfo]:
        """获取给定ref_doc_id的RefDocInfo。"""
        ref_doc_infos, doc_metadata = await asyncio.gather(
            self._kvstore.aquery(
                f"PartitionKey eq '{self._kvstore.partition_key}' and ref_doc_id eq '{ref_doc_id}'",
                self._metadata_collection,
                select="RowKey",
            ),
            self._kvstore.aget(
                ref_doc_id, collection=self._doc_metadata_collection, select="metadata"
            ),
        )

        node_ids = [doc["RowKey"] async for doc in ref_doc_infos]
        if not node_ids:
            return None

        ref_doc_info_dict = {
            "node_ids": node_ids,
            "metadata": doc_metadata.get("metadata"),
        }

        # TODO: deprecated legacy support
        return self._remove_legacy_info(ref_doc_info_dict)

    def get_all_ref_doc_info(self) -> Optional[Dict[str, RefDocInfo]]:
        """
        获取所有已摄取文档的 ref_doc_id -> RefDocInfo 的映射。
        """
        ref_doc_infos = self._kvstore.query(
            f"PartitionKey eq '{self._kvstore.partition_key}'",
            self._metadata_collection,
            select=["RowKey", "ref_doc_id"],
        )

        # TODO: deprecated legacy support
        all_ref_doc_infos = defaultdict(lambda: {"node_ids": [], "metadata": None})
        for ref_doc_info in ref_doc_infos:
            ref_doc_id = ref_doc_info["ref_doc_id"]
            ref_doc_info_dict = all_ref_doc_infos[ref_doc_id]
            ref_doc_info_dict["node_ids"].append(ref_doc_info["RowKey"])

            if ref_doc_info_dict["metadata"] is None:
                ref_doc = self._kvstore.get(
                    ref_doc_id, collection=self._ref_doc_collection, select="metadata"
                )
                ref_doc_info_dict["metadata"] = ref_doc.get("metadata")

        for ref_doc_id, ref_doc_info_dict in all_ref_doc_infos.items():
            all_ref_doc_infos[ref_doc_id] = self._remove_legacy_info(ref_doc_info_dict)

        return all_ref_doc_infos

    async def aget_all_ref_doc_info(self) -> Optional[Dict[str, RefDocInfo]]:
        """
        获取所有已摄取文档的 ref_doc_id -> RefDocInfo 的映射。
        """
        ref_doc_infos = await self._kvstore.aquery(
            f"PartitionKey eq '{self._kvstore.partition_key}'",
            self._metadata_collection,
            select=["RowKey", "ref_doc_id"],
        )

        # TODO: deprecated legacy support
        all_ref_doc_infos = defaultdict(lambda: {"node_ids": [], "metadata": None})
        async for ref_doc_info in ref_doc_infos:
            ref_doc_id = ref_doc_info["ref_doc_id"]
            ref_doc_info_dict = all_ref_doc_infos[ref_doc_id]
            ref_doc_info_dict["node_ids"].append(ref_doc_info["RowKey"])

            if ref_doc_info_dict["metadata"] is None:
                ref_doc = await self._kvstore.aget(
                    ref_doc_id, collection=self._ref_doc_collection, select="metadata"
                )
                ref_doc_info_dict["metadata"] = ref_doc.get("metadata")

        for ref_doc_id, ref_doc_info_dict in all_ref_doc_infos.items():
            all_ref_doc_infos[ref_doc_id] = self._remove_legacy_info(ref_doc_info_dict)

        return all_ref_doc_infos

    def _remove_from_ref_doc_node(self, doc_id: str) -> None:
        """辅助函数,用于从ref_doc_collection中移除节点doc_id。
如果ref_doc没有更多的doc_ids,则从集合中删除它。
"""
        self._kvstore.delete(doc_id, collection=self._metadata_collection)

    async def _aremove_from_ref_doc_node(self, doc_id: str) -> None:
        """辅助函数,用于从ref_doc_collection中移除节点doc_id。
如果ref_doc没有更多的doc_ids,则从集合中删除它。
"""
        await self._kvstore.adelete(doc_id, collection=self._metadata_collection)

from_connection_string classmethod #

from_connection_string(
    connection_string: str,
    namespace: Optional[str] = None,
    node_collection_suffix: Optional[str] = None,
    ref_doc_collection_suffix: Optional[str] = None,
    metadata_collection_suffix: Optional[str] = None,
    service_mode: ServiceMode = ServiceMode.STORAGE,
    partition_key: Optional[str] = None,
) -> AzureDocumentStore

使用Azure连接字符串初始化AzureDocumentStore。

Source code in llama_index/storage/docstore/azure/base.py
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
@classmethod
def from_connection_string(
    cls,
    connection_string: str,
    namespace: Optional[str] = None,
    node_collection_suffix: Optional[str] = None,
    ref_doc_collection_suffix: Optional[str] = None,
    metadata_collection_suffix: Optional[str] = None,
    service_mode: ServiceMode = ServiceMode.STORAGE,
    partition_key: Optional[str] = None,
) -> "AzureDocumentStore":
    """使用Azure连接字符串初始化AzureDocumentStore。"""
    azure_kvstore = AzureKVStore.from_connection_string(
        connection_string,
        service_mode=service_mode,
        partition_key=partition_key,
    )
    return cls(
        azure_kvstore,
        namespace,
        node_collection_suffix,
        ref_doc_collection_suffix,
        metadata_collection_suffix,
    )

from_account_and_key classmethod #

from_account_and_key(
    account_name: str,
    account_key: str,
    namespace: Optional[str] = None,
    node_collection_suffix: Optional[str] = None,
    ref_doc_collection_suffix: Optional[str] = None,
    metadata_collection_suffix: Optional[str] = None,
    service_mode: ServiceMode = ServiceMode.STORAGE,
    partition_key: Optional[str] = None,
) -> AzureDocumentStore

从帐户名称和密钥初始化一个AzureDocumentStore。

Source code in llama_index/storage/docstore/azure/base.py
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
@classmethod
def from_account_and_key(
    cls,
    account_name: str,
    account_key: str,
    namespace: Optional[str] = None,
    node_collection_suffix: Optional[str] = None,
    ref_doc_collection_suffix: Optional[str] = None,
    metadata_collection_suffix: Optional[str] = None,
    service_mode: ServiceMode = ServiceMode.STORAGE,
    partition_key: Optional[str] = None,
) -> "AzureDocumentStore":
    """从帐户名称和密钥初始化一个AzureDocumentStore。"""
    azure_kvstore = AzureKVStore.from_account_and_key(
        account_name,
        account_key,
        service_mode=service_mode,
        partition_key=partition_key,
    )
    return cls(
        azure_kvstore,
        namespace,
        node_collection_suffix,
        ref_doc_collection_suffix,
        metadata_collection_suffix,
    )

from_sas_token classmethod #

from_sas_token(
    endpoint: str,
    sas_token: str,
    namespace: Optional[str] = None,
    node_collection_suffix: Optional[str] = None,
    ref_doc_collection_suffix: Optional[str] = None,
    metadata_collection_suffix: Optional[str] = None,
    service_mode: ServiceMode = ServiceMode.STORAGE,
    partition_key: Optional[str] = None,
) -> AzureDocumentStore

使用SAS令牌初始化AzureDocumentStore。

Source code in llama_index/storage/docstore/azure/base.py
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
@classmethod
def from_sas_token(
    cls,
    endpoint: str,
    sas_token: str,
    namespace: Optional[str] = None,
    node_collection_suffix: Optional[str] = None,
    ref_doc_collection_suffix: Optional[str] = None,
    metadata_collection_suffix: Optional[str] = None,
    service_mode: ServiceMode = ServiceMode.STORAGE,
    partition_key: Optional[str] = None,
) -> "AzureDocumentStore":
    """使用SAS令牌初始化AzureDocumentStore。"""
    azure_kvstore = AzureKVStore.from_sas_token(
        endpoint,
        sas_token,
        service_mode=service_mode,
        partition_key=partition_key,
    )
    return cls(
        azure_kvstore,
        namespace,
        node_collection_suffix,
        ref_doc_collection_suffix,
        metadata_collection_suffix,
    )

from_aad_token classmethod #

from_aad_token(
    endpoint: str,
    namespace: Optional[str] = None,
    node_collection_suffix: Optional[str] = None,
    ref_doc_collection_suffix: Optional[str] = None,
    metadata_collection_suffix: Optional[str] = None,
    service_mode: ServiceMode = ServiceMode.STORAGE,
    partition_key: Optional[str] = None,
) -> AzureDocumentStore

使用AAD令牌初始化AzureDocumentStore。

Source code in llama_index/storage/docstore/azure/base.py
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
@classmethod
def from_aad_token(
    cls,
    endpoint: str,
    namespace: Optional[str] = None,
    node_collection_suffix: Optional[str] = None,
    ref_doc_collection_suffix: Optional[str] = None,
    metadata_collection_suffix: Optional[str] = None,
    service_mode: ServiceMode = ServiceMode.STORAGE,
    partition_key: Optional[str] = None,
) -> "AzureDocumentStore":
    """使用AAD令牌初始化AzureDocumentStore。"""
    azure_kvstore = AzureKVStore.from_aad_token(
        endpoint,
        service_mode=service_mode,
        partition_key=partition_key,
    )
    return cls(
        azure_kvstore,
        namespace,
        node_collection_suffix,
        ref_doc_collection_suffix,
        metadata_collection_suffix,
    )

add_documents #

add_documents(
    nodes: Sequence[BaseNode],
    allow_update: bool = True,
    batch_size: Optional[int] = None,
    store_text: bool = True,
) -> None

向存储添加文档。

Source code in llama_index/storage/docstore/azure/base.py
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
def add_documents(
    self,
    nodes: Sequence[BaseNode],
    allow_update: bool = True,
    batch_size: Optional[int] = None,
    store_text: bool = True,
) -> None:
    """向存储添加文档。"""
    batch_size = batch_size or self._batch_size

    node_kv_pairs, metadata_kv_pairs, ref_doc_kv_pairs = super()._prepare_kv_pairs(
        nodes, allow_update, store_text
    )

    # Change ref_doc_kv_pairs
    ref_doc_kv_pairs = self._extract_doc_metadatas(ref_doc_kv_pairs)

    self._kvstore.put_all(
        node_kv_pairs,
        collection=self._node_collection,
        batch_size=batch_size,
    )

    self._kvstore.put_all(
        metadata_kv_pairs,
        collection=self._metadata_collection,
        batch_size=batch_size,
    )

    self._kvstore.put_all(
        ref_doc_kv_pairs,
        collection=self._ref_doc_collection,
        batch_size=batch_size,
    )

async_add_documents async #

async_add_documents(
    nodes: Sequence[BaseNode],
    allow_update: bool = True,
    batch_size: Optional[int] = None,
    store_text: bool = True,
) -> None

向存储添加文档。

Source code in llama_index/storage/docstore/azure/base.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
async def async_add_documents(
    self,
    nodes: Sequence[BaseNode],
    allow_update: bool = True,
    batch_size: Optional[int] = None,
    store_text: bool = True,
) -> None:
    """向存储添加文档。"""
    batch_size = batch_size or self._batch_size

    (
        node_kv_pairs,
        metadata_kv_pairs,
        ref_doc_kv_pairs,
    ) = await super()._async_prepare_kv_pairs(nodes, allow_update, store_text)

    # Change ref_doc_kv_pairs
    ref_doc_kv_pairs = self._extract_doc_metadatas(ref_doc_kv_pairs)

    await asyncio.gather(
        self._kvstore.aput_all(
            node_kv_pairs,
            collection=self._node_collection,
            batch_size=batch_size,
        ),
        self._kvstore.aput_all(
            metadata_kv_pairs,
            collection=self._metadata_collection,
            batch_size=batch_size,
        ),
        self._kvstore.aput_all(
            ref_doc_kv_pairs,
            collection=self._ref_doc_collection,
            batch_size=batch_size,
        ),
    )

get_ref_doc_info #

get_ref_doc_info(ref_doc_id: str) -> Optional[RefDocInfo]

获取给定ref_doc_id的RefDocInfo。

Source code in llama_index/storage/docstore/azure/base.py
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
def get_ref_doc_info(self, ref_doc_id: str) -> Optional[RefDocInfo]:
    """获取给定ref_doc_id的RefDocInfo。"""
    ref_doc_infos = self._kvstore.query(
        f"PartitionKey eq '{self._kvstore.partition_key}' and ref_doc_id eq '{ref_doc_id}'",
        self._metadata_collection,
        select="RowKey",
    )

    node_ids = [doc["RowKey"] for doc in ref_doc_infos]
    if not node_ids:
        return None

    doc_metadata = self._kvstore.get(
        ref_doc_id, collection=self._ref_doc_collection, select="metadata"
    )

    ref_doc_info_dict = {
        "node_ids": node_ids,
        "metadata": doc_metadata.get("metadata"),
    }

    # TODO: deprecated legacy support
    return self._remove_legacy_info(ref_doc_info_dict)

aget_ref_doc_info async #

aget_ref_doc_info(ref_doc_id: str) -> Optional[RefDocInfo]

获取给定ref_doc_id的RefDocInfo。

Source code in llama_index/storage/docstore/azure/base.py
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
async def aget_ref_doc_info(self, ref_doc_id: str) -> Optional[RefDocInfo]:
    """获取给定ref_doc_id的RefDocInfo。"""
    ref_doc_infos, doc_metadata = await asyncio.gather(
        self._kvstore.aquery(
            f"PartitionKey eq '{self._kvstore.partition_key}' and ref_doc_id eq '{ref_doc_id}'",
            self._metadata_collection,
            select="RowKey",
        ),
        self._kvstore.aget(
            ref_doc_id, collection=self._doc_metadata_collection, select="metadata"
        ),
    )

    node_ids = [doc["RowKey"] async for doc in ref_doc_infos]
    if not node_ids:
        return None

    ref_doc_info_dict = {
        "node_ids": node_ids,
        "metadata": doc_metadata.get("metadata"),
    }

    # TODO: deprecated legacy support
    return self._remove_legacy_info(ref_doc_info_dict)

get_all_ref_doc_info #

get_all_ref_doc_info() -> Optional[Dict[str, RefDocInfo]]

获取所有已摄取文档的 ref_doc_id -> RefDocInfo 的映射。

Source code in llama_index/storage/docstore/azure/base.py
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
def get_all_ref_doc_info(self) -> Optional[Dict[str, RefDocInfo]]:
    """
    获取所有已摄取文档的 ref_doc_id -> RefDocInfo 的映射。
    """
    ref_doc_infos = self._kvstore.query(
        f"PartitionKey eq '{self._kvstore.partition_key}'",
        self._metadata_collection,
        select=["RowKey", "ref_doc_id"],
    )

    # TODO: deprecated legacy support
    all_ref_doc_infos = defaultdict(lambda: {"node_ids": [], "metadata": None})
    for ref_doc_info in ref_doc_infos:
        ref_doc_id = ref_doc_info["ref_doc_id"]
        ref_doc_info_dict = all_ref_doc_infos[ref_doc_id]
        ref_doc_info_dict["node_ids"].append(ref_doc_info["RowKey"])

        if ref_doc_info_dict["metadata"] is None:
            ref_doc = self._kvstore.get(
                ref_doc_id, collection=self._ref_doc_collection, select="metadata"
            )
            ref_doc_info_dict["metadata"] = ref_doc.get("metadata")

    for ref_doc_id, ref_doc_info_dict in all_ref_doc_infos.items():
        all_ref_doc_infos[ref_doc_id] = self._remove_legacy_info(ref_doc_info_dict)

    return all_ref_doc_infos

aget_all_ref_doc_info async #

aget_all_ref_doc_info() -> Optional[Dict[str, RefDocInfo]]

获取所有已摄取文档的 ref_doc_id -> RefDocInfo 的映射。

Source code in llama_index/storage/docstore/azure/base.py
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
async def aget_all_ref_doc_info(self) -> Optional[Dict[str, RefDocInfo]]:
    """
    获取所有已摄取文档的 ref_doc_id -> RefDocInfo 的映射。
    """
    ref_doc_infos = await self._kvstore.aquery(
        f"PartitionKey eq '{self._kvstore.partition_key}'",
        self._metadata_collection,
        select=["RowKey", "ref_doc_id"],
    )

    # TODO: deprecated legacy support
    all_ref_doc_infos = defaultdict(lambda: {"node_ids": [], "metadata": None})
    async for ref_doc_info in ref_doc_infos:
        ref_doc_id = ref_doc_info["ref_doc_id"]
        ref_doc_info_dict = all_ref_doc_infos[ref_doc_id]
        ref_doc_info_dict["node_ids"].append(ref_doc_info["RowKey"])

        if ref_doc_info_dict["metadata"] is None:
            ref_doc = await self._kvstore.aget(
                ref_doc_id, collection=self._ref_doc_collection, select="metadata"
            )
            ref_doc_info_dict["metadata"] = ref_doc.get("metadata")

    for ref_doc_id, ref_doc_info_dict in all_ref_doc_infos.items():
        all_ref_doc_infos[ref_doc_id] = self._remove_legacy_info(ref_doc_info_dict)

    return all_ref_doc_infos