For AI agents: a documentation index is available at https://www.mongodb.com/docs/llms.txt — markdown versions of all pages are available by appending .md to any URL path.
Docs Menu

Integrate Voyage AI with LangChain

LangChain is an open-source framework that provides chains to simplify the creation of large language model applications. Chains consist of interconnected LangChain components that perform a sequence of operations. You can use chains for a variety of AI use cases, including RAG and agentic retrieval.

LangChain provides dedicated packages that expose Voyage AI embedding models as standard LangChain embedding classes. When you pair those packages with MongoDB, you can store your embeddings alongside your other data and query them with MongoDB Vector Search.

This tutorial demonstrates how to use Voyage AI embeddings with LangChain to complete the following tasks:

  1. Load and split source data into documents.

  2. Store the documents and their embeddings in MongoDB.

  3. Create a MongoDB Vector Search index on your embeddings.

  4. Run semantic search queries on your data.

  5. Implement RAG to answer questions about your data.

The LangChain integration includes the following Voyage AI packages:

  • In Python, the langchain-voyageai package provides the VoyageAIEmbeddings class.

  • In TypeScript, the @langchain/mongodb package provides the VoyageEmbeddings class alongside the MongoDBAtlasVectorSearch vector store.

Because both packages implement LangChain's standard embedding interface, you can pass a Voyage model to any LangChain component that accepts embeddings, including vector stores and retrievers.

The following tutorial demonstrates how to use Voyage AI embeddings with LangChain. Select your preferred language and LLM provider to view the corresponding instructions.

Language
LLM Provider

After you have a working pipeline, you can make the following adjustments to improve retrieval quality without changing your LangChain chain:

  • To reduce the storage footprint of your embeddings, pass the output_dimension parameter when you instantiate VoyageAIEmbeddings. The voyage-4-large model supports 256, 512, 1024 (default), and 2048 dimensions. To learn more, see Flexible Dimensions and Quantization.

  • To choose a different embedding model for your domain or latency budget, see Text Embeddings.

  • To reorder your search results by relevance before you pass them to the LLM, add a reranker. To learn more, see Rerankers.

To view additional tutorials, see the following resources:

Rate this page