This commit is contained in:
parent
c377ffd741
commit
c6bb1a381a
|
|
@ -105,6 +105,26 @@ def build_user_index(user_id: str):
|
|||
storage_context.persist(persist_dir=persist_dir)
|
||||
logger.info(f"索引数据已保存到 {persist_dir}")
|
||||
|
||||
|
||||
|
||||
# 持久化存储之后,加载已保存的存储上下文信息
|
||||
logger.info(f"开始加载持久化存储的数据...")
|
||||
|
||||
# 创建一个新的 StorageContext 实例,使用相同的目录
|
||||
loaded_storage_context = StorageContext.from_defaults(
|
||||
persist_dir=persist_dir, # 使用与之前相同的目录
|
||||
vector_store=FaissVectorStore(faiss_index=faiss_index) # 使用之前保存的 FAISS 索引
|
||||
)
|
||||
|
||||
# 确认存储是否加载成功,检查索引数据
|
||||
logger.info("已成功加载存储上下文。")
|
||||
|
||||
# 加载索引,进行检查
|
||||
loaded_index = VectorStoreIndex.from_storage_context(loaded_storage_context)
|
||||
logger.info(f"加载的索引数量: {len(loaded_index.get_documents())}")
|
||||
|
||||
|
||||
|
||||
except Exception as e:
|
||||
logger.error(f"索引构建失败: {e}")
|
||||
raise HTTPException(status_code=500, detail="索引构建失败")
|
||||
|
|
|
|||
Loading…
Reference in New Issue