This commit is contained in:
parent
96d3bffb4b
commit
cf19e61cb6
|
|
@ -89,21 +89,25 @@ def build_user_index(user_id: str):
|
|||
)
|
||||
|
||||
try:
|
||||
# 构建索引,并使用 `storage_context.persist()` 方法保存索引
|
||||
# 构建索引,并使用 `storage_context.persist()` 方法保存索引
|
||||
index = VectorStoreIndex.from_documents(
|
||||
documents,
|
||||
service_context=service_context,
|
||||
storage_context=storage_context
|
||||
)
|
||||
|
||||
# 获取 FAISS 索引对象
|
||||
faiss_index = index.vector_store.get_index() # 从 index 中获取 FAISS 索引
|
||||
|
||||
# 保存 Faiss 索引为文件,使用正确的路径
|
||||
faiss_index_file = os.path.join(persist_dir, "index.faiss")
|
||||
faiss.write_index(faiss_index, faiss_index_file) # 使用 Faiss 的 write_index 方法保存索引
|
||||
logger.info(f"Faiss 索引已保存到 {faiss_index_file}")
|
||||
|
||||
|
||||
# 使用 storage_context.persist() 保存其他索引数据
|
||||
storage_context.persist(persist_dir=persist_dir)
|
||||
logger.info(f"索引数据已保存到 {persist_dir}")
|
||||
|
||||
except Exception as e:
|
||||
logger.error(f"索引构建失败: {e}")
|
||||
raise HTTPException(status_code=500, detail="索引构建失败")
|
||||
|
|
|
|||
Loading…
Reference in New Issue