nomic-ai / nomic-embed-code

huggingface.co
Total runs: 242.8K
24-hour runs: -4.3K
7-day runs: -11.5K
30-day runs: -159.7K
Model's Last Updated: April 01 2025
sentence-similarity

Introduction of nomic-embed-code

Model Details of nomic-embed-code

Nomic Embed Code: A State-of-the-Art Code Retriever

nomic-embed-code is a state-of-the-art code embedding model that excels at code retrieval tasks:

  • High Performance : Outperforms Voyage Code 3 and OpenAI Embed 3 Large on CodeSearchNet
  • Multilingual Code Support : Trained for multiple programming languages (Python, Java, Ruby, PHP, JavaScript, Go)
  • Advanced Architecture : 7B parameter code embedding model
  • Fully Open-Source : Model weights, training data, and evaluation code released
Model Python Java Ruby PHP JavaScript Go
Nomic Embed Code 81.7 80.5 81.8 72.3 77.1 93.8
Voyage Code 3 80.8 80.5 84.6 71.7 79.2 93.2
OpenAI Embed 3 Large 70.8 72.9 75.3 59.6 68.1 87.6
Nomic CodeRankEmbed-137M 78.4 76.9 79.3 68.8 71.4 92.7
CodeSage Large v2 (1B) 74.2 72.3 76.7 65.2 72.5 84.6
CodeSage Large (1B) 70.8 70.2 71.9 61.3 69.5 83.7
Qodo Embed 1 7B 59.9 61.6 68.4 48.5 57.0 81.4
Model Architecture
  • Total Parameters : 7B
  • Training Approach : Trained on the CoRNStack dataset with dual-consistency filtering and progressive hard negative mining
  • Supported Languages : Python, Java, Ruby, PHP, JavaScript, and Go
Usage Guide
Installation

You can install the necessary dependencies with:

pip install transformers sentence-transformers torch
Transformers
import torch
import torch.nn.functional as F
from transformers import AutoTokenizer, AutoModel

tokenizer = AutoTokenizer.from_pretrained("nomic-ai/nomic-embed-code")
model = AutoModel.from_pretrained("nomic-ai/nomic-embed-code")

def last_token_pooling(hidden_states, attention_mask):
    sequence_lengths = attention_mask.sum(-1) - 1
    return hidden_states[torch.arange(hidden_states.shape[0]), sequence_lengths]

queries = ['Represent this query for searching relevant code: Calculate the n-th factorial']
codes = ['def fact(n):\n if n < 0:\n  raise ValueError\n return 1 if n == 0 else n * fact(n - 1)']
code_snippets = queries + codes

encoded_input = tokenizer(code_snippets, padding=True, truncation=True, return_tensors='pt')
model.eval()
with torch.no_grad():
    model_output = model(**encoded_input)[0]

embeddings = last_token_pooling(model_output, encoded_input['attention_mask'])
embeddings = F.normalize(embeddings, p=2, dim=1)
print(embeddings.shape)

similarity = F.cosine_similarity(embeddings[0], embeddings[1], dim=0)
print(similarity)
SentenceTransformers
from sentence_transformers import SentenceTransformer

queries = ['Calculate the n-th factorial']
code_snippets = ['def fact(n):\n if n < 0:\n  raise ValueError\n return 1 if n == 0 else n * fact(n - 1)']

model = SentenceTransformer("nomic-ai/nomic-embed-code")
query_emb = model.encode(queries, prompt_name="query")
code_emb = model.encode(code_snippets)

similarity = model.similarity(query_emb[0], code_emb[0])
print(similarity)
CoRNStack Dataset Curation

Starting with the deduplicated Stackv2, we create text-code pairs from function docstrings and respective code. We filtered out low-quality pairs where the docstring wasn't English, too short, or that contained URLs, HTML tags, or invalid characters. We additionally kept docstrings with text lengths of 256 tokens or longer to help the model learn long-range dependencies.

image/png

After the initial filtering, we used dual-consistency filtering to remove potentially noisy examples. We embed each docstring and code pair and compute the similarity between each docstring and every code example. We remove pairs from the dataset if the corresponding code example is not found in the top-2 most similar examples for a given docstring.

During training, we employ a novel curriculum-based hard negative mining strategy to ensure the model learns from challenging examples. We use a softmax-based sampling strategy to progressively sample hard negatives with increasing difficulty over time.

Join the Nomic Community

Citation

If you find the model, dataset, or training code useful, please cite our work:

@misc{suresh2025cornstackhighqualitycontrastivedata,
      title={CoRNStack: High-Quality Contrastive Data for Better Code Retrieval and Reranking}, 
      author={Tarun Suresh and Revanth Gangi Reddy and Yifei Xu and Zach Nussbaum and Andriy Mulyar and Brandon Duderstadt and Heng Ji},
      year={2025},
      eprint={2412.01007},
      archivePrefix={arXiv},
      primaryClass={cs.CL},
      url={https://arxiv.org/abs/2412.01007}, 
}

Runs of nomic-ai nomic-embed-code on huggingface.co

242.8K
Total runs
-4.3K
24-hour runs
-4.7K
3-day runs
-11.5K
7-day runs
-159.7K
30-day runs

More Information About nomic-embed-code huggingface.co Model

More nomic-embed-code license Visit here:

https://choosealicense.com/licenses/apache-2.0

nomic-embed-code huggingface.co

nomic-embed-code huggingface.co is an AI model on huggingface.co that provides nomic-embed-code's model effect (), which can be used instantly with this nomic-ai nomic-embed-code model. huggingface.co supports a free trial of the nomic-embed-code model, and also provides paid use of the nomic-embed-code. Support call nomic-embed-code model through api, including Node.js, Python, http.

nomic-embed-code huggingface.co Url

https://huggingface.co/nomic-ai/nomic-embed-code

nomic-ai nomic-embed-code online free

nomic-embed-code huggingface.co is an online trial and call api platform, which integrates nomic-embed-code's modeling effects, including api services, and provides a free online trial of nomic-embed-code, you can try nomic-embed-code online for free by clicking the link below.

nomic-ai nomic-embed-code online free url in huggingface.co:

https://huggingface.co/nomic-ai/nomic-embed-code

nomic-embed-code install

nomic-embed-code is an open source model from GitHub that offers a free installation service, and any user can find nomic-embed-code on GitHub to install. At the same time, huggingface.co provides the effect of nomic-embed-code install, users can directly use nomic-embed-code installed effect in huggingface.co for debugging and trial. It also supports api for free installation.

nomic-embed-code install url in huggingface.co:

https://huggingface.co/nomic-ai/nomic-embed-code

Url of nomic-embed-code

nomic-embed-code huggingface.co Url

Provider of nomic-embed-code huggingface.co

nomic-ai
ORGANIZATIONS

Other API from nomic-ai

huggingface.co

Total runs: 15.3K
Run Growth: -3.9K
Growth Rate: -25.60%
Updated:June 24 2025
huggingface.co

Total runs: 2.0K
Run Growth: -110
Growth Rate: -5.42%
Updated:April 08 2024
huggingface.co

Total runs: 833
Run Growth: -253
Growth Rate: -30.37%
Updated:May 25 2023