Implementation:Cohere ai Cohere python EmbedResponse Model
| Metadata |
|---|
| Cohere Python SDK |
| NLP, Embeddings, Response_Parsing |
| 2026-02-15 14:00 GMT |
Overview
Concrete Pydantic models representing embedding API responses with support for multiple embedding formats.
Description
EmbedResponse is a discriminated union (on response_type field) of two response types: EmbeddingsFloatsEmbedResponse (response_type="embeddings_floats") with embeddings as List[List[float]], and EmbeddingsByTypeEmbedResponse (response_type="embeddings_by_type") with typed embeddings. Both include id, texts, and meta (ApiMeta with billed_units).
Usage
Access after calling client.embed(). The response type depends on whether embedding_types was specified.
Code Reference
- Source Location: Repository cohere-ai/cohere-python https://github.com/cohere-ai/cohere-python, File src/cohere/types/embed_response.py, Lines L1-53
- Signature:
class EmbeddingsFloatsEmbedResponse(UncheckedBaseModel):
response_type: typing.Literal["embeddings_floats"] = "embeddings_floats"
id: str
embeddings: typing.List[typing.List[float]]
texts: typing.List[str]
meta: typing.Optional[ApiMeta] = None
class EmbeddingsByTypeEmbedResponse(UncheckedBaseModel):
response_type: typing.Literal["embeddings_by_type"] = "embeddings_by_type"
id: str
embeddings: EmbedByTypeResponseEmbeddings
texts: typing.Optional[typing.List[str]] = None
meta: typing.Optional[ApiMeta] = None
EmbedResponse = Union[EmbeddingsFloatsEmbedResponse, EmbeddingsByTypeEmbedResponse]
- Import:
from cohere.types import EmbedResponse(typically accessed via client.embed() return)
I/O Contract
Inputs
Raw HTTP JSON response from Cohere API.
Outputs
| Field | Type | Description |
|---|---|---|
| response_type | str | "embeddings_floats" or "embeddings_by_type" |
| id | str | Response identifier |
| embeddings | List[List[float]] or EmbedByTypeResponseEmbeddings | Embedding vectors |
| texts | List[str] | Input texts echoed back |
| meta | Optional[ApiMeta] | Billing metadata |
Usage Examples
response = client.embed(
texts=["Hello world", "Goodbye world"],
model="embed-english-v3.0",
input_type="search_document",
)
# Float embeddings
if hasattr(response, 'embeddings'):
for i, embedding in enumerate(response.embeddings):
print(f"Text {i}: vector dim={len(embedding)}")