This commit is contained in:
parent
fe30d8427c
commit
cae4dd103e
|
|
@ -174,30 +174,35 @@ def build_user_index(user_id: str):
|
|||
|
||||
|
||||
|
||||
# # 持久化存储之后,加载已保存的存储上下文信息
|
||||
# logger.info(f"开始加载持久化存储的数据...")
|
||||
|
||||
# # 加载 Faiss 索引
|
||||
# faiss_index_file = os.path.join(persist_dir, "index.faiss")
|
||||
# faiss_index = faiss.read_index(faiss_index_file)
|
||||
|
||||
# # 创建 FaissVectorStore 实例
|
||||
# vector_store = FaissVectorStore(faiss_index=faiss_index)
|
||||
|
||||
# # 创建一个新的 StorageContext 实例,使用相同的目录
|
||||
# storage_context = StorageContext.from_defaults(
|
||||
# persist_dir=persist_dir, # 使用与之前相同的目录
|
||||
# vector_store=vector_store # 使用 Faiss 向量存储
|
||||
# )
|
||||
|
||||
# # 确认存储是否加载成功,检查索引数据
|
||||
# logger.info("已成功加载存储上下文。")
|
||||
# 持久化存储之后,加载已保存的存储上下文信息
|
||||
logger.info(f"开始加载持久化存储的数据...")
|
||||
|
||||
# # 使用 load_index_from_storage 加载索引
|
||||
# loaded_index = load_index_from_storage(storage_context)
|
||||
# 加载 Faiss 索引
|
||||
faiss_index_file = os.path.join(persist_dir, "index.faiss")
|
||||
faiss_index = faiss.read_index(faiss_index_file)
|
||||
|
||||
# # 检查加载后的索引
|
||||
# logger.info(f"加载的索引数量: {len(loaded_index.get_documents())}")
|
||||
# 创建 FaissVectorStore 实例
|
||||
vector_store = FaissVectorStore(faiss_index=faiss_index)
|
||||
|
||||
# 创建一个新的 StorageContext 实例,使用相同的目录
|
||||
storage_context = StorageContext.from_defaults(
|
||||
persist_dir=persist_dir, # 使用与之前相同的目录
|
||||
vector_store=vector_store, # 使用 Faiss 向量存储
|
||||
llm=None # 明确指定不使用 LLM
|
||||
)
|
||||
|
||||
# 确认存储是否加载成功,检查索引数据
|
||||
logger.info("已成功加载存储上下文。")
|
||||
|
||||
# 使用 load_index_from_storage 加载索引
|
||||
loaded_index = load_index_from_storage(storage_context)
|
||||
|
||||
# 检查加载后的索引
|
||||
logger.info(f"加载的索引数量: {len(loaded_index.get_documents())}")
|
||||
|
||||
|
||||
except Exception as e:
|
||||
|
|
|
|||
Loading…
Reference in New Issue