|
| 1 | +// Copyright Envoy AI Gateway Authors |
| 2 | +// SPDX-License-Identifier: Apache-2.0 |
| 3 | +// The full text of the Apache license is available in the LICENSE file at |
| 4 | +// the root of the repo. |
| 5 | + |
| 6 | +// Package cohere contains Cohere API schema definitions. |
| 7 | +package cohere |
| 8 | + |
| 9 | +// RerankV2Request represents the request body for Cohere Rerank API v2. |
| 10 | +// Docs: https://docs.cohere.com/reference/rerank |
| 11 | +type RerankV2Request struct { |
| 12 | + // Model identifier to use, e.g. "rerank-v3.5". |
| 13 | + Model string `json:"model"` |
| 14 | + // Query to rank documents against. |
| 15 | + Query string `json:"query"` |
| 16 | + // Documents to be compared with the query. For best performance, keep under 1000. |
| 17 | + // Long documents may be truncated server-side by max_tokens_per_doc. |
| 18 | + Documents []string `json:"documents"` |
| 19 | + // Optional: limit returned results to top_n. |
| 20 | + TopN *int `json:"top_n,omitempty"` |
| 21 | + // Optional: truncate long documents to this many tokens. Default: 4096. |
| 22 | + MaxTokensPerDoc *int `json:"max_tokens_per_doc,omitempty"` |
| 23 | +} |
| 24 | + |
| 25 | +// RerankV2Response represents the response from Cohere Rerank API v2. |
| 26 | +// Docs: https://docs.cohere.com/reference/rerank |
| 27 | +type RerankV2Response struct { |
| 28 | + // Ordered list of ranked documents with scores. |
| 29 | + Results []*RerankV2Result `json:"results"` |
| 30 | + // Unique request ID. |
| 31 | + ID *string `json:"id,omitempty"` |
| 32 | + // Additional metadata including API version and billing. |
| 33 | + Meta *RerankV2Meta `json:"meta,omitempty"` |
| 34 | +} |
| 35 | + |
| 36 | +// RerankV2Result is a single ranked item in the response. |
| 37 | +type RerankV2Result struct { |
| 38 | + // Index is the position of the matched item in the input documents slice. |
| 39 | + Index int `json:"index"` |
| 40 | + // RelevanceScore is the model-assigned score indicating how well the |
| 41 | + // document matches the query (higher means more relevant). |
| 42 | + RelevanceScore float64 `json:"relevance_score"` |
| 43 | +} |
| 44 | + |
| 45 | +// RerankV2Meta contains metadata returned by the API. |
| 46 | +type RerankV2Meta struct { |
| 47 | + // APIVersion contains the version information for the API that processed the request. |
| 48 | + APIVersion *RerankV2APIVersion `json:"api_version,omitempty"` |
| 49 | + // BilledUnits reports the billed resource usage for this request. |
| 50 | + BilledUnits *RerankV2BilledUnits `json:"billed_units,omitempty"` |
| 51 | + // Tokens provides the token usage breakdown for the request/response. |
| 52 | + Tokens *RerankV2Tokens `json:"tokens,omitempty"` |
| 53 | + // CachedTokens is the number of prompt tokens that hit the inference cache. |
| 54 | + CachedTokens *float64 `json:"cached_tokens,omitempty"` |
| 55 | + // Warnings contains any non-fatal warnings generated while processing the request. |
| 56 | + Warnings []string `json:"warnings,omitempty"` |
| 57 | +} |
| 58 | + |
| 59 | +// RerankV2APIVersion describes the API version details in the response meta. |
| 60 | +type RerankV2APIVersion struct { |
| 61 | + // Version is the API version string (e.g., "2"). |
| 62 | + Version string `json:"version"` |
| 63 | + // IsDeprecated indicates whether this API version is deprecated (nullable). |
| 64 | + IsDeprecated *bool `json:"is_deprecated,omitempty"` |
| 65 | + // IsExperimental indicates whether this API version is experimental (nullable). |
| 66 | + IsExperimental *bool `json:"is_experimental,omitempty"` |
| 67 | +} |
| 68 | + |
| 69 | +// RerankV2BilledUnits contains usage metrics related to the request. |
| 70 | +type RerankV2BilledUnits struct { |
| 71 | + // Images is the number of billed images (nullable). |
| 72 | + Images *float64 `json:"images,omitempty"` |
| 73 | + // InputTokens is the number of billed input tokens (nullable). |
| 74 | + InputTokens *float64 `json:"input_tokens,omitempty"` |
| 75 | + // OutputTokens is the number of billed output tokens (nullable). |
| 76 | + OutputTokens *float64 `json:"output_tokens,omitempty"` |
| 77 | + // SearchUnits is the number of billed search units (nullable). |
| 78 | + SearchUnits *float64 `json:"search_units,omitempty"` |
| 79 | + // Classifications is the number of billed classification units (nullable). |
| 80 | + Classifications *float64 `json:"classifications,omitempty"` |
| 81 | +} |
| 82 | + |
| 83 | +// RerankV2Tokens captures token accounting for the request. |
| 84 | +// Docs: https://docs.cohere.com/reference/rerank#response.body.meta.tokens |
| 85 | +type RerankV2Tokens struct { |
| 86 | + // InputTokens is the number of tokens used as input to the model (nullable). |
| 87 | + InputTokens *float64 `json:"input_tokens,omitempty"` |
| 88 | + // OutputTokens is the number of tokens produced by the model (nullable). |
| 89 | + OutputTokens *float64 `json:"output_tokens,omitempty"` |
| 90 | +} |
| 91 | + |
| 92 | +// RerankV2Error describes a Cohere v2 error. |
| 93 | +type RerankV2Error struct { |
| 94 | + // ID is a unique identifier for the error (nullable). |
| 95 | + ID *string `json:"id,omitempty"` |
| 96 | + // Message is a human-readable description of the error (nullable). |
| 97 | + Message *string `json:"message,omitempty"` |
| 98 | +} |
0 commit comments