popoto.embeddings.sentence_transformers¶
popoto.embeddings.sentence_transformers
¶
Sentence-Transformers embedding provider.
Wraps a local sentence-transformers model (all-MiniLM-L6-v2 by
default) behind the AbstractEmbeddingProvider interface. Inference runs
entirely on the local machine, so there is no API key, no per-token cost,
and no network dependency on a paid external provider.
The first use downloads the model weights (~90MB for all-MiniLM-L6-v2)
from Hugging Face and caches them locally; subsequent uses are offline.
sentence-transformers is a heavy optional dependency (it pulls in
PyTorch). It is therefore imported lazily inside embed() so that
import popoto.embeddings stays cheap and does not require the package to
be installed. The dependency ships under the [benchmark] optional extra::
pip install popoto[benchmark]
Example
from popoto.embeddings.sentence_transformers import ( SentenceTransformersProvider, ) provider = SentenceTransformersProvider() vectors = provider.embed(["hello world"])
SentenceTransformersProvider
¶
Bases: AbstractEmbeddingProvider
Local Sentence-Transformers embedding provider.
Wraps a sentence-transformers model and produces dense vectors with
no API key. The default model, all-MiniLM-L6-v2, emits 384-dim
vectors and is symmetric (the same encoder is used for documents and
queries), so input_type is accepted for interface compatibility but
ignored.
The underlying model is loaded lazily on the first embed() call and
cached on the instance; constructing the provider does nothing heavy and
triggers no download.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_name
|
str
|
Name of the sentence-transformers model to load.
Default |
'all-MiniLM-L6-v2'
|
dimensions
|
int
|
Output vector dimensionality. Defaults to 384 for the MiniLM model; override only if you pass a different model. |
_MINILM_DIMENSIONS
|
Raises:
| Type | Description |
|---|---|
ImportError
|
At |
Source code in src/popoto/embeddings/sentence_transformers.py
dimensions
property
¶
Embedding vector dimensionality (384 for all-MiniLM-L6-v2).
max_batch_size
property
¶
Conservative batch limit for local CPU inference.
Embedding many texts in a single forward pass can be memory-heavy on modest hardware. Users with more headroom can subclass and override.
embed(texts, input_type=None)
¶
Generate embeddings with a local sentence-transformers model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
texts
|
List[str]
|
List of text strings to embed. |
required |
input_type
|
Optional[str]
|
Accepted for interface compatibility but ignored —
|
None
|
Returns:
| Type | Description |
|---|---|
List[List[float]]
|
List of embedding vectors, one per input text. An empty input |
List[List[float]]
|
list returns |
Raises:
| Type | Description |
|---|---|
ImportError
|
If |