This commit is contained in:
hailin 2025-05-11 00:01:24 +08:00
parent b38d0db43c
commit fd4c0604e1
1 changed files with 7 additions and 6 deletions

View File

@ -148,15 +148,16 @@ def build_user_index(user_id: str):
logger.info(f"Faiss 索引已保存到 {faiss_index_file}") logger.info(f"Faiss 索引已保存到 {faiss_index_file}")
# 同步保存文本和向量 # 将文本和向量存储为 Node 对象
# 将文本和对应的向量一起存储,确保 Faiss 向量存储和文本数据关联 for i, document in enumerate(documents):
for i, document in enumerate(documents): # 修改日期2025-05-10
# 获取文本并生成向量
text = document.text text = document.text
embedding = embed_model._get_query_embedding(text) embedding = embed_model._get_query_embedding(text)
# 将文本和向量添加到 Faiss 向量存储 # 创建一个 Node 对象,它包含文本和嵌入
vector_store.add([(embedding, text)]) # 保存向量和文本 node = Node(text=text, embedding=embedding)
# 将 Node 对象添加到 FaissVectorStore 中
vector_store.add([node]) # 确保添加的是 Node 对象,而不是元组
# 使用 storage_context.persist() 保存其他索引数据 # 使用 storage_context.persist() 保存其他索引数据