DS DevShelfHub Projects · AI tools
Tutorials / LangChain / Reference / Classes / NomicEmbeddings
Embeddings langchain-community Beginner

NomicEmbeddings: Reference Guide

By DevShelfHub

Use Nomic's open-source embeddings.

What is NomicEmbeddings?

NomicEmbeddings wraps Nomic's nomic-embed-text family — open-weight models trained for high retrieval accuracy with an 8192-token context window, far longer than the typical 512-token limit of sentence-transformers models. The models can run locally via the nomic Python SDK or be called through Nomic's hosted Atlas API. Both modes use the same class; the difference is whether NOMIC_API_KEY is set and whether you want hosted inference or local GPU inference.

A key design feature of Nomic models is the task_type prefix. Prepending 'search_query: ' to queries and 'search_document: ' to documents during indexing measurably improves retrieval recall. This asymmetric encoding is not automatic — you must configure task_type explicitly. NomicEmbeddings exposes task_type='search_query' for query-time and task_type='search_document' for index-time.

The nomic-embed-text-v1.5 model is Matryoshka-capable, meaning you can truncate its 768-dimension output to smaller sizes (64, 128, 256) with minimal quality loss via the dimensionality parameter. This is useful when your vector store has index-size constraints or when you want faster similarity search and lower storage cost.

When to Use

You want privacy or local embeddings with decent quality. Use Nomic for open-source projects.

Use Cases

  • Local embeddings
  • Privacy-focused
  • Open-source
  • Low-cost
  • Self-hosted
  • Customizable

Key Features

  • Open-source
  • Local inference
  • Good quality
  • Privacy
  • No API
  • Customizable

When NOT to Use

For production SLAs or highest quality.

Notes

task_type prefixes improve retrieval recall significantly

Nomic recommends using search_document for indexing and search_query for querying. Without them, the model treats both as general text and retrieval quality drops. Always set task_type explicitly — asymmetric retrieval is the intended usage pattern and skipping it is the most common reason Nomic-backed RAG underperforms expectations.

API vs local inference via NOMIC_API_KEY

If NOMIC_API_KEY is set, NomicEmbeddings calls the hosted Atlas API. Without it, the nomic SDK runs inference locally. The API path is faster for small batch sizes; local inference is free but needs a GPU for reasonable throughput. Set NOMIC_API_KEY=None explicitly to force local mode even in environments where the key might be set.

8192-token context — chunk less aggressively than with sentence-transformers

Nomic models handle up to 8192 tokens per input without silent truncation. This lets you embed longer document chunks (whole paragraphs, code blocks) without splitting them further. Smaller chunks still improve retrieval precision, but you have more headroom than with 512-token models.

Prefer langchain-nomic package over langchain-community import

The canonical import for newer projects is from langchain_nomic import NomicEmbeddings (pip install langchain-nomic). The langchain-community import still works but may lag behind on new model support. Pin langchain-nomic alongside your LangChain version.

Import

python
from langchain_community.embeddings import NomicEmbeddings

Configuration

Parameter Type Default Purpose
model str nomic-embed-text-v1.5 Nomic model

Usage Examples

Default Nomic Embeddings

python
from langchain_community.embeddings import NomicEmbeddings

embeddings = NomicEmbeddings(model='nomic-embed-text-v1.5')
vec = embeddings.embed_query('What is retrieval augmented generation?')
print(len(vec))  # 768 dimensions

Asymmetric Retrieval with task_type

python
# Use task_type prefixes for better retrieval quality
doc_embedder = NomicEmbeddings(
    model='nomic-embed-text-v1.5', task_type='search_document'
)
query_embedder = NomicEmbeddings(
    model='nomic-embed-text-v1.5', task_type='search_query'
)
doc_vecs = doc_embedder.embed_documents(['LangChain intro'])
query_vec = query_embedder.embed_query('What is LangChain?')

Reduced Dimensionality (Matryoshka)

python
# Matryoshka: truncate to smaller dimensions
embeddings = NomicEmbeddings(
    model='nomic-embed-text-v1.5',
    dimensionality=256,
)
vec = embeddings.embed_query('compact vector')
print(len(vec))  # 256 instead of 768

Common Pitfalls

❌ Expect highest quality like OpenAI

✅ Good quality, but not top-tier

Alternative Embedding Models

Model When to Use
HuggingFaceEmbeddings For more model variety

Browse the full LangChain API reference index to explore more classes, methods, and decorators, or start with the LangChain introduction tutorial for end-to-end context on building with NomicEmbeddings and the wider framework.

NomicEmbeddings FAQ

What is NomicEmbeddings in LangChain?

Use Nomic's open-source embeddings. NomicEmbeddings wraps Nomic's nomic-embed-text family — open-weight models trained for high retrieval accuracy with an 8192-token context window, far longer than the typical 512-token limit of sentence-transformers models. The models can run locally via the nomic Python SDK or be called through Nomic's hosted Atlas API. Both modes use the same class; the difference is whether NOMIC_API_KEY is set and whether you want hosted inference or local GPU inference. A key design feat…

Which package provides NomicEmbeddings?

DevShelfHub documents NomicEmbeddings from the langchain-community package. Pin your installed LangChain version and match imports to the snippet on this page.

When should I use NomicEmbeddings?

You want privacy or local embeddings with decent quality. Use Nomic for open-source projects.

When should I avoid using NomicEmbeddings?

For production SLAs or highest quality.

How do I import NomicEmbeddings in Python?

from langchain_community.embeddings import NomicEmbeddings

Where can I explore more LangChain API reference pages?

Open the LangChain API reference index on DevShelfHub to browse classes, methods, and decorators, each with runnable examples, parameters, common mistakes, and cross-links.