Skip to main content
Voyage AI provides cutting-edge embedding/vectorizations models.
Let’s load the Voyage AI Embedding class. (Install the LangChain partner package with pip install langchain-voyageai)
Voyage AI utilizes API keys to monitor usage and manage permissions. To obtain your key, create an account on our homepage. Then, create a VoyageEmbeddings model with your API key. You can use any of the following models: (source):
  • voyage-4-large
  • voyage-4
  • voyage-4-lite
  • voyage-context-3
  • voyage-3.5
  • voyage-3.5-lite
  • voyage-3-large
  • voyage-3
  • voyage-3-lite
  • voyage-large-2
  • voyage-code-2
  • voyage-2
  • voyage-law-2
  • voyage-large-2-instruct
  • voyage-finance-2
  • voyage-multilingual-2
Prepare the documents and use embed_documents to get their embeddings.
Similarly, use embed_query to embed the query.

A minimalist retrieval system

The main feature of the embeddings is that the cosine similarity between two embeddings captures the semantic relatedness of the corresponding original passages. This allows us to use the embeddings to do semantic retrieval / search. We can find a few closest embeddings in the documents embeddings based on the cosine similarity, and retrieve the corresponding document using the KNNRetriever class from LangChain.