Views
No views yet
1pip install sentence-transformers
21from sentence_transformers import SentenceTransformer
2
3# Load model
4model = SentenceTransformer('hasankursun/matryoshka-text-embedding-v1')
5
6# Full precision (1024D)
7embeddings = model.encode(["Your text here"])
8
9# Balanced mode (512D) - Recommended for most use cases
10embeddings = model.encode(["Your text here"], truncate_dim=512)
11
12# Fast mode (256D) - For high-throughput applications
13embeddings = model.encode(["Your text here"], truncate_dim=256)
14
15# Ultra-fast mode (128D) - For real-time applications
16embeddings = model.encode(["Your text here"], truncate_dim=128)
17| 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% |
1import numpy as np
2from sentence_transformers import util
3
4# Index documents with 512D (optimal balance)
5documents = [
6 "Artificial intelligence is transforming healthcare.",
7 "Machine learning models require large datasets.",
8 "Quantum computing promises exponential speedups."
9]
10
11doc_embeddings = model.encode(documents, truncate_dim=512)
12
13# Search with same dimension
14query = "How is AI used in medicine?"
15query_embedding = model.encode(query, truncate_dim=512)
16
17# Compute similarities
18similarities = util.cos_sim(query_embedding, doc_embeddings)
19top_result = np.argmax(similarities)
20
21print(f"Most relevant: {documents[top_result]}")
221import faiss
2import numpy as np
3
4# Create embeddings with 512D
5embeddings = model.encode(documents, truncate_dim=512)
6embeddings = embeddings.astype('float32')
7
8# Build FAISS index
9dimension = 512
10index = faiss.IndexFlatIP(dimension)
11faiss.normalize_L2(embeddings)
12index.add(embeddings)
13
14# Search
15query_embedding = model.encode(query, truncate_dim=512).astype('float32')
16faiss.normalize_L2(query_embedding.reshape(1, -1))
17distances, indices = index.search(query_embedding.reshape(1, -1), k=10)
18pytorch_model.bin - Model weightsconfig.json - Model configurationtokenizer.json - Tokenizer configurationmatryoshka_config.json - Matryoshka-specific configuration1@misc{matryoshka-text-embedding-v1,
2 title={Matryoshka Text Embedding v1},
3 author={Hasan Kurşun},
4 year={2025},
5 url={[https://huggingface.co/hasankursun/matryoshka-text-embedding-v1](https://huggingface.co/hasankursun/matryoshka-text-embedding-v1)}
6}
7