Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:Cohere ai Cohere python EmbedResponse Model

From Leeroopedia
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

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)}")

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment