update class method of KnowledgeBase and KnowledgeFile

This commit is contained in:
imClumsyPanda 2023-08-05 13:48:30 +08:00
parent 206261cd0c
commit e8a88f174d
1 changed files with 1 additions and 18 deletions

View File

@ -30,20 +30,3 @@ class KnowledgeFile:
from langchain.text_splitter import CharacterTextSplitter from langchain.text_splitter import CharacterTextSplitter
text_splitter = CharacterTextSplitter(chunk_size=500, chunk_overlap=200) text_splitter = CharacterTextSplitter(chunk_size=500, chunk_overlap=200)
return loader.load_and_split(text_splitter) return loader.load_and_split(text_splitter)
def docs2vs(self):
vs_path = get_vs_path(self.kb.kb_name)
embeddings = load_embeddings(embedding_model_dict[EMBEDDING_MODEL], EMBEDDING_DEVICE)
if os.path.exists(vs_path) and "index.faiss" in os.listdir(vs_path):
vector_store = FAISS.load_local(vs_path, embeddings)
vector_store.add_documents(self.docs)
torch_gc()
else:
if not os.path.exists(vs_path):
os.makedirs(vs_path)
vector_store = FAISS.from_documents(self.docs, embeddings) # docs 为Document列表
torch_gc()
vector_store.save_local(vs_path)
refresh_vs_cache(self.kb.kb_name)
return True