Downloads · 30 days
112
8% of all-time downloads
hasankursun/matryoshka-embedding-v1
matryoshka-embedding-v1 is a sentence similarity model from hasankursun. Use it when you need a score for how close two texts are. It is set up for sentence-transformers. The card lists the license as cc-by-nc-4.0.
A multilingual text embedding model with Matryoshka Representation Learning, allowing flexible embedding dimensions from 64D to 1024D.
Downloads · 30 days
112
8% of all-time downloads
All-time downloads
1.4K
Public
Parameters
568M
2.3 GB on disk
Likes
3
Public
Click a slice to open those files.
.safetensors2.3 GB · 99%
From the Hugging Face model README
A multilingual text embedding model with Matryoshka Representation Learning, allowing flexible embedding dimensions from 64D to 1024D.
This model implements Matryoshka Representation Learning, enabling you to truncate embeddings to different dimensions while maintaining good performance. This allows you to balance accuracy, speed, and storage based on your specific needs.
pip install sentence-transformers
from sentence_transformers import SentenceTransformer
# Load model
model = SentenceTransformer('hasankursun/matryoshka-text-embedding-v1')
# Full precision (1024D)
embeddings = model.encode(["Your text here"])
# Balanced mode (512D) - Recommended for most use cases
embeddings = model.encode(["Your text here"], truncate_dim=512)
# Fast mode (256D) - For high-throughput applications
embeddings = model.encode(["Your text here"], truncate_dim=256)
# Ultra-fast mode (128D) - For real-time applications
embeddings = model.encode(["Your text here"], truncate_dim=128)
| Dimension | NDCG@10 | Relative Performance |
|---|---|---|
| 1024D | 0.6308 | 100.0% |
| 768D | 0.6277 | 99.5% |
| 512D | 0.6114 | 96.9% |
| 384D | 0.6035 | 95.7% |
| 256D | 0.5614 | 89.0% |
| 128D | 0.4732 | 75.0% |
| 64D | 0.3317 | 52.6% |
Average Spearman Correlation across languages: 0.8096
Performance by language pair (1024D):
import numpy as np
from sentence_transformers import util
# Index documents with 512D (optimal balance)
documents = [
"Artificial intelligence is transforming healthcare.",
"Machine learning models require large datasets.",
"Quantum computing promises exponential speedups."
]
doc_embeddings = model.encode(documents, truncate_dim=512)
# Search with same dimension
query = "How is AI used in medicine?"
query_embedding = model.encode(query, truncate_dim=512)
# Compute similarities
similarities = util.cos_sim(query_embedding, doc_embeddings)
top_result = np.argmax(similarities)
print(f"Most relevant: {documents[top_result]}")
import faiss
import numpy as np
# Create embeddings with 512D
embeddings = model.encode(documents, truncate_dim=512)
embeddings = embeddings.astype('float32')
# Build FAISS index
dimension = 512
index = faiss.IndexFlatIP(dimension)
faiss.normalize_L2(embeddings)
index.add(embeddings)
# Search
query_embedding = model.encode(query, truncate_dim=512).astype('float32')
faiss.normalize_L2(query_embedding.reshape(1, -1))
distances, indices = index.search(query_embedding.reshape(1, -1), k=10)
pytorch_model.bin - Model weightsconfig.json - Model configurationtokenizer.json - Tokenizer configurationmatryoshka_config.json - Matryoshka-specific configurationThis model is released under the CC-BY-NC-4.0 (Creative Commons Attribution-NonCommercial 4.0 International) license.
See the LICENSE file for full details and acknowledgments.
This model builds upon important foundational work:
If you use this model in your research or application, please cite:
@misc{matryoshka-text-embedding-v1,
title={Matryoshka Text Embedding v1},
author={Hasan Kurşun},
year={2025},
url={[https://huggingface.co/hasankursun/matryoshka-text-embedding-v1](https://huggingface.co/hasankursun/matryoshka-text-embedding-v1)}
}