> ## Documentation Index
> Fetch the complete documentation index at: https://docs.lambdadb.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Query a collection

> Search a collection with a query and return the most similar documents. Optionally rerank globally merged candidates with a model provided by LambdaDB before the final size limit. Rerank is configured per query; omitted/null preserves existing behavior. See the Native reranking guide for candidate depth, score meaning, and failure policy.

For query-level reranking, see [Native reranking](https://docs.lambdadb.ai/guides/search/native-reranking.md) for default and custom criteria, candidate depth, final scores, and fallback behavior. LambdaDB manages provider credentials.


## OpenAPI

````yaml post /collections/{collectionName}/query
openapi: 3.1.1
info:
  title: LambdaDB API
  summary: LambdaDB Open API Spec
  version: 1.1.1
servers:
  - url: https://{projectHost}
    description: LambdaDB API endpoints
    variables:
      projectHost:
        description: The project-scoped URL of the API
        default: api.lambdadb.ai/projects/example-project
security: []
tags:
  - name: collections
    description: Create, describe, configure, list, and delete collections.
  - name: versioning
    description: Manage branches, tags, and aliases within a collection.
  - name: collections.docs
    description: Write, fetch, list, and bulk upload documents.
paths:
  /collections/{collectionName}/query:
    post:
      tags:
        - collections
      summary: Query a Collection
      description: >-
        Search a collection with a query and return the most similar documents.
        Optionally rerank globally merged candidates with a model provided by
        LambdaDB before the final size limit. Rerank is configured per query;
        omitted/null preserves existing behavior. See the Native reranking guide
        for candidate depth, score meaning, and failure policy.
      operationId: queryCollection
      parameters:
        - $ref: '#/components/parameters/CollectionName'
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                size:
                  type:
                    - integer
                    - 'null'
                  minimum: 0
                  maximum: 1000
                  default: 10
                  description: >-
                    Number of documents to return, from 0 to 1000. Defaults to
                    10 when omitted or null. Zero requires at least one facet;
                    facet counts cover all matching documents regardless of this
                    size. Rerank requires a positive size; this remains the
                    final returned-document limit, distinct from candidateSize
                    and each knn.k.
                query:
                  type:
                    - object
                    - 'null'
                  additionalProperties: true
                  description: >-
                    Query object. For native embedding vector fields, use
                    knn.queryText or ordered knn.queryInputs parts with explicit
                    type (text or image) and string value. Cohere accepts mixed
                    parts, OpenAI one text part. A raw knn.queryVector is also
                    accepted for native fields and skips inference. Each knn
                    query requires exactly one non-null queryText, queryInputs
                    or queryVector and has its own k from 1 to 1000, independent
                    of size and candidateSize. Text and multimodal inputs
                    require a native embedding vector field. queryInputs uses
                    the same part, image and byte limits as document inputs. All
                    automatic query inputs are prepared before the first
                    provider call; Cohere preparation checks inference quota
                    before retrieving images. Query structure and per-leg bounds
                    are validated by the server. Omit or use null to match all
                    documents. Facets support queryString and bool queries only;
                    vector, sparse vector, and hybrid queries cannot be combined
                    with facets. Bayesian fusion uses a top-level bayesian array
                    of exactly two unboosted subqueries, with no nested fusion
                    or boosts on Boolean descendants. See the Hybrid query guide
                    for candidate budgets.
                consistentRead:
                  $ref: '#/components/schemas/ConsistentRead'
                includeVectors:
                  $ref: '#/components/schemas/IncludeVectors'
                sort:
                  type:
                    - array
                    - 'null'
                  description: >-
                    List of field name, sort direction pairs. Omitted or null
                    means no explicit sort. A non-null sort list, including an
                    empty list, cannot be combined with rerank.
                  items:
                    type: object
                    additionalProperties: true
                fields:
                  $ref: '#/components/schemas/FieldsSelector'
                partitionFilter:
                  $ref: '#/components/schemas/PartitionFilter'
                ref:
                  $ref: '#/components/schemas/RefContext'
                facets:
                  type:
                    - object
                    - 'null'
                  maxProperties: 5
                  propertyNames:
                    type: string
                    pattern: .*\S.*
                  additionalProperties:
                    $ref: '#/components/schemas/FacetRequest'
                  description: >-
                    Exact document counts by indexed keyword value. Keys are
                    keyword field names, including dotted paths. Applies all
                    query and partition filters and the selected ref. At most
                    10,000 distinct (field, value) buckets and 262,144 UTF-8
                    value bytes across requested fields; exceeding either bound
                    returns 400 instead of partial counts. Separate memory
                    admission limits return 400 when one request exceeds its
                    estimated budget, or 429 when concurrent requests
                    temporarily exhaust a budget. Request fewer fields or
                    partitions for memory-limit errors; retry temporary 429
                    errors with backoff.
                rerank:
                  $ref: '#/components/schemas/RerankConfig'
                candidateSize:
                  type:
                    - integer
                    - 'null'
                  minimum: 1
                  maximum: 1000
                  description: >-
                    Required for top-level Bayesian fusion without rerank: 1 <=
                    size <= candidateSize <= 1000. Controls retrieval and
                    calibration depth per signal, independently of final size
                    and each knn.k. With rerank, omit this field and use
                    rerank.candidateSize. Other query types must omit it. Null
                    is treated as omitted; query semantics and the cross-field
                    size bound are validated by the server.
              additionalProperties: false
              if:
                required:
                  - consistentRead
                properties:
                  consistentRead:
                    const: true
              then:
                properties:
                  ref:
                    properties:
                      kind:
                        enum:
                          - branch
                          - alias
              allOf:
                - if:
                    required:
                      - size
                    properties:
                      size:
                        const: 0
                  then:
                    required:
                      - facets
                    properties:
                      facets:
                        type: object
                        minProperties: 1
                - if:
                    required:
                      - rerank
                    properties:
                      rerank:
                        type: object
                  then:
                    required:
                      - query
                    properties:
                      size:
                        type:
                          - integer
                          - 'null'
                        minimum: 1
                      query:
                        type: object
                        description: >-
                          Must contain a scoring retrieval query; filter-only
                          queries are rejected by the server.
                      sort:
                        type: 'null'
                      candidateSize:
                        type: 'null'
            examples:
              example:
                summary: Example request body for query collection
                value:
                  size: 2
                  query:
                    queryString:
                      query: example-field1:example-value
              nativeEmbeddingKnnQuery:
                summary: Example request body for native embedding KNN query
                value:
                  size: 10
                  query:
                    knn:
                      field: bodyEmbedding
                      queryText: refund policy
                      k: 10
              keywordFacets:
                summary: Keyword facets without document hits
                value:
                  size: 0
                  facets:
                    tags:
                      size: 10
              nativeReranking:
                summary: >-
                  Native reranking with default criteria and
                  candidateSize=max(50, size)
                value:
                  size: 2
                  query:
                    queryString:
                      query: restore collection
                      defaultField: body
                  fields:
                    include:
                      - id
                      - title
                  rerank:
                    provider: typesafe
                    model: jev-1.13.0
                    queryText: How do I restore a previous collection version?
                    fields:
                      - title
                      - body
              customReranking:
                summary: Native reranking with three ordered custom descriptions
                value:
                  size: 2
                  query:
                    queryString:
                      query: restore collection
                      defaultField: body
                  fields:
                    include:
                      - id
                      - title
                  rerank:
                    provider: typesafe
                    model: jev-1.13.0
                    queryText: How do I restore a previous collection version?
                    fields:
                      - title
                      - body
                    criteria:
                      - Does not explain how to restore a collection version.
                      - >-
                        Explains part of the restore process but leaves
                        essential steps unclear.
                      - >-
                        Provides the steps needed to restore the requested
                        collection version.
              bayesianHybrid:
                summary: Bayesian hybrid search with an explicit candidate budget
                value:
                  size: 10
                  candidateSize: 30
                  query:
                    bayesian:
                      - queryString:
                          query: refund policy
                          defaultField: body
                      - knn:
                          field: bodyEmbedding
                          queryText: What is the refund policy?
                          k: 30
              bayesianReranking:
                summary: Bayesian fusion followed by native reranking
                value:
                  size: 10
                  query:
                    bayesian:
                      - queryString:
                          query: refund policy
                          defaultField: body
                      - knn:
                          field: bodyEmbedding
                          queryText: What is the refund policy?
                          k: 30
                  rerank:
                    provider: typesafe
                    model: jev-1.13.0
                    queryText: What is the refund policy?
                    fields:
                      - body
                    candidateSize: 30
              cohereMultimodalKnnQuery:
                summary: Mixed text and image retrieval on a Cohere native vector field
                value:
                  query:
                    knn:
                      field: embedding
                      queryInputs:
                        - type: text
                          value: red shoes
                        - type: image
                          value: https://example.com/shoe.png
                      k: 10
                  size: 10
      responses:
        '200':
          description: Documents selected by query.
          content:
            application/json:
              schema:
                type: object
                properties:
                  took:
                    type: integer
                    description: >-
                      Complete request elapsed time in milliseconds, including
                      reranking when requested.
                  maxScore:
                    type: number
                    description: >-
                      Maximum final score among returned documents. Applied
                      reranking uses the final evaluation scores; fallback keeps
                      search scores. Omitted for empty results or when no score
                      is computed. Numeric zero is a valid maximum.
                  total:
                    type: integer
                    description: Total number of documents returned.
                  docs:
                    type: array
                    description: List of documents.
                    items:
                      type: object
                      properties:
                        collection:
                          type: string
                          description: Collection name.
                        score:
                          type: number
                          description: >-
                            Final sorting score. Applied reranking returns a
                            double-precision evaluation score in [0,1], not a
                            relevance probability. Without reranking or on
                            fallback, this remains the original retrieval/fusion
                            score and is not constrained to [0,1]. Omitted when
                            the query does not compute a score. Numeric zero is
                            valid; retain precision.
                        doc:
                          type: object
                          additionalProperties: true
                        retrievalScore:
                          type: number
                          description: >-
                            Original retrieval/fusion score, present only when
                            reranking was applied. A sibling of score and doc,
                            not a field inside doc. Omitted when reranking is
                            not requested, is skipped, or falls back; preserve
                            original precision.
                      required:
                        - collection
                        - doc
                  isDocsInline:
                    type: boolean
                    description: >-
                      Whether docs are included inline. When false, docs is
                      empty and the result items must be downloaded from
                      docsUrl.
                  docsUrl:
                    type: string
                    description: >-
                      Presigned download URL when isDocsInline is false. GET the
                      complete URL without forwarding the LambdaDB API key.
                      Returns a JSON array of result items, not an object with a
                      docs field. Applied reranking preserves score and
                      retrievalScore in each downloaded envelope; rerank
                      metadata stays in the top-level response.
                  facets:
                    type: object
                    additionalProperties:
                      $ref: '#/components/schemas/FacetResult'
                    description: >-
                      Present when facets were requested, including empty
                      buckets for fields without matching values. Remains inline
                      when documents are served through docsUrl. total remains
                      the number of returned documents, not the facet
                      population.
                  rerank:
                    $ref: '#/components/schemas/RerankResponse'
                required:
                  - took
                  - total
                  - docs
                  - isDocsInline
                allOf:
                  - if:
                      required:
                        - rerank
                      properties:
                        rerank:
                          required:
                            - status
                          properties:
                            status:
                              const: applied
                    then:
                      properties:
                        maxScore:
                          minimum: 0
                          maximum: 1
                        docs:
                          items:
                            required:
                              - score
                              - retrievalScore
                            properties:
                              score:
                                minimum: 0
                                maximum: 1
                  - if:
                      required:
                        - rerank
                      properties:
                        rerank:
                          required:
                            - status
                          properties:
                            status:
                              enum:
                                - skipped
                                - fallback
                    then:
                      properties:
                        docs:
                          items:
                            not:
                              required:
                                - retrievalScore
              examples:
                example:
                  summary: Example response for documents query
                  value:
                    took: 10
                    maxScore: 1
                    total: 2
                    docs:
                      - collection: example-collection-name
                        score: 1
                        doc:
                          example-field1: example-value1
                          example-field2:
                            - 0.1
                            - 0.2
                            - 0.3
                      - collection: example-collection-name
                        score: 0.9
                        doc:
                          example-field1: example-value2
                          example-field2:
                            - 0.4
                            - 0.5
                            - 0.6
                    isDocsInline: true
                nativeReranking:
                  summary: Applied reranking preserves original search scores
                  value:
                    took: 195
                    maxScore: 0.80000002
                    total: 2
                    docs:
                      - collection: articles
                        score: 0.80000002
                        retrievalScore: 3.2
                        doc:
                          id: restore-guide
                          title: Restore a collection version
                      - collection: articles
                        score: 0.3
                        retrievalScore: 4.1
                        doc:
                          id: overview
                          title: Collection overview
                    isDocsInline: true
                    rerank:
                      status: applied
                      provider: typesafe
                      model: jev-1.13.0
                      candidateCount: 2
                      scoredCount: 2
                      took: 180
                      criteriaVersion: default-relevance-v1
                customReranking:
                  summary: Custom evaluation includes a valid zero score
                  value:
                    took: 195
                    maxScore: 1
                    total: 2
                    docs:
                      - collection: articles
                        score: 1
                        retrievalScore: 3.2
                        doc:
                          id: restore-guide
                          title: Restore a collection version
                      - collection: articles
                        score: 0
                        retrievalScore: 4.1
                        doc:
                          id: overview
                          title: Collection overview
                    isDocsInline: true
                    rerank:
                      status: applied
                      provider: typesafe
                      model: jev-1.13.0
                      candidateCount: 2
                      scoredCount: 2
                      took: 180
                      criteriaVersion: custom
                emptyReranking:
                  summary: No candidates; provider not called
                  value:
                    took: 3
                    total: 0
                    docs: []
                    isDocsInline: true
                    rerank:
                      status: skipped
                      provider: typesafe
                      model: jev-1.13.0
                      candidateCount: 0
                      scoredCount: 0
                      took: 0
                      reason: noCandidates
                rerankFallback:
                  summary: Whole-stage timeout fallback with unchanged search scores
                  value:
                    took: 2010
                    maxScore: 4.1
                    total: 2
                    docs:
                      - collection: articles
                        score: 4.1
                        doc:
                          id: overview
                          title: Collection overview
                      - collection: articles
                        score: 3.2
                        doc:
                          id: restore-guide
                          title: Restore a collection version
                    isDocsInline: true
                    rerank:
                      status: fallback
                      provider: typesafe
                      model: jev-1.13.0
                      candidateCount: 2
                      scoredCount: 0
                      took: 2000
                      reason: timeout
        '400':
          description: >-
            Bad request, including invalid rerank provider/model, fields,
            criteria, size/candidateSize, sort combination, or
            query-less/filter-only reranking. Validation and disabled-model
            errors do not use returnOriginal.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/BadRequest'
              examples:
                example:
                  summary: Example response for bad request
                  value:
                    message: Invalid request
        '401':
          description: Unauthenticated
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Unauthenticated'
              examples:
                example:
                  summary: Example response for authentication failure
                  value:
                    message: Authentication failed
        '403':
          description: >-
            Project inference quota exceeded. Rerank returnOriginal does not
            bypass inference quota errors.
          content:
            application/json:
              schema:
                type: object
                properties:
                  message:
                    type: string
                required:
                  - message
        '404':
          description: Resource not found
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ResourceNotFound'
              examples:
                example:
                  summary: Example response for resource not found
                  value:
                    message: Resource not found
        '408':
          description: >-
            Rerank provider timeout with the default error policy. No partial
            results are returned. Overall query deadline and cancellation are
            separate errors, not fallback opportunities.
          content:
            application/json:
              schema:
                type: object
                properties:
                  message:
                    type: string
                required:
                  - message
        '413':
          $ref: '#/components/responses/PayloadTooLarge'
        '429':
          description: >-
            Too many requests, the pending-write payload exceeds the
            consistent-read limit, or concurrent facet requests temporarily
            exhaust a memory budget. Rerank provider-call admission limits also
            return 429 and do not use returnOriginal.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/TooManyRequests'
              examples:
                example:
                  summary: Example response for too many requests
                  value:
                    message: Too many requests
          headers:
            Retry-After:
              description: >-
                Optional retry delay in seconds. Not present on every 429
                response.
              schema:
                type: string
        '500':
          description: Internal server error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/InternalServerError'
              examples:
                example:
                  summary: Example response for internal server error
                  value:
                    message: Internal server error
        '502':
          $ref: '#/components/responses/BadGateway'
        '503':
          $ref: '#/components/responses/ServiceUnavailable'
        '504':
          $ref: '#/components/responses/GatewayTimeout'
      security:
        - ProjectApiKey: []
components:
  parameters:
    CollectionName:
      in: path
      name: collectionName
      description: Collection name.
      required: true
      schema:
        type: string
  schemas:
    ConsistentRead:
      title: ConsistentRead
      type: boolean
      default: false
      description: >-
        Overlay eligible pending writes on the selected branch's committed data.
        Defaults to false. Allowed when ref selects a branch directly or an
        alias that currently targets a branch; the alias is resolved to its
        branch when the request is admitted. Tag reads and an alias that targets
        a tag reject true with 400. Pending bulk imports are excluded. Returns
        429 if the pending payload exceeds the consistent-read limit.
    IncludeVectors:
      title: IncludeVectors
      type: boolean
      default: false
      description: >-
        If your application need to include vector values in the response, set
        includeVectors to true.
    FieldsSelector:
      type: object
      description: >-
        An object to specify a list of field names to include and/or exclude in
        the result.
      properties:
        include:
          type: array
          description: List of field names to include in the result.
          items:
            type: string
        exclude:
          type: array
          description: List of field names to exclude in the result.
          items:
            type: string
      anyOf:
        - required:
            - include
        - required:
            - exclude
    PartitionFilter:
      title: PartitionFilter
      type: object
      properties:
        field:
          type: string
          description: Partition field name.
        in:
          type: array
          description: Partition values to filter.
          items:
            type: string
      required:
        - field
        - in
    RefContext:
      title: RefContext
      type: object
      description: >-
        Read ref selector. A ref that does not exist returns 404
        ResourceNotFound; an alias whose target is dangling returns 400
        BadRequest.
      additionalProperties: false
      properties:
        kind:
          type: string
          enum:
            - branch
            - tag
            - alias
        name:
          type: string
          minLength: 3
          maxLength: 52
          pattern: ^[a-zA-Z0-9_-]{3,52}$
      required:
        - kind
        - name
    FacetRequest:
      type: object
      additionalProperties: false
      properties:
        size:
          type:
            - integer
            - 'null'
          minimum: 1
          maximum: 100
          default: 10
          description: >-
            Maximum buckets to return after global aggregation. Defaults to 10
            when omitted or null.
    RerankConfig:
      type:
        - object
        - 'null'
      description: >-
        Optional native reranking for this query, not a collection setting.
        Omitted or null preserves existing search behavior. LambdaDB manages
        provider credentials; no provider API key is supplied by the caller.
        Request validation, field types, UTF-8 byte limits, and size <=
        candidateSize are checked by the server.
      properties:
        provider:
          type: string
          enum:
            - typesafe
            - cohere
          description: Required native reranking provider.
        model:
          type: string
          enum:
            - jev-1.13.0
            - rerank-v5.0-pro
            - rerank-v5.0-fast
          description: >-
            Required reranking model; independent of the collection embedding
            model.
        queryText:
          type: string
          minLength: 1
          pattern: .*\S.*
          description: >-
            Required nonblank evaluation query, including for raw-vector or
            hybrid retrieval. At most 8 KiB UTF-8; never inferred from retrieval
            legs.
        fields:
          type: array
          minItems: 1
          maxItems: 8
          uniqueItems: true
          items:
            type: string
            minLength: 1
            pattern: .*\S.*
          description: >-
            Ordered, unique stored scalar string paths, using dotted paths for
            nested fields. Paths do not need index configs. If configured,
            leaves must be text or keyword and configured ancestors must be
            objects. Empty or blank path segments are invalid; arrays, objects,
            and non-string values are invalid, including on unindexed stored
            paths. Values are checked before provider dispatch. Missing/null
            values are skipped, but every candidate must have at least one
            nonblank selected value. Only these fields enter model input;
            top-level fields controls the response projection. Rendered
            candidate text is limited to 16 KiB UTF-8, and query plus all
            rendered candidates plus custom criteria to 256 KiB.
        candidateSize:
          type:
            - integer
            - 'null'
          minimum: 1
          maximum: 1000
          description: >-
            Upper bound on the globally merged and deduplicated rerank pool.
            Omitted or null defaults to max(50, size). Must satisfy size <=
            candidateSize <= 1000. Does not modify any knn.k and does not
            guarantee this many candidates.
        onFailure:
          type:
            - string
            - 'null'
          enum:
            - error
            - returnOriginal
            - null
          default: error
          description: >-
            Omitted or null uses error. Provider timeout, rate limit,
            unavailable service, credential rejection, or invalid/incomplete
            scores follow this policy for the whole stage. returnOriginal keeps
            pre-rerank candidate order and search scores. Input/configuration,
            retrieval/hydration, authorization, quota, admission, and overall
            cancellation/deadline errors do not become fallback results.
        criteria:
          type:
            - array
            - 'null'
          minItems: 2
          maxItems: 10
          uniqueItems: true
          items:
            type: string
            minLength: 1
            pattern: .*\S.*
          description: >-
            TypeSafe/Jev only; Cohere requires omitted or null criteria.
            Distinct nonblank descriptions ordered from lowest to highest
            relevance. Omitted/null uses default-relevance-v1. Each description
            is limited to 2 KiB and the full list to 8 KiB UTF-8. Text is
            preserved exactly. Custom levels use uniformly spaced scores from 0
            to 1; explicitly sending the default descriptions still selects
            custom scoring. Weights and thresholds are not supported.
      required:
        - provider
        - model
        - queryText
        - fields
      additionalProperties: false
      allOf:
        - if:
            properties:
              provider:
                const: cohere
          then:
            properties:
              model:
                enum:
                  - rerank-v5.0-pro
                  - rerank-v5.0-fast
              criteria:
                type: 'null'
        - if:
            properties:
              provider:
                const: typesafe
          then:
            properties:
              model:
                const: jev-1.13.0
    FacetResult:
      type: object
      required:
        - buckets
      properties:
        buckets:
          type: array
          description: >-
            Ordered by count descending, then keyword Unicode code point order
            ascending. A document contributes once per distinct indexed value.
            Missing or unindexed values have no bucket.
          items:
            type: object
            required:
              - value
              - count
            properties:
              value:
                type: string
              count:
                type: integer
                format: int64
                minimum: 1
    RerankResponse:
      type: object
      description: >-
        Present only when rerank was requested. Whole-stage metadata remains
        inline even when documents are downloaded through docsUrl.
      properties:
        status:
          type: string
          enum:
            - applied
            - skipped
            - fallback
        provider:
          type: string
          enum:
            - typesafe
            - cohere
          description: Requested provider.
        model:
          type: string
          enum:
            - jev-1.13.0
            - rerank-v5.0-pro
            - rerank-v5.0-fast
          description: Requested model.
        resolvedModel:
          type: string
          description: >-
            Resolved model identity, when reported by the provider. Omitted
            otherwise.
        candidateCount:
          type: integer
          minimum: 0
          maximum: 1000
          description: >-
            Actual unique candidates in the rerank stage before final size
            limiting, not the returned-document count.
        scoredCount:
          type: integer
          minimum: 0
          maximum: 1000
          description: >-
            Equals candidateCount on applied results; zero for skipped/fallback.
            Partial scores are never exposed.
        took:
          type: integer
          minimum: 0
          description: >-
            Rerank stage milliseconds after candidate hydration, including
            preparation and ordering or failure handling; not the complete
            request duration.
        criteriaVersion:
          type: string
          enum:
            - default-relevance-v1
            - custom
            - cohere-relevance-v1
          description: >-
            Only on applied results. TypeSafe/Jev uses default-relevance-v1 or
            custom; Cohere uses cohere-relevance-v1.
        reason:
          type: string
          enum:
            - noCandidates
            - timeout
            - rateLimit
            - unavailable
            - invalidResponse
            - credentials
          description: >-
            Only for skipped/fallback. skipped uses noCandidates; fallback uses
            a bounded provider failure reason.
      required:
        - status
        - provider
        - model
        - candidateCount
        - scoredCount
        - took
      additionalProperties: false
      allOf:
        - if:
            properties:
              status:
                const: skipped
          then:
            required:
              - reason
            properties:
              reason:
                const: noCandidates
              candidateCount:
                const: 0
              scoredCount:
                const: 0
            not:
              required:
                - criteriaVersion
        - if:
            properties:
              status:
                const: fallback
          then:
            required:
              - reason
            properties:
              reason:
                enum:
                  - timeout
                  - rateLimit
                  - unavailable
                  - invalidResponse
                  - credentials
              scoredCount:
                const: 0
            not:
              required:
                - criteriaVersion
        - if:
            properties:
              status:
                const: applied
          then:
            not:
              required:
                - reason
            properties:
              candidateCount:
                minimum: 1
              scoredCount:
                minimum: 1
        - if:
            properties:
              provider:
                const: cohere
          then:
            properties:
              model:
                enum:
                  - rerank-v5.0-pro
                  - rerank-v5.0-fast
              criteriaVersion:
                const: cohere-relevance-v1
        - if:
            properties:
              provider:
                const: typesafe
          then:
            properties:
              model:
                const: jev-1.13.0
              criteriaVersion:
                enum:
                  - default-relevance-v1
                  - custom
    BadRequest:
      title: BadRequest
      type: object
      properties:
        message:
          type: string
    Unauthenticated:
      title: Unauthenticated
      type: object
      properties:
        message:
          type: string
    ResourceNotFound:
      title: ResourceNotFound
      type: object
      properties:
        message:
          type: string
    TooManyRequests:
      title: TooManyRequests
      type: object
      properties:
        message:
          type: string
    InternalServerError:
      title: InternalServerError
      type: object
      properties:
        message:
          type: string
    MessageResponse:
      type: object
      properties:
        message:
          type: string
      required:
        - message
  responses:
    PayloadTooLarge:
      description: >-
        Request exceeds the Gateway transport limit. Reduce the request size or
        use bulk upsert when supported.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/MessageResponse'
    BadGateway:
      description: >-
        Unexpected downstream failure. A failed write response may leave its
        outcome uncertain.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/MessageResponse'
    ServiceUnavailable:
      description: >-
        Transient catalog or storage dependency failure. Use bounded retries
        where the operation permits.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/MessageResponse'
    GatewayTimeout:
      description: >-
        Gateway request deadline exceeded. A write may have been applied; verify
        its outcome before retrying.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/MessageResponse'
  securitySchemes:
    ProjectApiKey:
      type: apiKey
      in: header
      name: x-api-key
      description: Project API Key.
      x-speakeasy-example: <YOUR_PROJECT_API_KEY>

````

This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.