windlass.providers.embeddings.huggingface¶
huggingface
¶
Hugging Face embedding models via sentence-transformers.
Runs entirely locally: no API key, no per-token cost, and your documents never leave the machine. The trade-off is a one-time model download and CPU/GPU time per batch.
Install with::
pip install "windlass[embeddings]"
Model choice matters more than anything else in a RAG stack. Sensible starting points:
BAAI/bge-small-en-v1.5— 384 dims, fast, strong for English (the default).BAAI/bge-m3— multilingual, 1024 dims, heavier.intfloat/multilingual-e5-large— multilingual, needs thequery:/passage:prefixes this adapter applies for you.
Example
from windlass import Windlass # doctest: +SKIP emb = Windlass.embedding("huggingface") # doctest: +SKIP len(emb.embed_one("hello")) # doctest: +SKIP 384
HuggingFaceEmbedder
¶
HuggingFaceEmbedder(
model: str = "",
*,
device: str | None = None,
trust_remote_code: bool = False,
auto_prefix: bool = True,
model_kwargs: dict[str, Any] | None = None,
encode_kwargs: dict[str, Any] | None = None,
**config: Any
)
Bases: Embedder
Local embeddings from a sentence-transformers model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
str
|
Model id on the Hugging Face Hub. |
''
|
device
|
str | None
|
|
None
|
trust_remote_code
|
bool
|
Allow the model repo to execute its own code. Only enable this for repos you trust. |
False
|
auto_prefix
|
bool
|
Apply the model family's query/document instruction prefixes automatically. Turn it off if you prefix text yourself. |
True
|
model_kwargs
|
dict[str, Any] | None
|
Extra keyword arguments for |
None
|
encode_kwargs
|
dict[str, Any] | None
|
Extra keyword arguments for |
None
|
**config
|
Any
|
Forwarded to :class: |
{}
|
Raises:
| Type | Description |
|---|---|
MissingDependencyError
|
When |
ProviderError
|
When the model cannot be loaded. |
Performance
The model is loaded once and reused. Encoding runs on a worker thread so
it never blocks the event loop, and batching is handled by the base
class — raise batch_size on a GPU, lower it if you hit memory limits.
Source code in src\windlass\providers\embeddings\huggingface.py
default_model
classmethod
¶
native
¶
dimension
¶
aembed_texts
async
¶
Encode a batch of texts on a worker thread.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
texts
|
list[str]
|
The texts to embed. Prefixes are already applied by the base class. |
required |
kind
|
str
|
|
'document'
|
Returns:
| Type | Description |
|---|---|
list[list[float]]
|
One vector per input. |
Raises:
| Type | Description |
|---|---|
ProviderError
|
When encoding fails. |