nomic-embed-text-v1.5: Resizable Production Embeddings with Matryoshka Representation Learning
nomic-embed-text-v1.5 is an improvement upon Nomic Embed that utilizes Matryoshka Representation Learning which gives developers the flexibility to trade off the embedding size for a negligible reduction in performance.
Name
SeqLen
Dimension
MTEB
nomic-embed-text-v1
8192
768
62.39
nomic-embed-text-v1.5
8192
768
62.28
nomic-embed-text-v1.5
8192
512
61.96
nomic-embed-text-v1.5
8192
256
61.04
nomic-embed-text-v1.5
8192
128
59.34
nomic-embed-text-v1.5
8192
64
56.10
image/png
Hosted Inference API
The easiest way to get started with Nomic Embed is through the Nomic Embedding API.
Generating embeddings with the nomic Python client is as easy as
We train our embedder using a multi-stage training pipeline. Starting from a long-context BERT model,
the first unsupervised contrastive stage trains on a dataset generated from weakly related text pairs, such as question-answer pairs from forums like StackExchange and Quora, title-body pairs from Amazon reviews, and summarizations from news articles.
In the second finetuning stage, higher quality labeled datasets such as search queries and answers from web searches are leveraged. Data curation and hard-example mining is crucial in this stage.
Training data to train the models is released in its entirety. For more details, see the contrastorsrepository
Usage
Note nomic-embed-text requires prefixes! We support the prefixes [search_query, search_document, classification, clustering].
For retrieval applications, you should prepend search_document for all your documents and search_query for your queries.
Sentence Transformers
python
1import torch.nn.functional as F
2from sentence_transformers import SentenceTransformer
34matryoshka_dim =51256model = SentenceTransformer("nomic-ai/nomic-embed-text-v1.5", trust_remote_code=True)7sentences =['search_query: What is TSNE?','search_query: Who is Laurens van der Maaten?']8embeddings = model.encode(sentences, convert_to_tensor=True)9embeddings = F.layer_norm(embeddings, normalized_shape=(embeddings.shape[1],))10embeddings = embeddings[:,:matryoshka_dim]11embeddings = F.normalize(embeddings, p=2, dim=1)12print(embeddings)
The model natively supports scaling of the sequence length past 2048 tokens. To do so,
diff
1- tokenizer = AutoTokenizer.from_pretrained('bert-base-uncased')
2+ tokenizer = AutoTokenizer.from_pretrained('bert-base-uncased', model_max_length=8192)
345- model = AutoModel.from_pretrained('nomic-ai/nomic-embed-text-v1', trust_remote_code=True)
6+ model = AutoModel.from_pretrained('nomic-ai/nomic-embed-text-v1', trust_remote_code=True, rotary_scaling_factor=2)
Transformers.js
js
1import{ pipeline, layer_norm }from'@xenova/transformers';23// Create a feature extraction pipeline4const extractor =awaitpipeline('feature-extraction','nomic-ai/nomic-embed-text-v1.5',{5quantized:false,// Comment out this line to use the quantized version6});78// Define sentences9const texts =['search_query: What is TSNE?','search_query: Who is Laurens van der Maaten?'];1011// Compute sentence embeddings12let embeddings =awaitextractor(texts,{pooling:'mean'});13console.log(embeddings);// Tensor of shape [2, 768]1415const matryoshka_dim =512;16embeddings =layer_norm(embeddings,[embeddings.dims[1]])17.slice(null,[0, matryoshka_dim])18.normalize(2,-1);19console.log(embeddings.tolist());
If you find the model, dataset, or training code useful, please cite our work
bibtex
1@misc{nussbaum2024nomic,
2 title={Nomic Embed: Training a Reproducible Long Context Text Embedder},
3 author={Zach Nussbaum and John X. Morris and Brandon Duderstadt and Andriy Mulyar},
4 year={2024},
5 eprint={2402.01613},
6 archivePrefix={arXiv},
7 primaryClass={cs.CL}
8}