This commit is contained in:
parent
8bb61a3297
commit
64e4ca5c15
|
|
@ -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.indices.registry import INDEX_STRUCT_TYPE_TO_INDEX_CLASS
|
||||||
from llama_index.storage.storage_context import StorageContext
|
from llama_index.storage.storage_context import StorageContext
|
||||||
|
|
||||||
from llama_index import ServiceContext
|
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
def load_index_from_storage(
|
def load_index_from_storage(
|
||||||
storage_context: StorageContext,
|
storage_context: StorageContext,
|
||||||
index_id: Optional[str] = None,
|
index_id: Optional[str] = None,
|
||||||
service_context: Optional[ServiceContext] = None, # 添加service_context参数
|
|
||||||
**kwargs: Any,
|
**kwargs: Any,
|
||||||
) -> BaseIndex:
|
) -> BaseIndex:
|
||||||
"""Load index from storage context.
|
"""Load index from storage context.
|
||||||
|
|
@ -27,6 +24,11 @@ def load_index_from_storage(
|
||||||
in the index store and load it.
|
in the index store and load it.
|
||||||
**kwargs: Additional keyword args to pass to the index constructors.
|
**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]]
|
index_ids: Optional[Sequence[str]]
|
||||||
if index_id is None:
|
if index_id is None:
|
||||||
index_ids = None
|
index_ids = None
|
||||||
|
|
@ -51,7 +53,6 @@ def load_index_from_storage(
|
||||||
def load_indices_from_storage(
|
def load_indices_from_storage(
|
||||||
storage_context: StorageContext,
|
storage_context: StorageContext,
|
||||||
index_ids: Optional[Sequence[str]] = None,
|
index_ids: Optional[Sequence[str]] = None,
|
||||||
service_context: Optional[ServiceContext] = None, # 添加service_context参数
|
|
||||||
**kwargs: Any,
|
**kwargs: Any,
|
||||||
) -> List[BaseIndex]:
|
) -> List[BaseIndex]:
|
||||||
"""Load multiple indices from storage context.
|
"""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.
|
Defaults to None, which loads all indices in the index store.
|
||||||
**kwargs: Additional keyword args to pass to the index constructors.
|
**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:
|
if index_ids is None:
|
||||||
logger.info("Loading all indices.")
|
logger.info("Loading all indices.")
|
||||||
index_structs = storage_context.index_store.index_structs()
|
index_structs = storage_context.index_store.index_structs()
|
||||||
|
|
@ -79,7 +85,7 @@ def load_indices_from_storage(
|
||||||
for index_struct in index_structs:
|
for index_struct in index_structs:
|
||||||
type_ = index_struct.get_type()
|
type_ = index_struct.get_type()
|
||||||
index_cls = INDEX_STRUCT_TYPE_TO_INDEX_CLASS[type_]
|
index_cls = INDEX_STRUCT_TYPE_TO_INDEX_CLASS[type_]
|
||||||
|
|
||||||
# index = index_cls(
|
# index = index_cls(
|
||||||
# index_struct=index_struct, storage_context=storage_context, **kwargs
|
# index_struct=index_struct, storage_context=storage_context, **kwargs
|
||||||
# )
|
# )
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue