Principle:Cohere ai Cohere python Embed Response Processing
| Metadata |
|---|
| Cohere Python SDK |
| Cohere Embed API |
| NLP, Embeddings, Response_Parsing |
| 2026-02-15 14:00 GMT |
Overview
A parsing pattern for extracting typed embedding vectors and metadata from embedding API responses.
Description
Embed Response Processing handles the structured output from embedding API calls. The response is a discriminated union: when a single default embedding type is requested, it returns EmbeddingsFloatsEmbedResponse with a simple List[List[float]] embeddings field. When multiple embedding types are requested, it returns EmbeddingsByTypeEmbedResponse with embeddings grouped by type. Both variants include id, texts, and API metadata. For batched requests, the SDK's merge_embed_responses utility transparently concatenates embeddings from multiple batch responses into a single unified response.
Usage
After calling Client.embed(), access the response's embeddings field for the vector data. If using multiple embedding_types, access the typed embeddings object. Check meta for billing information.
Theoretical Basis
The discriminated union response pattern (keyed on response_type) allows a single endpoint to serve different output formats while maintaining type safety. The merge operation for batched responses preserves the semantic invariant that embeddings[i] corresponds to texts[i].