Closed Harrold-Lee closed 8 months ago
这是langchain的函数 参考:https://github.com/langchain-ai/langchain/blob/master/libs/community/langchain_community/vectorstores/faiss.py
非常感谢您,我是小白,我想请教一下,在chatchat项目中,使用vs.similarity_search_with_score_by_vector来查询相关文档时,无需在项目中包含这个方法的定义吗?
这是langchain的函数 参考:https://github.com/langchain-ai/langchain/blob/master/libs/community/langchain_community/vectorstores/faiss.py
非常感谢您,我是小白,我想请教一下,在chatchat项目中,使用vs.similarity_search_with_score_by_vector来查询相关文档时,无需在项目中包含这个方法的定义吗?
前面的代码有应该已经调用了。你说的定义是?
我记得是L2
server/knowledge_base/kb_cache/faiss_cache.py
class KBFaissPool(_FaissPool): def load_vector_store( self, kb_name: str, vector_name: str = None, create: bool = True, embed_model: str = EMBEDDING_MODEL, embed_device: str = embedding_device(), ) -> ThreadSafeFaiss: self.atomic.acquire() vector_name = vector_name or embed_model cache = self.get((kb_name, vector_name)) # 用元组比拼接字符串好一些 if cache is None: item = ThreadSafeFaiss((kb_name, vector_name), pool=self) self.set((kb_name, vector_name), item) with item.acquire(msg="初始化"): self.atomic.release() logger.info(f"loading vector store in '{kb_name}/vector_store/{vector_name}' from disk.") vs_path = get_vs_path(kb_name, vector_name)
if os.path.isfile(os.path.join(vs_path, "index.faiss")):
embeddings = self.load_kb_embeddings(kb_name=kb_name, embed_device=embed_device, default_embed_model=embed_model)
vector_store = FAISS.load_local(vs_path, embeddings, normalize_L2=True,distance_strategy="METRIC_INNER_PRODUCT")
elif create:
# create an empty vector store
if not os.path.exists(vs_path):
os.makedirs(vs_path)
vector_store = self.new_vector_store(embed_model=embed_model, embed_device=embed_device)
vector_store.save_local(vs_path)
else:
raise RuntimeError(f"knowledge base {kb_name} not exist.")
item.obj = vector_store
item.finish_loading()
else:
self.atomic.release()
return self.get((kb_name, vector_name))
这是langchain的函数 参考:https://github.com/langchain-ai/langchain/blob/master/libs/community/langchain_community/vectorstores/faiss.py
非常感谢您,我是小白,我想请教一下,在chatchat项目中,使用vs.similarity_search_with_score_by_vector来查询相关文档时,无需在项目中包含这个方法的定义吗?
前面的代码有应该已经调用了。你说的定义是?
因为我在整个项目文件中未找到similarity_search_with_score_by_vector这个方法的代码,并且仅在我问题中给出的位置进行了一次调用,所以我比较疑惑为什么项目中没有这个方法的相关代码,但却可以调用这个方法来获得候选文档。
这是langchain的函数 参考:https://github.com/langchain-ai/langchain/blob/master/libs/community/langchain_community/vectorstores/faiss.py
非常感谢您,我是小白,我想请教一下,在chatchat项目中,使用vs.similarity_search_with_score_by_vector来查询相关文档时,无需在项目中包含这个方法的定义吗?
前面的代码有应该已经调用了。你说的定义是?
因为我在整个项目文件中未找到similarity_search_with_score_by_vector这个方法的代码,并且仅在我问题中给出的位置进行了一次调用,所以我比较疑惑为什么项目中没有这个方法的相关代码,但却可以调用这个方法来获得候选文档。
因为它调用的faiss是来自langchain的,
from langchain.vectorstores.faiss import FAISS
。这个库里面有定义这个方法,这里直接调用就好了
问题描述 / Problem Description 未找到faiss_kb_service.py中similarity_search_with_score_by_vector方法的代码
复现问题的步骤 / Steps to Reproduce
预期的结果 / Expected Result 能够打开similarity_search_with_score_by_vector方法的代码块
实际结果 / Actual Result 提示无相关代码
环境信息 / Environment Information
附加信息 / Additional Information 添加与问题相关的任何其他信息 / Add any other information related to the issue.