Cohere Embedder
The CohereEmbedder class is used to embed text data into vectors using the Cohere API. You can get started with Cohere from here
Get your key from here.
Usage
1from kern.knowledge.knowledge import Knowledge2from kern.vectordb.pgvector import PgVector3from kern.knowledge.embedder.cohere import CohereEmbedder45# Add embedding to database6embeddings = CohereEmbedder(id="embed-english-v3.0").get_embedding("The quick brown fox jumps over the lazy dog.")7# Print the embeddings and their dimensions8print(f"Embeddings: {embeddings[:5]}")9print(f"Dimensions: {len(embeddings)}")1011# Use an embedder in a knowledge base12knowledge = Knowledge(13 vector_db=PgVector(14 db_url="postgresql+psycopg://ai:ai@localhost:5532/ai",15 table_name="cohere_embeddings",16 embedder=CohereEmbedder(id="embed-english-v3.0"),17 ),18 max_results=2,19)Params
| Parameter | Type | Default | Description |
|---|---|---|---|
model | str | "embed-english-v3.0" | The name of the model used for generating embeddings. |
input_type | str | search_query | The type of input to embed. You can find more details here |
embedding_types | Optional[List[str]] | - | The type of embeddings to generate. Optional. |
api_key | str | - | The Cohere API key used for authenticating requests. |
request_params | Optional[Dict[str, Any]] | - | Additional parameters to include in the API request. Optional. |
client_params | Optional[Dict[str, Any]] | - | Additional parameters for configuring the API client. Optional. |
cohere_client | Optional[CohereClient] | - | An instance of the CohereClient 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