From fd4c0604e137e14cacdee57c47b52938f53c59b4 Mon Sep 17 00:00:00 2001 From: hailin Date: Sun, 11 May 2025 00:01:24 +0800 Subject: [PATCH] . --- scripts/rag_build_query.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/scripts/rag_build_query.py b/scripts/rag_build_query.py index 296e551..a329741 100644 --- a/scripts/rag_build_query.py +++ b/scripts/rag_build_query.py @@ -148,15 +148,16 @@ def build_user_index(user_id: str): logger.info(f"Faiss 索引已保存到 {faiss_index_file}") - # 同步保存文本和向量 - # 将文本和对应的向量一起存储,确保 Faiss 向量存储和文本数据关联 - for i, document in enumerate(documents): # 修改日期:2025-05-10 - # 获取文本并生成向量 + # 将文本和向量存储为 Node 对象 + for i, document in enumerate(documents): text = document.text embedding = embed_model._get_query_embedding(text) - # 将文本和向量添加到 Faiss 向量存储 - vector_store.add([(embedding, text)]) # 保存向量和文本 + # 创建一个 Node 对象,它包含文本和嵌入 + node = Node(text=text, embedding=embedding) + + # 将 Node 对象添加到 FaissVectorStore 中 + vector_store.add([node]) # 确保添加的是 Node 对象,而不是元组 # 使用 storage_context.persist() 保存其他索引数据