
LANGCHAIN — How Can Voyage Embeddings Enhance LangChain and Chat?
The most dangerous phrase in the language is, ‘We’ve always done it this way.’ — Grace Hopper
Voyage embeddings can significantly enhance LangChain and Chat by improving the retrieval quality and, consequently, the overall response quality. By integrating Voyage AI’s embedding models into LangChain, you can achieve more accurate and contextually informed responses in your chatbot. Let’s delve into how Voyage embeddings can be utilized in LangChain and explore some examples demonstrating their effectiveness.
Evaluating the effect of embeddings in the RAG stack
To understand the impact of embedding models on the retrieval-augmented generation (RAG) process, let’s consider an example comparing the retrieval and response quality of different embedding models. In this example, we’ll use Voyage’s generalist embedding model voyage-01 and an enhanced version fine-tuned on LangChain documents, voyage-langchain-01.
Measuring response and retrieval quality
We measure response quality using semantic similarity scores and retrieval quality using the NDCG@10 metric. The results show that voyage-01 surpasses OpenAI’s text-embedding-ada-002 in both retrieval and response quality. Furthermore, voyage-langchain-01 demonstrates the highest retrieval and response quality, indicating a strong correlation between retrieval quality and final response quality.
Demonstrating examples
Let’s showcase a few examples to illustrate how Voyage’s embeddings enable more accurate responses in the RAG stack.
Example 1: voyage-01 vs text-embedding-ada-002
Given the query “What is html2texttransformer? Does it omit urls?”, voyage-01 fetches the correct document, providing an accurate response. Meanwhile, text-embedding-ada-002 retrieves a less relevant document, leading to a less accurate response.
Example 2: voyage-01 vs voyage-langchain-01
For the query “I’m running my own model using vllm. How do I connect it to LangChain?”, voyage-01 fails to retrieve a relevant document, resulting in an inaccurate response. However, voyage-langchain-01 retrieves the correct document and generates an accurate response.
Using Voyage in LangChain
To leverage Voyage embeddings in LangChain, you can integrate the voyage-01 model into your applications. Here's a simple example demonstrating how to use Voyage to power KNN retrieval in LangChain:
from langchain.embeddings import VoyageEmbeddings
from langchain.retrievers import KNNRetriever
texts = [
"Caching embeddings enables the storage or temporary caching of embeddings, eliminating the necessity to recompute them each time.",
"The agent executor is the runtime for an agent. This is what actually calls the agent and executes the actions it chooses",
"A Runnable represents a generic unit of work that can be invoked, batched, streamed, and/or transformed."
]
embeddings = VoyageEmbeddings(model="voyage-01", batch_size=8)
retriever = KNNRetriever.from_texts(texts, embeddings, k=1)
result = retriever.get_relevant_documents("How do I build an agent?")
print(result[0].page_content)By following these steps, you can start using Voyage embeddings in LangChain to enhance the retrieval and response quality of your chatbot.
In conclusion, the quality of the final response is highly correlated with the retrieval quality, emphasizing the importance of using high-quality embeddings in your RAG stack. By integrating Voyage embeddings such as voyage-01 or voyage-langchain-01 into LangChain, you can significantly improve the performance of your chatbot.
