vllm_mlx.embedding¶
Embedding engine using mlx-embeddings.
View the complete module source at #L1-L131.
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.embedding
¶
Embedding engine using mlx-embeddings.
Provides lazy-loaded model management and batch embedding generation for the OpenAI-compatible /v1/embeddings endpoint.
vllm_mlx.embedding.EmbeddingEngine
¶
Wrapper around mlx-embeddings for text embedding generation.
Supports lazy model loading and batch embedding with proper tokenization and pooling.
Source code in vllm_mlx/embedding.py
vllm_mlx.embedding.EmbeddingEngine.is_loaded
property
¶
Return whether the embedding model has been loaded.
vllm_mlx.embedding.EmbeddingEngine.load
¶
Load the embedding model and tokenizer.
Source code in vllm_mlx/embedding.py
vllm_mlx.embedding.EmbeddingEngine._ensure_loaded
¶
vllm_mlx.embedding.EmbeddingEngine._resolve_max_length
¶
Tokenizer truncation length from the model config (cached).
Source code in vllm_mlx/embedding.py
vllm_mlx.embedding.EmbeddingEngine.embed
¶
Generate embeddings for one or more texts.
Parameters:
-
texts(str | list[str]) –A single string or list of strings.
Returns:
-
list[list[float]]–List of embedding vectors (one per input text).
Source code in vllm_mlx/embedding.py
vllm_mlx.embedding.EmbeddingEngine.count_tokens
¶
Approximate token count for usage reporting.
Source code in vllm_mlx/embedding.py
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.
vllm_mlx.embedding.EmbeddingEngine · class
Wrapper around mlx-embeddings for text embedding generation.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
model_name |
str |
yes |
none |
Required positional or keyword input. |
Returns
- Constructs:
vllm_mlx.embedding.EmbeddingEngine
Exceptions and behavior
Class EmbeddingEngine declares 7 direct member(s).
No direct raise statement appears in this definition.
vllm_mlx.embedding.EmbeddingEngine.__init__ · method
Method EmbeddingEngine.__init__ updates self.model_name, self._model, self._tokenizer, self._max_length.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
model_name |
str |
yes |
none |
Required positional or keyword input. |
Returns
- Type:
not annotated
Exceptions and behavior
Method EmbeddingEngine.__init__ updates self.model_name, self._model, self._tokenizer, self._max_length.
No direct raise statement appears in this definition.
vllm_mlx.embedding.EmbeddingEngine.is_loaded · method
Return whether the embedding model has been loaded.
Parameters
This callable has no explicit inputs.
Returns
- Type:
bool - Direct return expressions:
self._model is not None
Exceptions and behavior
Method EmbeddingEngine.is_loaded returns self._model is not None.
No direct raise statement appears in this definition.
vllm_mlx.embedding.EmbeddingEngine.load · method
Load the embedding model and tokenizer.
Parameters
This callable has no explicit inputs.
Returns
- Type:
None
Exceptions and behavior
Method EmbeddingEngine.load updates self._model, self._tokenizer; calls logger.info, time.perf_counter, load.
No direct raise statement appears in this definition.
vllm_mlx.embedding.EmbeddingEngine._ensure_loaded · method
Method EmbeddingEngine._ensure_loaded calls self.load.
Parameters
This callable has no explicit inputs.
Returns
- Type:
None
Exceptions and behavior
Method EmbeddingEngine._ensure_loaded calls self.load.
No direct raise statement appears in this definition.
vllm_mlx.embedding.EmbeddingEngine._resolve_max_length · method
Tokenizer truncation length from the model config (cached).
Parameters
This callable has no explicit inputs.
Returns
- Type:
int - Direct return expressions:
self._max_length
Exceptions and behavior
Method EmbeddingEngine._resolve_max_length updates self._max_length; calls resolve_max_length, getattr; returns self._max_length.
No direct raise statement appears in this definition.
vllm_mlx.embedding.EmbeddingEngine.embed · method
Generate embeddings for one or more texts.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
texts |
str \| list[str] |
yes |
none |
A single string or list of strings. |
Returns
- Type:
list[list[float]] - Direct return expressions:
result
Exceptions and behavior
Method EmbeddingEngine.embed calls self._ensure_loaded, isinstance, inner_tokenizer, inner_tok; returns result.
No direct raise statement appears in this definition.
vllm_mlx.embedding.EmbeddingEngine.count_tokens · method
Approximate token count for usage reporting.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
texts |
str \| list[str] |
yes |
none |
Required positional or keyword input. |
Returns
- Type:
int - Direct return expressions:
total
Exceptions and behavior
Method EmbeddingEngine.count_tokens calls self._ensure_loaded, isinstance, self._tokenizer.encode, len; returns total.
No direct raise statement appears in this definition.
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 |
|---|---|---|---|---|
EmbeddingEngine |
class | EmbeddingEngine(model_name: str) |
Wrapper around mlx-embeddings for text embedding generation. | #L19-L131 |
EmbeddingEngine.__init__ |
method | EmbeddingEngine.__init__(model_name: str) -> not annotated |
Method EmbeddingEngine.__init__ updates self.model_name, self._model, self._tokenizer, self._max_length. |
#L27-L31 |
EmbeddingEngine.is_loaded |
method | EmbeddingEngine.is_loaded() -> bool |
Return whether the embedding model has been loaded. | #L34-L37 |
EmbeddingEngine.load |
method | EmbeddingEngine.load() -> None |
Load the embedding model and tokenizer. | #L39-L47 |
EmbeddingEngine._ensure_loaded |
method | EmbeddingEngine._ensure_loaded() -> None |
Method EmbeddingEngine._ensure_loaded calls self.load. |
#L49-L51 |
EmbeddingEngine._resolve_max_length |
method | EmbeddingEngine._resolve_max_length() -> int |
Tokenizer truncation length from the model config (cached). | #L53-L60 |
EmbeddingEngine.embed |
method | EmbeddingEngine.embed(texts: str \| list[str]) -> list[list[float]] |
Generate embeddings for one or more texts. | #L62-L109 |
EmbeddingEngine.count_tokens |
method | EmbeddingEngine.count_tokens(texts: str \| list[str]) -> int |
Approximate token count for usage reporting. | #L111-L131 |