> ## 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

> Biến văn bản thành vector.

Tầng embedding: các hàm trợ giúp, bản giả cho kiểm thử và các bộ điều hợp cho `core.pipeline.Embedder`.

## `embedding.base`

Các hàm trợ giúp cho bất cứ thứ gì triển khai `core.pipeline.Embedder`.

#### `EmbeddingError`

Lần gọi thất bại (lỗi mô hình, hết thời gian chờ, câu trả lời sai) sau các lần thử lại của chính bộ điều hợp.

#### `check_vectors`

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

Kiểm tra một lô theo hợp đồng của Protocol và trả về nó dưới dạng danh sách.

#### `cosine`

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

Độ tương đồng cosine cho hai vector bất kỳ.

#### `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]
```

Co giãn về độ dài đơn vị.

## `embedding.fake`

Các bộ nhúng cho kiểm thử và cho việc chạy mà không cần mô hình.

#### `HashEmbedder`

Băm đặc trưng có dấu của các từ và các trigram ký tự, chuẩn hóa L2.

Khởi tạo bằng `HashEmbedder(dimensions: int = 256, *, trigram_weight: float = 0.5)`.

| Phương thức | Làm gì |
| - | - |
| `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`

Trả về vector mà bạn đã đăng ký cho mỗi văn bản.

Khởi tạo bằng `TableEmbedder(vectors: dict[str, Sequence[float]], model: str = 'fake/table')`.

| Phương thức | Làm gì |
| - | - |
| `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`

Một bộ nhúng chạy một mô hình embedding LiteRT-LM trên máy này (EmbeddingGemma 270M `.litertlm`).

#### `LiteRtEmbedder`

`Embedder` trên một mô hình embedding LiteRT-LM cục bộ.

Khởi tạo bằng `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)`.

| Phương thức | Làm gì |
| - | - |
| `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`

Một bộ nhúng gọi các mô hình embedding của Google trên Vertex AI (hoặc Gemini API) qua `google.genai`.

#### `VertexEmbedder`

`Embedder` trên một mô hình embedding của Google.

Khởi tạo bằng `VertexEmbedder(config: VertexEmbeddingConfig, *, client=None, sleep: Callable[[float], None] = <built-in function sleep>)`.

| Phương thức | Làm gì |
| - | - |
| `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`

| Trường | Kiểu | Mặc định |
| - | - | - |
| `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` |

| Phương thức | Làm gì |
| - | - |
| `(property)` | — |


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