Voyage AI Embedder
The VoyageAIEmbedder class is used to embed text data into vectors using the Voyage AI API. Get your key from here.
Usage
1from kern.knowledge.knowledge import Knowledge2from kern.vectordb.pgvector import PgVector3from kern.knowledge.embedder.voyageai import VoyageAIEmbedder45# Embed sentence in database6embeddings = VoyageAIEmbedder().get_embedding("The quick brown fox jumps over the lazy dog.")78# Print the embeddings and their dimensions9print(f"Embeddings: {embeddings[:5]}")10print(f"Dimensions: {len(embeddings)}")1112# Use an embedder in a knowledge base13knowledge = Knowledge(14 vector_db=PgVector(15 db_url="postgresql+psycopg://ai:ai@localhost:5532/ai",16 table_name="voyageai_embeddings",17 embedder=VoyageAIEmbedder(),18 ),19 max_results=2,20)Params
| Parameter | Type | Default | Description |
|---|---|---|---|
model | str | "voyage-2" | The name of the model used for generating embeddings. |
dimensions | int | 1024 | The dimensionality of the embeddings generated by the model. |
request_params | Optional[Dict[str, Any]] | - | Additional parameters to include in the API request. Optional. |
api_key | str | - | The API key used for authenticating requests. |
base_url | str | "https://api.voyageai.com/v1/embeddings" | The base URL for the API endpoint. |
max_retries | Optional[int] | - | The maximum number of retries for API requests. Optional. |
timeout | Optional[float] | - | The timeout duration for API requests. Optional. |
client_params | Optional[Dict[str, Any]] | - | Additional parameters for configuring the API client. Optional. |
voyage_client | Optional[Client] | - | An instance of the Client to use for making API requests. Optional. |
enable_batch | bool | False | Enable batch processing to reduce API calls and avoid rate limits |
batch_size | int | 100 | Number of texts to process in each API call for batch operations. |
Developer Resources
- View Cookbook