This commit is contained in:
hailin 2025-05-10 02:12:39 +08:00
parent cf19e61cb6
commit 33f266e552
1 changed files with 2 additions and 5 deletions

View File

@ -89,21 +89,18 @@ 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}")