Unverified 提交 47922d2e 作者: Winter 提交者: GitHub

fix: 扩展文档的代码逻辑 (#227)

* fix: 扩展文档的代码逻辑

* Update local_doc_qa.py

---------

Co-authored-by: imClumsyPanda <littlepanda0716@gmail.com>
上级 07ff81a1
...@@ -68,6 +68,7 @@ def similarity_search_with_score_by_vector( ...@@ -68,6 +68,7 @@ def similarity_search_with_score_by_vector(
scores, indices = self.index.search(np.array([embedding], dtype=np.float32), k) scores, indices = self.index.search(np.array([embedding], dtype=np.float32), k)
docs = [] docs = []
id_set = set() id_set = set()
store_len = len(self.index_to_docstore_id)
for j, i in enumerate(indices[0]): for j, i in enumerate(indices[0]):
if i == -1: if i == -1:
# This happens when not enough docs are returned. # This happens when not enough docs are returned.
...@@ -76,7 +77,7 @@ def similarity_search_with_score_by_vector( ...@@ -76,7 +77,7 @@ def similarity_search_with_score_by_vector(
doc = self.docstore.search(_id) doc = self.docstore.search(_id)
id_set.add(i) id_set.add(i)
docs_len = len(doc.page_content) docs_len = len(doc.page_content)
for k in range(1, max(i, len(docs) - i)): for k in range(1, max(i, store_len-i)):
break_flag = False break_flag = False
for l in [i + k, i - k]: for l in [i + k, i - k]:
if 0 <= l < len(self.index_to_docstore_id): if 0 <= l < len(self.index_to_docstore_id):
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论