mirror of
https://github.com/arc53/DocsGPT.git
synced 2025-11-29 00:23:17 +00:00
raise more legible error if the embedding vector dims don't match
This commit is contained in:
@@ -2,6 +2,7 @@ from application.vectorstore.base import BaseVectorStore
|
||||
from langchain.vectorstores import FAISS
|
||||
from application.core.settings import settings
|
||||
|
||||
HUGGINGFACE_MODEL_NAME = "huggingface_sentence-transformers/all-mpnet-base-v2"
|
||||
class FaissStore(BaseVectorStore):
|
||||
|
||||
def __init__(self, path, embeddings_key, docs_init=None):
|
||||
@@ -12,9 +13,19 @@ class FaissStore(BaseVectorStore):
|
||||
docs_init, self._get_embeddings(settings.EMBEDDINGS_NAME, embeddings_key)
|
||||
)
|
||||
else:
|
||||
embeddings = self._get_embeddings(settings.EMBEDDINGS_NAME, embeddings_key)
|
||||
self.docsearch = FAISS.load_local(
|
||||
self.path, self._get_embeddings(settings.EMBEDDINGS_NAME, settings.EMBEDDINGS_KEY)
|
||||
self.path, embeddings
|
||||
)
|
||||
|
||||
# Check that the word_embedding_dimension of the index matches the word_embedding_dimension of the embeddings
|
||||
if settings.EMBEDDINGS_NAME == HUGGINGFACE_MODEL_NAME:
|
||||
try:
|
||||
word_embedding_dimension = embeddings.client[1].word_embedding_dimension
|
||||
except AttributeError as e:
|
||||
raise AttributeError("word_embedding_dimension not found in embeddings.client[1]") from e
|
||||
if word_embedding_dimension != self.docsearch.index.d:
|
||||
raise ValueError("word_embedding_dimension != docsearch_index_word_embedding_dimension")
|
||||
|
||||
def search(self, *args, **kwargs):
|
||||
return self.docsearch.similarity_search(*args, **kwargs)
|
||||
|
||||
Reference in New Issue
Block a user