Download embeddings.py from codegood/job-chat: direct link, hf CLI and curl.
- Browser
- Download file 659 Bytes
-
https://huggingface.co/spaces/codegood/job-chat/resolve/main/embeddings.py
- Command line
-
hf download hf://spaces/codegood/job-chat/embeddings.py
-
curl -L -o embeddings.py https://huggingface.co/spaces/codegood/job-chat/resolve/main/embeddings.py
659 Bytes
| """Sentence embeddings via fastembed (ONNX runtime, no torch dependency). | |
| Vectors come back L2-normalised, so a dot product is cosine similarity. | |
| """ | |
| from functools import lru_cache | |
| import numpy as np | |
| from config import get_settings | |
| def _model(): | |
| from fastembed import TextEmbedding | |
| return TextEmbedding(get_settings(require_api_key=False).embedding_model) | |
| def embed(texts) -> np.ndarray: | |
| """Embed a sequence of strings into a (n, dim) float32 matrix.""" | |
| texts = list(texts) | |
| if not texts: | |
| return np.zeros((0, 0), dtype=np.float32) | |
| return np.asarray(list(_model().embed(texts)), dtype=np.float32) | |