windlass.providers.embeddings.hf_inference¶
hf_inference
¶
HuggingFace Inference API embeddings.
The huggingface provider runs sentence-transformers locally — which means
torch, a model download, and a machine with the RAM to hold it. This one calls
the hosted inference endpoint instead: an API token, no local model, no cold
start on your own hardware.
It needs no optional dependency at all. httpx is already part of the core
install, so this works on a bare pip install windlass::
embedder = Windlass.embedding("hf_inference", model="BAAI/bge-base-en-v1.5")
BGE and E5 models expect an instruction prefix on queries but not on documents. Getting that asymmetry wrong is a silent quality bug — retrieval still "works", just worse — so the prefixes are declared through the interface's own hooks and applied by the base class on the right side of the split.
Example
from windlass import Windlass # doctest: +SKIP emb = Windlass.embedding("hf_inference") # doctest: +SKIP len(emb.embed_one("hello")) # doctest: +SKIP 768
HuggingFaceInferenceEmbedder
¶
HuggingFaceInferenceEmbedder(
model: str = "",
*,
api_key: str | None = None,
timeout: float = 60.0,
base_url: str = _ROUTER,
dimensions: int | None = None,
**config: Any
)
Bases: Embedder
Embeddings from the hosted HuggingFace Inference API.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
str
|
Repository id, e.g. |
''
|
api_key
|
str | None
|
Token. Falls back to |
None
|
timeout
|
float
|
Per-request timeout. Hosted models cold-start, so this is generous by default. |
60.0
|
base_url
|
str
|
Inference router base URL. Override for a dedicated endpoint. |
_ROUTER
|
dimensions
|
int | None
|
Output width. Inferred for known models, which lets a vector store be provisioned before the first call. |
None
|
**config
|
Any
|
Forwarded to :class: |
{}
|
Raises:
| Type | Description |
|---|---|
AuthenticationError
|
When no token is configured. |
Example
from windlass import Windlass # doctest: +SKIP emb = Windlass.embedding("hf_inference") # doctest: +SKIP emb.dimension() # doctest: +SKIP 768
Source code in src\windlass\providers\embeddings\hf_inference.py
default_model
classmethod
¶
native
¶
aembed_texts
async
¶
Embed one batch through the feature-extraction pipeline.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
texts
|
list[str]
|
Texts to embed, already carrying any instruction prefix. |
required |
kind
|
str
|
|
'document'
|
Returns:
| Type | Description |
|---|---|
list[list[float]]
|
One vector per input, in input order. |
Raises:
| Type | Description |
|---|---|
AuthenticationError
|
On 401 or 403. |
RateLimitError
|
On 429. |
ProviderTimeoutError
|
On a timeout or a cold-starting model (503). |
ProviderError
|
For any other failure, including a response whose shape does not match the request. |