This commit is contained in:
hailin 2025-05-11 13:23:35 +08:00
parent 8bb61a3297
commit 64e4ca5c15
1 changed files with 11 additions and 5 deletions

View File

@ -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
# )