Skip to main content
Embedding layer: helpers, test doubles and adapters for core.pipeline.Embedder.

embedding.base

Helpers for anything that implements core.pipeline.Embedder.

EmbeddingError

The call failed (model error, timeout, bad answer) after the adapter’s own retries.

check_vectors

Verify a batch against the Protocol’s contract and return it as lists.

cosine

Cosine similarity for any two vectors.

dot

norm

normalize

Scale to unit length.

embedding.fake

Embedders for tests and for running with no model.

HashEmbedder

Signed feature hashing of words and character trigrams, L2 normalized. Construct with HashEmbedder(dimensions: int = 256, *, trigram_weight: float = 0.5).

TableEmbedder

Returns the vector you registered for each text. Construct with TableEmbedder(vectors: dict[str, Sequence[float]], model: str = 'fake/table').

embedding.litert

An embedder that runs a LiteRT-LM embedding model on this machine (EmbeddingGemma 270M .litertlm).

LiteRtEmbedder

Embedder over a local LiteRT-LM embedding model. Construct with LiteRtEmbedder(model_path: str \| pathlib.Path, *, backend: str = 'cpu', dimensions: int \| None = None, cache_dir: str \| pathlib.Path \| None = None, batch_size: int = 16, query_prompt: str \| None = 'task: search result \| query: {text}', document_prompt: str \| None = 'title: none \| text: {text}', engine_factory: Callable[[], _Engine] \| None = None).

embedding.vertex

An embedder that calls Google’s embedding models on Vertex AI (or the Gemini API) through google.genai.

VertexEmbedder

Embedder over a Google embedding model. Construct with VertexEmbedder(config: VertexEmbeddingConfig, *, client=None, sleep: Callable[[float], None] = <built-in function sleep>).

VertexEmbeddingConfig