Implementation:Cohere ai Cohere python Client Embed
| Metadata |
|---|
| Cohere Python SDK |
| Cohere Embed API |
| NLP, Embeddings, Vector_Search |
| 2026-02-15 14:00 GMT |
Overview
Concrete method for generating text embeddings with automatic batching and concurrent processing.
Description
Client.embed provides embedding generation with automatic batching. When batching is enabled (default True), texts are split into chunks of 96 (embed_batch_size from config.py), processed concurrently using ThreadPoolExecutor.map(), and results are merged via merge_embed_responses() from utils.py. Image embeddings skip batching. The method delegates to BaseCohere.embed for the actual HTTP call.
Usage
Call on a Client or ClientV2 instance. Pass texts as a list of strings, specify the input_type for the use case, and optionally select embedding_types for the output format. Batching is automatic for text inputs.
Code Reference
- Source Location: Repository cohere-ai/cohere-python https://github.com/cohere-ai/cohere-python, File src/cohere/client.py, Lines L180-224
- Signature:
def embed(
self,
*,
texts: typing.Optional[typing.Sequence[str]] = OMIT,
images: typing.Optional[typing.Sequence[str]] = OMIT,
model: typing.Optional[str] = OMIT,
input_type: typing.Optional[EmbedInputType] = OMIT,
embedding_types: typing.Optional[typing.Sequence[EmbeddingType]] = OMIT,
truncate: typing.Optional[EmbedRequestTruncate] = OMIT,
request_options: typing.Optional[RequestOptions] = None,
batching: typing.Optional[bool] = True,
) -> EmbedResponse:
- Import:
from cohere import Clientorfrom cohere import ClientV2(Client.embed for V1 batching, ClientV2 inherits)
I/O Contract
Inputs
| Parameter | Type | Required | Description |
|---|---|---|---|
| texts | Optional[Sequence[str]] | No | Text strings to embed (auto-batched at 96) |
| images | Optional[Sequence[str]] | No | Image URLs or base64 data (no batching) |
| model | Optional[str] | No | Embedding model ID e.g. "embed-english-v3.0" |
| input_type | Optional[EmbedInputType] | No | "search_document", "search_query", "classification", "clustering", "image" |
| embedding_types | Optional[Sequence[EmbeddingType]] | No | "float", "int8", "uint8", "binary", "ubinary" |
| truncate | Optional[EmbedRequestTruncate] | No | Truncation behavior |
| batching | Optional[bool] | No | Enable auto-batching (default True) |
Outputs
EmbedResponse (discriminated union):
- EmbeddingsFloatsEmbedResponse: id, embeddings (List[List[float]]), texts, meta
- EmbeddingsByTypeEmbedResponse: id, embeddings (typed), texts, meta
Usage Examples
from cohere import Client
client = Client()
# Embed documents for search indexing
doc_response = client.embed(
texts=["Machine learning is a subset of AI.", "Deep learning uses neural networks."],
model="embed-english-v3.0",
input_type="search_document",
embedding_types=["float"],
)
# Access embeddings
embeddings = doc_response.embeddings # List[List[float]]
# Embed a query
query_response = client.embed(
texts=["What is deep learning?"],
model="embed-english-v3.0",
input_type="search_query",
)
# Large-scale embedding (auto-batched at 96)
large_response = client.embed(
texts=["text " + str(i) for i in range(1000)], # Auto-splits into batches of 96
model="embed-english-v3.0",
input_type="search_document",
)