Spaces:
Sleeping
Sleeping
fixing potential error
Browse files
rag_app/vector_store_handler/vectorstores.py
CHANGED
@@ -79,7 +79,7 @@ class BaseVectorStore(ABC):
|
|
79 |
Raises:
|
80 |
ValueError: If the vector store is not initialized.
|
81 |
"""
|
82 |
-
if
|
83 |
raise ValueError("Vector store not initialized. Call create_vectorstore or load_existing_vectorstore first.")
|
84 |
return self.vectorstore.similarity_search(query)
|
85 |
|
@@ -115,7 +115,7 @@ class ChromaVectorStore(BaseVectorStore):
|
|
115 |
Raises:
|
116 |
ValueError: If persist_directory is not set.
|
117 |
"""
|
118 |
-
if self.persist_directory:
|
119 |
self.vectorstore = Chroma(
|
120 |
persist_directory=self.persist_directory,
|
121 |
embedding_function=self.embeddings
|
@@ -156,7 +156,7 @@ class FAISSVectorStore(BaseVectorStore):
|
|
156 |
ValueError: If persist_directory is not set.
|
157 |
"""
|
158 |
if self.persist_directory:
|
159 |
-
self.vectorstore = FAISS.load_local(self.persist_directory, self.embeddings)
|
160 |
else:
|
161 |
raise ValueError("Persist directory is required for loading FAISS.")
|
162 |
|
@@ -167,7 +167,7 @@ class FAISSVectorStore(BaseVectorStore):
|
|
167 |
Raises:
|
168 |
ValueError: If the vector store is not initialized.
|
169 |
"""
|
170 |
-
if
|
171 |
raise ValueError("Vector store not initialized. Nothing to save.")
|
172 |
self.vectorstore.save_local(self.persist_directory)
|
173 |
|
|
|
79 |
Raises:
|
80 |
ValueError: If the vector store is not initialized.
|
81 |
"""
|
82 |
+
if self.vectorstore is None:
|
83 |
raise ValueError("Vector store not initialized. Call create_vectorstore or load_existing_vectorstore first.")
|
84 |
return self.vectorstore.similarity_search(query)
|
85 |
|
|
|
115 |
Raises:
|
116 |
ValueError: If persist_directory is not set.
|
117 |
"""
|
118 |
+
if self.persist_directory is not None:
|
119 |
self.vectorstore = Chroma(
|
120 |
persist_directory=self.persist_directory,
|
121 |
embedding_function=self.embeddings
|
|
|
156 |
ValueError: If persist_directory is not set.
|
157 |
"""
|
158 |
if self.persist_directory:
|
159 |
+
self.vectorstore = FAISS.load_local(self.persist_directory, self.embeddings, allow_dangerous_deserialization=True)
|
160 |
else:
|
161 |
raise ValueError("Persist directory is required for loading FAISS.")
|
162 |
|
|
|
167 |
Raises:
|
168 |
ValueError: If the vector store is not initialized.
|
169 |
"""
|
170 |
+
if self.vectorstore is not None:
|
171 |
raise ValueError("Vector store not initialized. Nothing to save.")
|
172 |
self.vectorstore.save_local(self.persist_directory)
|
173 |
|