> ## Documentation Index
> Fetch the complete documentation index at: https://ladygraph.io.vn/llms.txt
> Use this file to discover all available pages before exploring further.

# embedding

> Turn text into vectors.

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`

```python theme={null}
check_vectors(vectors: Sequence[Sequence[float]], count: int, dimensions: int | None = None) -> list[list[float]]
```

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

#### `cosine`

```python theme={null}
cosine(a: Sequence[float], b: Sequence[float]) -> float
```

Cosine similarity for any two vectors.

#### `dot`

```python theme={null}
dot(a: Sequence[float], b: Sequence[float]) -> float
```

#### `norm`

```python theme={null}
norm(vector: Sequence[float]) -> float
```

#### `normalize`

```python theme={null}
normalize(vector: Sequence[float]) -> list[float]
```

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)`.

| Method | What it does |
| - | - |
| `embed(self, texts: Sequence[str], *, kind: Literal['document', 'query'] = 'document') -> list[list[float]]` | — |
| `aembed(self, texts: Sequence[str], *, kind: Literal['document', 'query'] = 'document') -> list[list[float]]` | — |

#### `TableEmbedder`

Returns the vector you registered for each text.

Construct with `TableEmbedder(vectors: dict[str, Sequence[float]], model: str = 'fake/table')`.

| Method | What it does |
| - | - |
| `embed(self, texts: Sequence[str], *, kind: Literal['document', 'query'] = 'document') -> list[list[float]]` | — |
| `aembed(self, texts: Sequence[str], *, kind: Literal['document', 'query'] = 'document') -> list[list[float]]` | — |

## `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)`.

| Method | What it does |
| - | - |
| `embed(self, texts: Sequence[str], *, kind: Literal['document', 'query'] = 'document') -> list[list[float]]` | — |
| `aembed(self, texts: Sequence[str], *, kind: Literal['document', 'query'] = 'document') -> list[list[float]]` | — |
| `close(self) -> 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>)`.

| Method | What it does |
| - | - |
| `embed(self, texts: Sequence[str], *, kind: Literal['document', 'query'] = 'document') -> list[list[float]]` | — |
| `aembed(self, texts: Sequence[str], *, kind: Literal['document', 'query'] = 'document') -> list[list[float]]` | — |
| `close(self) -> None` | — |

#### `VertexEmbeddingConfig`

| Field | Type | Default |
| - | - | - |
| `api_key_env` | `str \| None` | `None` |
| `auth` | `Literal['environment', 'api_key', 'service_account']` | `'environment'` |
| `service_account_file` | `str \| None` | `None` |
| `service_account_json_env` | `str \| None` | `None` |
| `project` | `str \| None` | `None` |
| `location` | `str \| None` | `None` |
| `model` | `str` | required |
| `dimensions` | `int \| None` | `None` |
| `batch_size` | `int \| None` | `None` |
| `query_task` | `str \| None` | `'RETRIEVAL_QUERY'` |
| `document_task` | `str \| None` | `'RETRIEVAL_DOCUMENT'` |
| `auto_truncate` | `bool` | `True` |
| `attempts` | `int` | `3` |
| `backoff_s` | `float` | `1.0` |
| `timeout_s` | `float` | `60.0` |

| Method | What it does |
| - | - |
| `(property)` | — |


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.