# `vllm_mlx.utils.truncation`

Shared resolution of the tokenizer truncation length for embedding and reranker models.

[View the complete module source at #L1-L83](https://github.com/waybarrios/vllm-mlx/blob/a69d47912bcb21d8fe04d48f75fa896b620ffcfa/vllm_mlx/utils/truncation.py#L1-L83).

## API details

Each callable below includes its exact signature, type annotations, inputs, defaults, return contract, documented exceptions, implementation source, and parsed docstring sections when the source provides them.

::: vllm_mlx.utils.truncation
    options:
      members:
        - MAX_LENGTH_DEFAULT
        - TOKENIZER_SENTINEL_THRESHOLD
        - _config_get
        - inner_tokenizer
        - _positive_int
        - resolve_max_length
      filters: []
      show_if_no_docstring: true

## Complete contract reference

Expand any definition for its exact inputs, annotations, defaults, return contract, directly raised exceptions, source-grounded behavior, and immutable line link. This section includes private and nested definitions that ordinary API generators omit.

<details class="api-contract" id="contract-vllm_mlx.utils.truncation._config_get" markdown="1">
<summary><code>vllm_mlx.utils.truncation._config_get</code> · function</summary>

```python
vllm_mlx.utils.truncation._config_get(config: Any, key: str) -> Any
```

Read ``key`` from a model config that may be a dict or an object.

**Parameters**

| Name | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `config` | `Any` | `yes` | `none` | Required positional or keyword input. |
| `key` | `str` | `yes` | `none` | Required positional or keyword input. |

**Returns**

- Type: `Any`
- Direct return expressions: `None`; `config.get(key)`; `getattr(config, key, None)`

**Exceptions and behavior**

Function `_config_get` calls `isinstance`, `config.get`, `getattr`; has 3 explicit return paths.
No direct `raise` statement appears in this definition.

[View source #L25-L31](https://github.com/waybarrios/vllm-mlx/blob/a69d47912bcb21d8fe04d48f75fa896b620ffcfa/vllm_mlx/utils/truncation.py#L25-L31).

</details>

<details class="api-contract" id="contract-vllm_mlx.utils.truncation.inner_tokenizer" markdown="1">
<summary><code>vllm_mlx.utils.truncation.inner_tokenizer</code> · function</summary>

```python
vllm_mlx.utils.truncation.inner_tokenizer(tokenizer: Any) -> Any
```

Unwrap a wrapping tokenizer to its inner ``_tokenizer`` when present.

**Parameters**

| Name | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `tokenizer` | `Any` | `yes` | `none` | Required positional or keyword input. |

**Returns**

- Type: `Any`
- Direct return expressions: `getattr(tokenizer, '_tokenizer', tokenizer)`

**Exceptions and behavior**

Function `inner_tokenizer` calls `getattr`; returns `getattr(tokenizer, '_tokenizer', tokenizer)`.
No direct `raise` statement appears in this definition.

[View source #L34-L36](https://github.com/waybarrios/vllm-mlx/blob/a69d47912bcb21d8fe04d48f75fa896b620ffcfa/vllm_mlx/utils/truncation.py#L34-L36).

</details>

<details class="api-contract" id="contract-vllm_mlx.utils.truncation._positive_int" markdown="1">
<summary><code>vllm_mlx.utils.truncation._positive_int</code> · function</summary>

```python
vllm_mlx.utils.truncation._positive_int(value: Any) -> int | None
```

Function `_positive_int` calls `isinstance`; has 2 explicit return paths.

**Parameters**

| Name | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `value` | `Any` | `yes` | `none` | Required positional or keyword input. |

**Returns**

- Type: `int | None`
- Direct return expressions: `value`; `None`

**Exceptions and behavior**

Function `_positive_int` calls `isinstance`; has 2 explicit return paths.
No direct `raise` statement appears in this definition.

[View source #L39-L42](https://github.com/waybarrios/vllm-mlx/blob/a69d47912bcb21d8fe04d48f75fa896b620ffcfa/vllm_mlx/utils/truncation.py#L39-L42).

</details>

<details class="api-contract" id="contract-vllm_mlx.utils.truncation.resolve_max_length" markdown="1">
<summary><code>vllm_mlx.utils.truncation.resolve_max_length</code> · function</summary>

```python
vllm_mlx.utils.truncation.resolve_max_length(config: Any, tokenizer: Any, *, default: int = MAX_LENGTH_DEFAULT, sentinel_threshold: int = TOKENIZER_SENTINEL_THRESHOLD) -> int
```

Resolve the tokenizer truncation length for a model.

**Parameters**

| Name | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `config` | `Any` | `yes` | `none` | Model config as a dict (reranker) or object (embeddings). |
| `tokenizer` | `Any` | `yes` | `none` | The tokenizer (possibly wrapping an inner ``_tokenizer``). |
| `default` | `int` | `no` | `MAX_LENGTH_DEFAULT` | Fallback when no usable value is found. |
| `sentinel_threshold` | `int` | `no` | `TOKENIZER_SENTINEL_THRESHOLD` | Tokenizer-derived values at or above this are treated as an unset HuggingFace sentinel, not a real length. |

**Returns**

- Type: `int`
- Direct return expressions: `resolved`

**Exceptions and behavior**

Function `resolve_max_length` calls `_positive_int`, `_config_get`, `getattr`, `inner_tokenizer`; returns `resolved`.
No direct `raise` statement appears in this definition.

[View source #L45-L83](https://github.com/waybarrios/vllm-mlx/blob/a69d47912bcb21d8fe04d48f75fa896b620ffcfa/vllm_mlx/utils/truncation.py#L45-L83).

</details>

## Complete symbol map

This map also includes private definitions and nested helpers. The signature column exposes every explicit input even when an internal helper has no dedicated parameter prose.

| Symbol | Kind | Signature and inputs | What it does | Source |
| --- | --- | --- | --- | --- |
| [`_config_get`](#contract-vllm_mlx.utils.truncation._config_get) | function | `_config_get(config: Any, key: str) -> Any` | Read ``key`` from a model config that may be a dict or an object. | [#L25-L31](https://github.com/waybarrios/vllm-mlx/blob/a69d47912bcb21d8fe04d48f75fa896b620ffcfa/vllm_mlx/utils/truncation.py#L25-L31) |
| [`inner_tokenizer`](#contract-vllm_mlx.utils.truncation.inner_tokenizer) | function | `inner_tokenizer(tokenizer: Any) -> Any` | Unwrap a wrapping tokenizer to its inner ``_tokenizer`` when present. | [#L34-L36](https://github.com/waybarrios/vllm-mlx/blob/a69d47912bcb21d8fe04d48f75fa896b620ffcfa/vllm_mlx/utils/truncation.py#L34-L36) |
| [`_positive_int`](#contract-vllm_mlx.utils.truncation._positive_int) | function | `_positive_int(value: Any) -> int \| None` | Function `_positive_int` calls `isinstance`; has 2 explicit return paths. | [#L39-L42](https://github.com/waybarrios/vllm-mlx/blob/a69d47912bcb21d8fe04d48f75fa896b620ffcfa/vllm_mlx/utils/truncation.py#L39-L42) |
| [`resolve_max_length`](#contract-vllm_mlx.utils.truncation.resolve_max_length) | function | `resolve_max_length(config: Any, tokenizer: Any, *, default: int = MAX_LENGTH_DEFAULT, sentinel_threshold: int = TOKENIZER_SENTINEL_THRESHOLD) -> int` | Resolve the tokenizer truncation length for a model. | [#L45-L83](https://github.com/waybarrios/vllm-mlx/blob/a69d47912bcb21d8fe04d48f75fa896b620ffcfa/vllm_mlx/utils/truncation.py#L45-L83) |
