DocsGPT/application/vectorstore/faiss.py

27 lines
945 B
Python
Raw Normal View History

2023-09-27 15:25:57 +00:00
from application.vectorstore.base import BaseVectorStore
from langchain import FAISS
from application.core.settings import settings
class FaissStore(BaseVectorStore):
2023-09-29 16:17:48 +00:00
def __init__(self, path, embeddings_key, docs_init=None):
2023-09-27 15:25:57 +00:00
super().__init__()
self.path = path
2023-09-29 16:17:48 +00:00
if docs_init:
self.docsearch = FAISS.from_documents(
docs_init, self._get_embeddings(settings.EMBEDDINGS_NAME, embeddings_key)
)
else:
self.docsearch = FAISS.load_local(
self.path, self._get_embeddings(settings.EMBEDDINGS_NAME, settings.EMBEDDINGS_KEY)
)
2023-09-27 15:25:57 +00:00
def search(self, *args, **kwargs):
return self.docsearch.similarity_search(*args, **kwargs)
2023-09-28 23:32:19 +00:00
def add_texts(self, *args, **kwargs):
return self.docsearch.add_texts(*args, **kwargs)
2023-09-29 16:17:48 +00:00
def save_local(self, *args, **kwargs):
return self.docsearch.save_local(*args, **kwargs)