Spaces:
Running
Running
Update src/rag_engine.py
Browse filesmodified the PInecone upload functionality to let the system check embedded vector dimensionality automatically
- src/rag_engine.py +10 -3
src/rag_engine.py
CHANGED
|
@@ -196,10 +196,17 @@ def ingest_file(file_path: str, username: str, index_name: str, strategy: str =
|
|
| 196 |
for doc in docs:
|
| 197 |
acronym_mgr.scan_text_for_acronyms(doc.page_content)
|
| 198 |
|
| 199 |
-
# 3. Pinecone Safety Check
|
| 200 |
pm = PineconeManager(PINECONE_KEY)
|
| 201 |
-
|
| 202 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 203 |
|
| 204 |
# 4. Upload
|
| 205 |
emb_fn = get_embedding_func()
|
|
|
|
| 196 |
for doc in docs:
|
| 197 |
acronym_mgr.scan_text_for_acronyms(doc.page_content)
|
| 198 |
|
| 199 |
+
# 3. Pinecone Safety Check (Dynamic)
|
| 200 |
pm = PineconeManager(PINECONE_KEY)
|
| 201 |
+
emb_fn = get_embedding_func()
|
| 202 |
+
|
| 203 |
+
# DYNAMIC CHECK: Generate a test embedding to see true dimension
|
| 204 |
+
# This allows you to swap models in CONFIGURATION later without breaking code
|
| 205 |
+
test_vec = emb_fn.embed_query("this is a test")
|
| 206 |
+
model_dim = len(test_vec)
|
| 207 |
+
|
| 208 |
+
if not pm.check_dimension_compatibility(index_name, model_dim):
|
| 209 |
+
return False, f"Dimension Mismatch! Index '{index_name}' expects {model_dim}d vectors (based on current model), but found incompatible dimensions."
|
| 210 |
|
| 211 |
# 4. Upload
|
| 212 |
emb_fn = get_embedding_func()
|