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