From 64e4ca5c15081d37c793f17e4ad952204c3d85e5 Mon Sep 17 00:00:00 2001 From: hailin Date: Sun, 11 May 2025 13:23:35 +0800 Subject: [PATCH] . --- llama_index/indices/loading.py | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/llama_index/indices/loading.py b/llama_index/indices/loading.py index 70e43d1..ed2a74c 100644 --- a/llama_index/indices/loading.py +++ b/llama_index/indices/loading.py @@ -6,15 +6,12 @@ from llama_index.indices.composability.graph import ComposableGraph from llama_index.indices.registry import INDEX_STRUCT_TYPE_TO_INDEX_CLASS from llama_index.storage.storage_context import StorageContext -from llama_index import ServiceContext - logger = logging.getLogger(__name__) def load_index_from_storage( storage_context: StorageContext, index_id: Optional[str] = None, - service_context: Optional[ServiceContext] = None, # 添加service_context参数 **kwargs: Any, ) -> BaseIndex: """Load index from storage context. @@ -27,6 +24,11 @@ def load_index_from_storage( in the index store and load it. **kwargs: Additional keyword args to pass to the index constructors. """ + + # 使用 kwargs 获取 service_context + service_context = kwargs.get('service_context', None) + + index_ids: Optional[Sequence[str]] if index_id is None: index_ids = None @@ -51,7 +53,6 @@ def load_index_from_storage( def load_indices_from_storage( storage_context: StorageContext, index_ids: Optional[Sequence[str]] = None, - service_context: Optional[ServiceContext] = None, # 添加service_context参数 **kwargs: Any, ) -> List[BaseIndex]: """Load multiple indices from storage context. @@ -63,6 +64,11 @@ def load_indices_from_storage( Defaults to None, which loads all indices in the index store. **kwargs: Additional keyword args to pass to the index constructors. """ + + # 使用 kwargs 获取 service_context + service_context = kwargs.get('service_context', None) + + if index_ids is None: logger.info("Loading all indices.") index_structs = storage_context.index_store.index_structs() @@ -79,7 +85,7 @@ def load_indices_from_storage( for index_struct in index_structs: type_ = index_struct.get_type() index_cls = INDEX_STRUCT_TYPE_TO_INDEX_CLASS[type_] - + # index = index_cls( # index_struct=index_struct, storage_context=storage_context, **kwargs # )