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.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.
|
||||||
|
|
@ -30,7 +33,7 @@ def load_index_from_storage(
|
||||||
else:
|
else:
|
||||||
index_ids = [index_id]
|
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:
|
if len(indices) == 0:
|
||||||
raise ValueError(
|
raise ValueError(
|
||||||
|
|
@ -48,6 +51,7 @@ 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.
|
||||||
|
|
@ -75,9 +79,18 @@ 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_struct=index_struct, storage_context=storage_context, **kwargs
|
||||||
|
# )
|
||||||
|
|
||||||
|
# 显式传递service_context,确保禁用OpenAI
|
||||||
index = index_cls(
|
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)
|
indices.append(index)
|
||||||
return indices
|
return indices
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue