Spaces:
Sleeping
Sleeping
Aditya commited on
Commit ·
8223ae9
1
Parent(s): 594b780
Fix: Force embedding model update to paraphrase-MiniLM-L3-v2
Browse files- Prevent loading old model name from saved database
- Auto-regenerate embeddings when model mismatch detected
- Ensure new smaller model is used consistently
- This will reduce memory usage from ~80MB to ~17MB
- vector_db.py +13 -2
vector_db.py
CHANGED
|
@@ -186,9 +186,20 @@ class SimpleVectorDB:
|
|
| 186 |
|
| 187 |
self.documents = db_data['documents']
|
| 188 |
self.embeddings = db_data['embeddings']
|
| 189 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 190 |
|
| 191 |
-
logger.info(f"Loaded vector database with {len(self.documents)} documents")
|
| 192 |
return True
|
| 193 |
|
| 194 |
except FileNotFoundError:
|
|
|
|
| 186 |
|
| 187 |
self.documents = db_data['documents']
|
| 188 |
self.embeddings = db_data['embeddings']
|
| 189 |
+
# Keep the current model_name (don't overwrite with old saved model)
|
| 190 |
+
# This allows us to use a different model than what was saved
|
| 191 |
+
saved_model = db_data.get('model_name', 'unknown')
|
| 192 |
+
logger.info(f"Loaded vector database with {len(self.documents)} documents (original model: {saved_model}, using: {self.model_name})")
|
| 193 |
+
|
| 194 |
+
# If the saved model is different from current, regenerate embeddings
|
| 195 |
+
if saved_model != self.model_name:
|
| 196 |
+
logger.warning(f"Model mismatch: saved={saved_model}, current={self.model_name}. Regenerating embeddings with new model.")
|
| 197 |
+
# Force regeneration of embeddings with new model
|
| 198 |
+
self._load_embedding_model()
|
| 199 |
+
self.create_embeddings()
|
| 200 |
+
self.save_database() # Save with new model
|
| 201 |
+
logger.info(f"Embeddings regenerated and saved with new model: {self.model_name}")
|
| 202 |
|
|
|
|
| 203 |
return True
|
| 204 |
|
| 205 |
except FileNotFoundError:
|