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:
Load and split source data into documents.
Store the documents and their embeddings in MongoDB.
Create a MongoDB Vector Search index on your embeddings.
Run semantic search queries on your data.
Implement RAG to answer questions about your data.
Background
The LangChain integration includes the following Voyage AI packages:
In Python, the
langchain-voyageaipackage provides theVoyageAIEmbeddingsclass.In TypeScript, the
@langchain/mongodbpackage provides theVoyageEmbeddingsclass alongside theMongoDBAtlasVectorSearchvector 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.
Tutorial
The following tutorial demonstrates how to use Voyage AI embeddings with LangChain. Select your preferred language and LLM provider to view the corresponding instructions.
Next Steps
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_dimensionparameter when you instantiateVoyageAIEmbeddings. Thevoyage-4-largemodel supports256,512,1024(default), and2048dimensions. 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:
To implement RAG without a framework, see Retrieval-Augmented Generation (RAG) with Voyage AI.
To learn about other LangChain tutorials that use MongoDB, see Get Started with the MongoDB LangChain Integration.
To learn how to use Voyage AI models with other LLM frameworks and AI services, see MongoDB AI Integrations and Partners.