This commit is contained in:
parent
64d81efa69
commit
b38d0db43c
|
|
@ -147,6 +147,18 @@ def build_user_index(user_id: str):
|
|||
faiss.write_index(faiss_index, faiss_index_file) # 使用 Faiss 的 write_index 方法保存索引
|
||||
logger.info(f"Faiss 索引已保存到 {faiss_index_file}")
|
||||
|
||||
|
||||
# 同步保存文本和向量
|
||||
# 将文本和对应的向量一起存储,确保 Faiss 向量存储和文本数据关联
|
||||
for i, document in enumerate(documents): # 修改日期:2025-05-10
|
||||
# 获取文本并生成向量
|
||||
text = document.text
|
||||
embedding = embed_model._get_query_embedding(text)
|
||||
|
||||
# 将文本和向量添加到 Faiss 向量存储
|
||||
vector_store.add([(embedding, text)]) # 保存向量和文本
|
||||
|
||||
|
||||
# 使用 storage_context.persist() 保存其他索引数据
|
||||
storage_context.persist(persist_dir=persist_dir)
|
||||
logger.info(f"索引数据已保存到 {persist_dir}")
|
||||
|
|
|
|||
Loading…
Reference in New Issue