MLX Provider¶
MLXEmbedder¶
mailtag.mlx_provider.MLXEmbedder
¶
Generates embeddings using sentence-transformers with MLX backend.
Supports models like nomic-ai/nomic-embed-text-v1.5 which are optimized for semantic similarity tasks and support long context (8k tokens).
Source code in src/mailtag/mlx_provider.py
__init__(model_name='nomic-ai/nomic-embed-text-v1.5')
¶
Initialize the embedder with the specified model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_name
|
str
|
HuggingFace model name for embeddings |
'nomic-ai/nomic-embed-text-v1.5'
|
Source code in src/mailtag/mlx_provider.py
encode(texts, prefix='search_document: ')
¶
Generate embeddings for the given texts.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
texts
|
list[str] | str
|
Single text or list of texts to encode |
required |
prefix
|
str
|
Prefix to add to each text (nomic models use task prefixes) |
'search_document: '
|
Returns:
| Type | Description |
|---|---|
ndarray
|
Numpy array of embeddings with shape (n_texts, embedding_dim) |
Source code in src/mailtag/mlx_provider.py
encode_documents(documents)
¶
Encode document texts (for building an index).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
documents
|
list[str]
|
List of document texts to encode |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
Numpy array of shape (n_documents, embedding_dim) |
Source code in src/mailtag/mlx_provider.py
MLXLLM¶
mailtag.mlx_provider.MLXLLM
¶
Answers short prompts in batches using mlx-lm (Signal 6).
Uses quantized models from mlx-community for efficient inference on Apple Silicon.
Source code in src/mailtag/mlx_provider.py
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 | |
__init__(model_name='mlx-community/gemma-4-e4b-it-OptiQ-4bit')
¶
Initialize the LLM with the specified model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_name
|
str
|
MLX model name from mlx-community |
'mlx-community/gemma-4-e4b-it-OptiQ-4bit'
|
Source code in src/mailtag/mlx_provider.py
classify_batch(static_prompt, email_parts, batch_size=8, max_tokens=4)
¶
Answer one short prompt per email, reusing the KV cache of the shared static prefix.
The chat-formatted prompt is static_prompt + email_part; the static part is prefilled once
per distinct value and each email only prefills its own tokens. Emails run in batches.