Skip to main content
Voyage AI provides embedding models and rerankers, including general-purpose models and domain-specific models for areas such as code and law. This guide uses voyage-law-2, a legal-domain model.

Setup guide

In this guide, you use the Voyage Embedding API endpoint to generate text embeddings for terms of service and consumer contract documents, and then index those embeddings in Pinecone Database. This is a common combination for building retrieval-augmented generation (RAG), semantic search, question-answering, code assistants, and other applications that rely on NLP and search over a large corpus of text data.
1

Set up the environment

Start by installing the Voyage and Pinecone clients, along with Hugging Face Datasets for downloading the LegalBench: Consumer Contracts QA (mteb/legalbench_consumer_contracts_qa) dataset used in this guide:
Shell
2

Create embeddings

Sign up for an API key at Voyage AI and then use it to initialize your connection.
Python
Load the LegalBench: Consumer Contracts QA dataset, which contains 154 consumer contract documents and 396 labeled queries about these documents.
Python
Each document in mteb/legalbench_consumer_contracts_qa contains a text field, which you embed with the Voyage AI client.
Python
Check the dimensionality of the returned vectors. Save the embedding dimensionality, because you need it when you create your Pinecone index later.
Python
Response
In this example, you can see that for each of the 154 documents, the code creates a 1024-dimensional embedding with the Voyage AI voyage-law-2 model.
3

Store the embeddings

Now that you have your embeddings, you can move on to indexing them in Pinecone Database. For this, you need a Pinecone API key. Sign up for one.First, initialize your connection to Pinecone, and then create a new index called voyageai-pinecone-legalbench for storing the embeddings. When you create the index, specify the cosine similarity metric to align with Voyage AI’s embeddings, and pass the embedding dimensionality of 1024.
Python
Now you can begin populating the index with your embeddings. Pinecone expects you to provide a list of tuples in the format (id, vector, metadata), where the metadata field is an optional extra field where you can store anything you want in a dictionary format. For this example, you’ll store the original text of the embeddings.Upload the data in batches to avoid pushing too much data at once.
Python
Response
You can see from index.describe_index_stats that you have a 1024-dimensional index populated with 154 embeddings.
5

Clean up

When you’re finished with the index, delete it.
Python