Spaces:
Runtime error
Runtime error
Download app/services/embeddings.py from RamshaAnwar/contextquery-api: direct link, hf CLI and curl.
- Browser
- Download file 688 Bytes
-
https://huggingface.co/spaces/RamshaAnwar/contextquery-api/resolve/main/app/services/embeddings.py
- Command line
-
hf download hf://spaces/RamshaAnwar/contextquery-api/app/services/embeddings.py
-
curl -L -o embeddings.py https://huggingface.co/spaces/RamshaAnwar/contextquery-api/resolve/main/app/services/embeddings.py
688 Bytes
| from fastembed import TextEmbedding | |
| from app.config import settings | |
| from app.services.groq_service import AiUnavailable | |
| # 768-dim model — matches the existing vector(768) column in Postgres. | |
| # ONNX-based, no Torch dependency. Loads in ~50-200 MB of memory. | |
| _model = TextEmbedding(model_name="BAAI/bge-base-en-v1.5") | |
| def embed_texts(texts: list[str], batch_size: int = 32) -> list[list[float]]: | |
| try: | |
| # FastEmbed returns a generator of numpy arrays. Convert to plain lists. | |
| vectors = list(_model.embed(texts, batch_size=batch_size)) | |
| return [v.tolist() for v in vectors] | |
| except Exception as exc: | |
| raise AiUnavailable("provider", str(exc)) from exc |