This commit is contained in:
parent
bd7f88f131
commit
8bb61a3297
|
|
@ -6,12 +6,15 @@ 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.
|
||||
|
|
@ -30,7 +33,7 @@ def load_index_from_storage(
|
|||
else:
|
||||
index_ids = [index_id]
|
||||
|
||||
indices = load_indices_from_storage(storage_context, index_ids=index_ids, **kwargs)
|
||||
indices = load_indices_from_storage(storage_context, index_ids=index_ids, service_context=service_context, **kwargs)
|
||||
|
||||
if len(indices) == 0:
|
||||
raise ValueError(
|
||||
|
|
@ -48,6 +51,7 @@ 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.
|
||||
|
|
@ -75,8 +79,17 @@ 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
|
||||
# )
|
||||
|
||||
# 显式传递service_context,确保禁用OpenAI
|
||||
index = index_cls(
|
||||
index_struct=index_struct, storage_context=storage_context, **kwargs
|
||||
index_struct=index_struct,
|
||||
storage_context=storage_context,
|
||||
service_context=service_context, # 确保每个索引使用正确的service_context
|
||||
**kwargs
|
||||
)
|
||||
indices.append(index)
|
||||
return indices
|
||||
|
|
|
|||
Loading…
Reference in New Issue