Unverified 提交 2311fb00 作者: bright.python 提交者: GitHub

Update MyFAISS.py (#648)

防止i不存在时候错误,
langchain-ChatGLM/vectorstores/MyFAISS.py", line 55, in similarity_search_with_score_by_vector
    _id = self.index_to_docstore_id[i]
KeyError: 4
上级 3d95706d
...@@ -52,7 +52,11 @@ class MyFAISS(FAISS, VectorStore): ...@@ -52,7 +52,11 @@ class MyFAISS(FAISS, VectorStore):
if i == -1 or 0 < self.score_threshold < scores[0][j]: if i == -1 or 0 < self.score_threshold < scores[0][j]:
# This happens when not enough docs are returned. # This happens when not enough docs are returned.
continue continue
if i in self.index_to_docstore_id:
_id = self.index_to_docstore_id[i] _id = self.index_to_docstore_id[i]
# 执行接下来的操作
else:
continue
doc = self.docstore.search(_id) doc = self.docstore.search(_id)
if (not self.chunk_conent) or ("context_expand" in doc.metadata and not doc.metadata["context_expand"]): if (not self.chunk_conent) or ("context_expand" in doc.metadata and not doc.metadata["context_expand"]):
# 匹配出的文本如果不需要扩展上下文则执行如下代码 # 匹配出的文本如果不需要扩展上下文则执行如下代码
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论