Merge pull request #657 from imClumsyPanda/revert-653-dev-1
Revert 653 dev 1
This commit is contained in:
commit
3f7e81585e
|
|
@ -229,7 +229,7 @@ Web UI 可以实现如下功能:
|
||||||
- [x] VUE 前端
|
- [x] VUE 前端
|
||||||
|
|
||||||
## 项目交流群
|
## 项目交流群
|
||||||
<img src="img/qr_code_32.jpg" alt="二维码" width="300" height="300" />
|
<img src="img/qr_code_33.jpg" alt="二维码" width="300" height="300" />
|
||||||
|
|
||||||
|
|
||||||
🎉 langchain-ChatGLM 项目微信交流群,如果你也对本项目感兴趣,欢迎加入群聊参与讨论交流。
|
🎉 langchain-ChatGLM 项目微信交流群,如果你也对本项目感兴趣,欢迎加入群聊参与讨论交流。
|
||||||
|
|
|
||||||
Binary file not shown.
|
After Width: | Height: | Size: 154 KiB |
|
|
@ -6,6 +6,7 @@ from langchain.docstore.base import Docstore
|
||||||
from langchain.docstore.document import Document
|
from langchain.docstore.document import Document
|
||||||
import numpy as np
|
import numpy as np
|
||||||
import copy
|
import copy
|
||||||
|
import os
|
||||||
|
|
||||||
|
|
||||||
class MyFAISS(FAISS, VectorStore):
|
class MyFAISS(FAISS, VectorStore):
|
||||||
|
|
@ -53,10 +54,10 @@ class MyFAISS(FAISS, VectorStore):
|
||||||
# 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:
|
if i in self.index_to_docstore_id:
|
||||||
_id = self.index_to_docstore_id[i]
|
_id = self.index_to_docstore_id[i]
|
||||||
# 执行接下来的操作
|
# 执行接下来的操作
|
||||||
else:
|
else:
|
||||||
continue
|
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"]):
|
||||||
# 匹配出的文本如果不需要扩展上下文则执行如下代码
|
# 匹配出的文本如果不需要扩展上下文则执行如下代码
|
||||||
|
|
@ -117,8 +118,10 @@ class MyFAISS(FAISS, VectorStore):
|
||||||
try:
|
try:
|
||||||
if isinstance(source, str):
|
if isinstance(source, str):
|
||||||
ids = [k for k, v in self.docstore._dict.items() if v.metadata["source"] == source]
|
ids = [k for k, v in self.docstore._dict.items() if v.metadata["source"] == source]
|
||||||
|
vs_path = os.path.join(os.path.split(os.path.split(source)[0])[0], "vector_store")
|
||||||
else:
|
else:
|
||||||
ids = [k for k, v in self.docstore._dict.items() if v.metadata["source"] in source]
|
ids = [k for k, v in self.docstore._dict.items() if v.metadata["source"] in source]
|
||||||
|
vs_path = os.path.join(os.path.split(os.path.split(source[0])[0])[0], "vector_store")
|
||||||
if len(ids) == 0:
|
if len(ids) == 0:
|
||||||
return f"docs delete fail"
|
return f"docs delete fail"
|
||||||
else:
|
else:
|
||||||
|
|
@ -126,6 +129,9 @@ class MyFAISS(FAISS, VectorStore):
|
||||||
index = list(self.index_to_docstore_id.keys())[list(self.index_to_docstore_id.values()).index(id)]
|
index = list(self.index_to_docstore_id.keys())[list(self.index_to_docstore_id.values()).index(id)]
|
||||||
self.index_to_docstore_id.pop(index)
|
self.index_to_docstore_id.pop(index)
|
||||||
self.docstore._dict.pop(id)
|
self.docstore._dict.pop(id)
|
||||||
|
# TODO: 从 self.index 中删除对应id
|
||||||
|
# self.index.reset()
|
||||||
|
self.save_local(vs_path)
|
||||||
return f"docs delete success"
|
return f"docs delete success"
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(e)
|
print(e)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue