Spaces:
Running
Running
Update app/core/embedding_engine.py
Browse files- app/core/embedding_engine.py +23 -2
app/core/embedding_engine.py
CHANGED
|
@@ -1,12 +1,33 @@
|
|
| 1 |
# embedding_engine.py
|
| 2 |
import uuid, time
|
|
|
|
| 3 |
from qdrant_client import QdrantClient, models
|
| 4 |
from qdrant_client.http.models import Distance, VectorParams
|
| 5 |
from sentence_transformers import SentenceTransformer
|
| 6 |
from app.core.config import QDRANT_URL, QDRANT_API_KEY
|
| 7 |
|
| 8 |
-
MODEL_PATH = "app/core/models/bge-base-en-v1.5"
|
| 9 |
-
embedder = SentenceTransformer(MODEL_PATH)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
|
| 11 |
qdrant = QdrantClient(
|
| 12 |
url=QDRANT_URL,
|
|
|
|
| 1 |
# embedding_engine.py
|
| 2 |
import uuid, time
|
| 3 |
+
from pathlib import Path
|
| 4 |
from qdrant_client import QdrantClient, models
|
| 5 |
from qdrant_client.http.models import Distance, VectorParams
|
| 6 |
from sentence_transformers import SentenceTransformer
|
| 7 |
from app.core.config import QDRANT_URL, QDRANT_API_KEY
|
| 8 |
|
| 9 |
+
# MODEL_PATH = "app/core/models/bge-base-en-v1.5"
|
| 10 |
+
# embedder = SentenceTransformer(MODEL_PATH)
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
# ✅ Resolve model path relative to THIS file, not the working directory
|
| 14 |
+
# Works on local, HuggingFace, Docker — anywhere
|
| 15 |
+
BASE_DIR = Path(__file__).resolve().parent # → app/core/
|
| 16 |
+
MODEL_PATH = BASE_DIR / "models" / "bge-base-en-v1.5"
|
| 17 |
+
|
| 18 |
+
print(f"📁 Model path: {MODEL_PATH}")
|
| 19 |
+
print(f"📁 Model exists: {MODEL_PATH.exists()}")
|
| 20 |
+
|
| 21 |
+
if not MODEL_PATH.exists():
|
| 22 |
+
raise RuntimeError(
|
| 23 |
+
f"BGE model not found at {MODEL_PATH}. "
|
| 24 |
+
f"Ensure the model folder is committed to the repo under app/core/models/bge-base-en-v1.5/"
|
| 25 |
+
)
|
| 26 |
+
|
| 27 |
+
embedder = SentenceTransformer(str(MODEL_PATH)) # SentenceTransformer needs str, not Path
|
| 28 |
+
print("✅ Embedder loaded successfully")
|
| 29 |
+
|
| 30 |
+
|
| 31 |
|
| 32 |
qdrant = QdrantClient(
|
| 33 |
url=QDRANT_URL,
|