DS DevShelfHub Projects · AI tools
Tutorials / LangChain / Reference / Classes / VoyageAIEmbeddings
Embeddings langchain-voyageai Beginner

VoyageAIEmbeddings: Reference Guide

By DevShelfHub

Use Voyage AI's specialized embeddings.

What is VoyageAIEmbeddings?

VoyageAIEmbeddings wraps Voyage AI's text embedding API in LangChain's Embeddings interface. Voyage AI was founded specifically to build retrieval-optimized embedding models, and its voyage-large-2-instruct and voyage-3 families consistently rank at the top of the MTEB retrieval track. Unlike general-purpose embedding providers, Voyage AI's models are trained with instruction fine-tuning for retrieval — the model is aware whether an input is a search query or a passage, which materially improves relevance scoring.

The class maps cleanly to LangChain's embedding protocol: embed_query() for single queries, embed_documents() for passage batches. Voyage AI exposes an input_type parameter (query or document) that VoyageAIEmbeddings passes through automatically — embed_query() sends input_type=query and embed_documents() sends input_type=document. This asymmetric encoding is a real performance win for RAG: the query and document representations live in semantically aligned but distinct subspaces, which reduces false positives in similarity search.

Voyage AI's pricing is comparable to OpenAI text-embedding-3-large on a per-token basis, but retrieval accuracy tends to be higher on specialized corpora. The voyage-3-lite model is a faster, cheaper variant suited for applications where latency matters more than ranking precision. Set VOYAGE_API_KEY as an environment variable; the key is read at construction time and a missing key raises AuthenticationError.

When to Use

You want embeddings optimized for RAG. Use for retrieval-focused projects.

Use Cases

  • RAG optimization
  • Semantic search
  • Retrieval tasks
  • Document matching
  • Specialized search
  • High-quality retrieval

Key Features

  • RAG-optimized
  • Good similarity
  • Fast API
  • Competitive pricing
  • Search-focused
  • Strong semantic

When NOT to Use

For general-purpose embeddings.

Notes

Model generations — pin the name

voyage-large-2-instruct is the previous-generation flagship; voyage-3 is newer and generally outperforms it on MTEB. Pin the model name in production config — Voyage AI may change what the default resolves to across package versions.

Always use asymmetric encoding

Voyage AI's models are trained with separate query and document towers. Always use embed_query() for search queries and embed_documents() for index passages. Using embed_documents() for queries degrades retrieval quality because the model applies the wrong input_type.

Context length and silent truncation

voyage-large-2-instruct supports up to 16k tokens per text. Texts exceeding this limit are silently truncated — there is no error or warning. For long documents, split with RecursiveCharacterTextSplitter before embedding to avoid losing content.

Rate limits and token quotas

The free tier allows 3M tokens per month with a 300 RPM cap. For high-throughput indexing jobs, request an enterprise plan or add time.sleep() between batch calls to stay within rate limits.

Import

python
from langchain_community.embeddings.voyageai import VoyageAIEmbeddings

Configuration

Parameter Type Default Purpose
model str voyage-large-2-instruct Voyage model

Usage Examples

Basic query embedding

python
embeddings = VoyageAIEmbeddings(model='voyage-large-2-instruct')
vec = embeddings.embed_query('What is semantic search?')
print(f'Dim: {len(vec)}')

Build Chroma store with voyage-3

python
from langchain_community.embeddings.voyageai import VoyageAIEmbeddings
from langchain_chroma import Chroma

embeddings = VoyageAIEmbeddings(model='voyage-3')

passages = [
    'RAG retrieves context before generation.',
    'Voyage AI models are MTEB top-ranked.',
    'LangChain unifies LLM integrations.',
]
store = Chroma.from_texts(passages, embedding=embeddings)
results = store.similarity_search('how does retrieval work?', k=2)
for r in results:
    print(r.page_content)

Async batch embedding with aembed_documents

python
import asyncio
from langchain_community.embeddings.voyageai import VoyageAIEmbeddings

embeddings = VoyageAIEmbeddings(model='voyage-large-2-instruct')

async def embed_batch(texts):
    return await embeddings.aembed_documents(texts)

texts = [f'doc {i}' for i in range(50)]
vectors = asyncio.run(embed_batch(texts))
print(f'Embedded {len(vectors)} docs async')

Common Pitfalls

❌ Forget VOYAGE_API_KEY

✅ export VOYAGE_API_KEY='...'

Alternative Embedding Models

Model When to Use
OpenAIEmbeddings For broader use cases

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 VoyageAIEmbeddings and the wider framework.

VoyageAIEmbeddings FAQ

What is VoyageAIEmbeddings in LangChain?

Use Voyage AI's specialized embeddings. VoyageAIEmbeddings wraps Voyage AI's text embedding API in LangChain's Embeddings interface. Voyage AI was founded specifically to build retrieval-optimized embedding models, and its voyage-large-2-instruct and voyage-3 families consistently rank at the top of the MTEB retrieval track. Unlike general-purpose embedding providers, Voyage AI's models are trained with instruction fine-tuning for retrieval — the model is aware whether an input is a search query or a passage, which…

Which package provides VoyageAIEmbeddings?

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

When should I use VoyageAIEmbeddings?

You want embeddings optimized for RAG. Use for retrieval-focused projects.

When should I avoid using VoyageAIEmbeddings?

For general-purpose embeddings.

How do I import VoyageAIEmbeddings in Python?

from langchain_community.embeddings.voyageai import VoyageAIEmbeddings

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.