Exciting Update!: nomic-embed-text-v1.5 is now multimodal! nomic-embed-vision-v1.5 is aligned to the embedding space of nomic-embed-text-v1.5, meaning any text embedding is multimodal!
Usage
Important: the text prompt must include a task instruction prefix, instructing the model which task is being performed.
For example, if you are implementing a RAG application, you embed your documents as search_document: <text here> and embed your user queries as search_query: <text here>.
Notice: From transformers v5.5.0 and sentence transformers v5.3.0, trust_remote_code=True will no longer be necessary. This will only be possible with the text-only series as of now.
Task instruction prefixes
search_document
Purpose: embed texts as documents from a dataset
This prefix is used for embedding texts as documents, for example as documents for a RAG index.
python
1from sentence_transformers import SentenceTransformer
23model = SentenceTransformer("nomic-ai/nomic-embed-text-v1.5")4sentences =['search_document: TSNE is a dimensionality reduction algorithm created by Laurens van Der Maaten']5embeddings = model.encode(sentences)6print(embeddings)
search_query
Purpose: embed texts as questions to answer
This prefix is used for embedding texts as questions that documents from a dataset could resolve, for example as queries to be answered by a RAG application.
python
1from sentence_transformers import SentenceTransformer
23model = SentenceTransformer("nomic-ai/nomic-embed-text-v1.5")4sentences =['search_query: Who is Laurens van Der Maaten?']5embeddings = model.encode(sentences)6print(embeddings)
clustering
Purpose: embed texts to group them into clusters
This prefix is used for embedding texts in order to group them into clusters, discover common topics, or remove semantic duplicates.
python
1from sentence_transformers import SentenceTransformer
23model = SentenceTransformer("nomic-ai/nomic-embed-text-v1.5")4sentences =['clustering: the quick brown fox']5embeddings = model.encode(sentences)6print(embeddings)
classification
Purpose: embed texts to classify them
This prefix is used for embedding texts into vectors that will be used as features for a classification model
python
1from sentence_transformers import SentenceTransformer
23model = SentenceTransformer("nomic-ai/nomic-embed-text-v1.5")4sentences =['classification: the quick brown fox']5embeddings = model.encode(sentences)6print(embeddings)
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")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)
1import{ pipeline, layer_norm }from'@huggingface/transformers';23// Create a feature extraction pipeline4const extractor =awaitpipeline('feature-extraction','nomic-ai/nomic-embed-text-v1.5');56// Define sentences7const texts =['search_query: What is TSNE?','search_query: Who is Laurens van der Maaten?'];89// Compute sentence embeddings10let embeddings =awaitextractor(texts,{pooling:'mean'});11console.log(embeddings);// Tensor of shape [2, 768]1213const matryoshka_dim =512;14embeddings =layer_norm(embeddings,[embeddings.dims[1]])15.slice(null,[0, matryoshka_dim])16.normalize(2,-1);17console.log(embeddings.tolist());
Nomic API
The easiest way to use Nomic Embed is through the Nomic Embedding API.
Generating embeddings with the nomic Python client is as easy as
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
Training
Click the Nomic Atlas map below to visualize a 5M sample of our contrastive pretraining data!
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.
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}