Views
No views yet
| Property | Value |
|---|---|
| Architecture | XLM-RoBERTa |
| Precision | FP16 (float16) |
| Embedding Dimension | 1024 |
| Max Sequence Length | 8192 |
| Model Size | ~1.1 GB |
| Languages | 100+ languages |
1from mlx_embeddings.utils import load_model, load_tokenizer
2import mlx.core as mx
3
4model_path = "mlx-community/bge-m3-mlx-fp16"
5
6# Load model and tokenizer
7model = load_model(model_path)
8tokenizer = load_tokenizer(model_path)
9
10# Generate embeddings
11text = "Hello, world!"
12tokens = tokenizer.encode(text)
13input_ids = mx.array([tokens])
14output = model(input_ids)
15embedding = output.last_hidden_state.mean(axis=1) # Mean pooling
16
17print(f"Embedding shape: {embedding.shape}") # (1, 1024)1# Start oMLX server
2omlx serve --model-dir /path/to/models
3
4# Get embeddings via API
5curl http://127.0.0.1:8000/v1/embeddings \
6 -H "Content-Type: application/json" \
7 -d '{"model": "bge-m3-mlx-fp16", "input": "Your text here"}'1from openai import OpenAI
2
3client = OpenAI(base_url="http://127.0.0.1:8000/v1", api_key="dummy")
4
5response = client.embeddings.create(
6 model="bge-m3-mlx-fp16",
7 input="Your text here"
8)
9embedding = response.data[0].embedding # 1024-dimensional vector1@article{bge_m3,
2 title={BGE M3-Embedding: Accurate, Efficient and Versatile Text Embedding},
3 author={Chen, Jianlv and Xiao, Shitao and Zhang, Peitian and Luo, Kun and Zhang, Zheng},
4 journal={arXiv preprint arXiv:2402.03216},
5 year={2024}
6}