Text Embeddings
Model Choices
Voyage currently provides the following text embedding models:
Model | Context Length (tokens) | Embedding Dimension | Description |
---|---|---|---|
voyage-3 | 32000 | 1024 | Optimized for general-purpose and multilingual retrieval quality. See blog post for details. |
voyage-3-lite | 32000 | 512 | Optimized for latency and cost. See blog post for details. |
voyage-finance-2 | 32000 | 1024 | Optimized for finance retrieval and RAG. See blog post for details. |
voyage-multilingual-2 | 32000 | 1024 | Optimized for multilingual retrieval and RAG. See blog post for details. |
voyage-law-2 | 16000 | 1024 | Optimized for legal and long-context retrieval and RAG. Also improved performance across all domains. See blog post for details. |
voyage-code-2 | 16000 | 1536 | Optimized for code retrieval (17% better than alternatives). See blog post for details. |
Need help deciding which text embedding model to use? Check out our FAQ.
Older models
The following are our earlier models, which are still accessible from our API. We recommend using the new models above for better quality and efficiency. Our latest models listed in the above table will be strictly better than the legacy models in all aspects, such as quality, context length, latency, and throughput.
Model | Context Length (tokens) | Embedding Dimension | Description |
---|---|---|---|
voyage-large-2-instruct | 16000 | 1024 | Top of MTEB leaderboard . Instruction-tuned general-purpose embedding model optimized for clustering, classification, and retrieval. For retrieval, please use input_type parameter to specify whether the text is a query or document. For classification and clustering, please use the instructions here . See blog post for details. We recommend existing voyage-large-2-instruct users to transition to voyage-3 . |
voyage-large-2 | 16000 | 1536 | General-purpose embedding model that is optimized for retrieval quality (e.g., better than OpenAI V3 Large). Please transition to voyage-3 . |
voyage-2 | 4000 | 1024 | General-purpose embedding model optimized for a balance between cost, latency, and retrieval quality. Please transition to voyage-3-lite . |
voyage-lite-02-instruct | 4000 | 1024 | [Deprecated] Instruction-tuned for classification, clustering, and sentence textual similarity tasks, which are the only recommended use cases. Please transition to voyage-3 . |
voyage-02 | 4000 | 1024 | [Deprecated] This is our pilot-version v2 embedding model. We kindly ask you to transition to voyage-3 as detailed above. |
voyage-01 | 4000 | 1024 | [Deprecated] This is our v1 embedding model. Please transition to voyage-3 . |
voyage-lite-01 | 4000 | 1024 | [Deprecated] This is our v1 embedding model. Please transition to voyage-3 . |
voyage-lite-01-instruct | 4000 | 1024 | [Deprecated] Tweaked on top of voyage-lite-01 for classification and clustering tasks. Please transition to voyage-3 . |
Python API
Voyage text embeddings are accessible in Python through the voyageai
package. Please first install the voyageai
package and setup the API key, and use the embed()
function of voyageai.Client
to embed your input texts.
voyageai.Client.embed
(texts : List[str], model : str, input_type : Optional[str] = None, truncation : Optional[bool] = None)
Parameters
- texts (List[str]) - A list of texts as a list of strings, such as
["I like cats", "I also like dogs"]
. Currently, we have two constraints on the list:- The maximum length of the list is 128.
- The total number of tokens in the list is at most 1M for
voyage-3-lite
; 320K forvoyage-3
andvoyage-2
; and 120K forvoyage-large-2-instruct
,voyage-finance-2
,voyage-multilingual-2
,voyage-law-2
,voyage-code-2
, andvoyage-large-2
.
- model (str) - Name of the model. Recommended options:
voyage-3
,voyage-3-lite
,voyage-finance-2
,voyage-multilingual-2
,voyage-law-2
,voyage-code-2
. - input_type (str, optional, defaults to
None
) - Type of the input text. Default toNone
. Other options:query
,document
.- When the input_type is set to
None
, and the input text will be directly encoded by our embedding model. Alternatively, when the inputs are documents or queries, the users can specify input_type to bequery
ordocument
, respectively. In such cases, Voyage will prepend a special prompt to input text and send the extended inputs to the embedding model. - For retrieval/search use cases, we recommend specifying this argument when encoding queries or documents to enhance retrieval quality. Embeddings generated with and without the input_type argument are compatible.
- For transparency, the prompts the backend will prepend to your texts are below.
- For query, the prompt is "Represent the query for retrieving supporting documents: ".
- For document, the prompt is "Represent the document for retrieval: ".
- When the input_type is set to
- truncation (bool, optional, defaults to
True
) - Whether to truncate the input texts to fit within the context length.- If
True
, over-length input texts will be truncated to fit within the context length, before vectorized by the embedding model. - If
False
, an error will be raised if any given text exceeds the context length.
- If
Returns
- A
EmbeddingsObject
, containing the following attributes:- embeddings (List[List[float]]) - A list of embeddings for the corresponding list of input texts, where each embedding is a vector represented as a list of floats.
- total_tokens (int) - The total number of tokens in the input texts.
Example
import voyageai
vo = voyageai.Client()
# This will automatically use the environment variable VOYAGE_API_KEY.
# Alternatively, you can use vo = voyageai.Client(api_key="<your secret key>")
texts = [
"The Mediterranean diet emphasizes fish, olive oil, and vegetables, believed to reduce chronic diseases.",
"Photosynthesis in plants converts light energy into glucose and produces essential oxygen.",
"20th-century innovations, from radios to smartphones, centered on electronic advancements.",
"Rivers provide water, irrigation, and habitat for aquatic species, vital for ecosystems.",
"Apple’s conference call to discuss fourth fiscal quarter results and business updates is scheduled for Thursday, November 2, 2023 at 2:00 p.m. PT / 5:00 p.m. ET.",
"Shakespeare's works, like 'Hamlet' and 'A Midsummer Night's Dream,' endure in literature."
]
# Embed the documents
result = vo.embed(texts, model="voyage-3", input_type="document")
print(result.embeddings)
[
[0.005100732669234276, -0.04479769989848137, 0.023507222533226013, ...],
[0.014439012855291367, -0.05365084111690521, -0.019395021721720695, ...],
[0.048720553517341614, -0.05633316561579704, -0.00036325387191027403, ...],
[0.011985979974269867, -0.10603463649749756, -0.021402806043624878, ...],
[0-0.004056323319673538, -0.029253670945763588, 0.0067815352231264114, ...],
[0.00726663414388895, -0.0137932812795043, -0.015689561143517494, ...]
]
Deprecated Functions
The following functions are deprecated and will be removed in the future.
Parameters
- text - A single document/query as a string, such as
"I like cats"
. - model - Name of the model. Options:
voyage-01
(default),voyage-lite-01
. - input_type - Type of the input text. Defalut to
None
, meaning the type is unspecified. Other options:query
,document
.
Returns
- An embedding vector (a list of floating-point numbers) for the document.
get_embeddings(list_of_text, model="voyage-01", input_type=None)
Parameters
- list_of_text - A list of documents as a list of strings, such as
["I like cats", "I also like dogs"]
. The maximum length of the list is 64. - model - Name of the model. Options:
voyage-01
(default),voyage-lite-01
. - input_type - Type of the input text. Defalut to
None
, meaning the type is unspecified. Other options:query
,document
.
Returns
- A list of embedding vectors.
REST API
Voyage text embeddings can be accessed by calling the endpoint POST https://api.voyageai.com/v1/embeddings
. Please refer to the Embeddings API Reference for the specification.
Example
curl https://api.voyageai.com/v1/embeddings \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $VOYAGE_API_KEY" \
-d '{
"input": "Sample text",
"model": "voyage-3",
"input_type": "document"
}'
curl https://api.voyageai.com/v1/embeddings \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $VOYAGE_API_KEY" \
-d '{
"input": ["Sample text 1", "Sample text 2"],
"model": "voyage-3",
"input_type": "document"
}'
TypeScript Library
Voyage text embeddings are accessible in TypeScript through the Voyage TypeScript Library, which exposes all the functionality of our text embeddings endpoint (see Embeddings API Reference).
Updated 5 days ago