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

# Rerank documents

> Rerank a list of documents by relevance to a query.



## OpenAPI

````yaml post /v1/inference/rerank
openapi: 3.1.0
info:
  title: SeekrFlow API
  description: SeekrFlow API Documentation
  termsOfService: http://www.seekr.com/support
  contact:
    name: Seekr API Support
    url: http://www.seekr.com/contact
    email: contact@seekr.com
  version: 5.48.1
servers:
  - url: https://flow.seekr.com
    description: SeekrBuild server base URL
security: []
paths:
  /v1/inference/rerank:
    post:
      tags:
        - Inference
      summary: Rerank documents against a query
      operationId: route_v1_rerank_v1_inference_rerank_post
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/RerankRequest'
            example:
              model: BAAI/bge-reranker-v2-m3
              query: What is the capital of France?
              documents:
                - Paris is the capital and most populous city of France.
                - Berlin is the capital of Germany.
              top_n: 2
        required: true
      responses:
        '200':
          description: Successful response.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/RerankResponse'
        '400':
          description: Malformed request body, or `model` missing.
          content:
            application/json:
              schema:
                oneOf:
                  - properties:
                      error:
                        properties:
                          message:
                            type: string
                          type:
                            type: string
                          code:
                            type: integer
                          param:
                            type: string
                            nullable: true
                        type: object
                        required:
                          - message
                    type: object
                    required:
                      - error
                    title: StructuredError
                  - properties:
                      error:
                        type: string
                    type: object
                    required:
                      - error
                    title: SimpleError
                title: ErrorResponse
        '401':
          description: Missing or invalid API key.
          content:
            application/json:
              schema:
                oneOf:
                  - properties:
                      error:
                        properties:
                          message:
                            type: string
                          type:
                            type: string
                          code:
                            type: integer
                          param:
                            type: string
                            nullable: true
                        type: object
                        required:
                          - message
                    type: object
                    required:
                      - error
                    title: StructuredError
                  - properties:
                      error:
                        type: string
                    type: object
                    required:
                      - error
                    title: SimpleError
                title: ErrorResponse
        '403':
          description: >-
            The requested model is not a base model and is not deployed for your
            team.
          content:
            application/json:
              schema:
                oneOf:
                  - properties:
                      error:
                        properties:
                          message:
                            type: string
                          type:
                            type: string
                          code:
                            type: integer
                          param:
                            type: string
                            nullable: true
                        type: object
                        required:
                          - message
                    type: object
                    required:
                      - error
                    title: StructuredError
                  - properties:
                      error:
                        type: string
                    type: object
                    required:
                      - error
                    title: SimpleError
                title: ErrorResponse
        '422':
          description: Deployment not found, or the request is unprocessable.
          content:
            application/json:
              schema:
                oneOf:
                  - properties:
                      error:
                        properties:
                          message:
                            type: string
                          type:
                            type: string
                          code:
                            type: integer
                          param:
                            type: string
                            nullable: true
                        type: object
                        required:
                          - message
                    type: object
                    required:
                      - error
                    title: StructuredError
                  - properties:
                      error:
                        type: string
                    type: object
                    required:
                      - error
                    title: SimpleError
                title: ErrorResponse
        '429':
          description: Rate limit exceeded.
          content:
            application/json:
              schema:
                oneOf:
                  - properties:
                      error:
                        properties:
                          message:
                            type: string
                          type:
                            type: string
                          code:
                            type: integer
                          param:
                            type: string
                            nullable: true
                        type: object
                        required:
                          - message
                    type: object
                    required:
                      - error
                    title: StructuredError
                  - properties:
                      error:
                        type: string
                    type: object
                    required:
                      - error
                    title: SimpleError
                title: ErrorResponse
        '502':
          description: Backend disconnected before sending a response.
          content:
            application/json:
              schema:
                oneOf:
                  - properties:
                      error:
                        properties:
                          message:
                            type: string
                          type:
                            type: string
                          code:
                            type: integer
                          param:
                            type: string
                            nullable: true
                        type: object
                        required:
                          - message
                    type: object
                    required:
                      - error
                    title: StructuredError
                  - properties:
                      error:
                        type: string
                    type: object
                    required:
                      - error
                    title: SimpleError
                title: ErrorResponse
        '503':
          description: No healthy backend available for the requested model.
          content:
            application/json:
              schema:
                oneOf:
                  - properties:
                      error:
                        properties:
                          message:
                            type: string
                          type:
                            type: string
                          code:
                            type: integer
                          param:
                            type: string
                            nullable: true
                        type: object
                        required:
                          - message
                    type: object
                    required:
                      - error
                    title: StructuredError
                  - properties:
                      error:
                        type: string
                    type: object
                    required:
                      - error
                    title: SimpleError
                title: ErrorResponse
      security:
        - APIKeyHeader: []
components:
  schemas:
    RerankRequest:
      additionalProperties: true
      properties:
        model:
          anyOf:
            - type: string
            - type: 'null'
          default: null
          title: Model
        user:
          anyOf:
            - type: string
            - type: 'null'
          default: null
          title: User
        truncate_prompt_tokens:
          anyOf:
            - minimum: -1
              type: integer
            - type: 'null'
          default: null
          title: Truncate Prompt Tokens
        truncation_side:
          anyOf:
            - enum:
                - left
                - right
              type: string
            - type: 'null'
          default: null
          description: >-
            Which side to truncate from when truncate_prompt_tokens is active.
            'right' keeps the first N tokens. 'left' keeps the last N tokens.
          title: Truncation Side
        request_id:
          anyOf:
            - type: string
            - type: 'null'
          default: null
          description: >-
            The request_id related to this request. If the caller does not set
            it, a random uuid will be generated.
          title: Request Id
        priority:
          default: 0
          description: >-
            The priority of the request (lower means earlier handling; default:
            0). Any priority other than 0 will raise an error if the served
            model does not use priority scheduling.
          title: Priority
          type: integer
        mm_processor_kwargs:
          anyOf:
            - additionalProperties: true
              type: object
            - type: 'null'
          default: null
          description: Additional kwargs to pass to the HF processor.
          title: Mm Processor Kwargs
        cache_salt:
          anyOf:
            - type: string
            - type: 'null'
          default: null
          description: >-
            If specified, the prefix cache will be salted with the provided
            string to prevent an attacker from guessing prompts in multi-user
            environments.
          title: Cache Salt
        use_activation:
          anyOf:
            - type: boolean
            - type: 'null'
          default: null
          description: >-
            Whether to use activation for the pooler outputs. null uses the
            pooler's default, which is true in most cases.
          title: Use Activation
        max_tokens_per_query:
          default: 0
          description: >-
            Maximum number of tokens per query. Queries longer than this will be
            truncated. 0 means no query-level truncation is applied.
          title: Max Tokens Per Query
          type: integer
        max_tokens_per_doc:
          default: 0
          description: >-
            Maximum number of tokens per document. Documents longer than this
            will be truncated. 0 means no document-level truncation is applied
            (only truncate_prompt_tokens applies to the combined
            query+document).
          title: Max Tokens Per Doc
          type: integer
        instruction:
          anyOf:
            - type: string
            - type: 'null'
          default: null
          description: >-
            Task instruction prepended to each scored pair via the chat
            template. Equivalent to passing chat_template_kwargs={'instruction':
            ...}.
          title: Instruction
        chat_template_kwargs:
          anyOf:
            - additionalProperties: true
              type: object
            - type: 'null'
          default: null
          description: >-
            Additional keyword args to pass to the chat template renderer. Will
            be accessible by the score/rerank chat template.
          title: Chat Template Kwargs
        query:
          anyOf:
            - type: string
            - $ref: '#/components/schemas/ScoreMultiModalParam'
          title: Query
        documents:
          anyOf:
            - type: string
            - $ref: '#/components/schemas/ScoreMultiModalParam'
            - items:
                anyOf:
                  - type: string
                  - $ref: '#/components/schemas/ScoreMultiModalParam'
              type: array
          title: Documents
        top_n:
          default: 0
          minimum: 0
          title: Top N
          type: integer
      required:
        - query
        - documents
      title: RerankRequest
      type: object
    RerankResponse:
      additionalProperties: true
      properties:
        id:
          type: string
          title: Id
        model:
          title: Model
          type: string
        usage:
          $ref: '#/components/schemas/RerankUsage'
        results:
          items:
            $ref: '#/components/schemas/RerankResult'
          title: Results
          type: array
      required:
        - id
        - model
        - usage
        - results
      title: RerankResponse
      type: object
    ScoreMultiModalParam:
      additionalProperties: true
      properties:
        content:
          items:
            anyOf:
              - $ref: '#/components/schemas/ContentPartText'
              - $ref: '#/components/schemas/ContentPartImage'
              - $ref: '#/components/schemas/ContentPartAudio'
              - $ref: '#/components/schemas/ContentPartVideo'
          title: Content
          type: array
      required:
        - content
      title: ScoreMultiModalParam
      type: object
    RerankUsage:
      properties:
        prompt_tokens:
          title: Prompt Tokens
          type: integer
        total_tokens:
          title: Total Tokens
          type: integer
      required:
        - prompt_tokens
        - total_tokens
      title: RerankUsage
      type: object
    RerankResult:
      properties:
        index:
          type: integer
          title: Index
        document:
          $ref: '#/components/schemas/RerankDocument'
        relevance_score:
          title: Relevance Score
          type: number
      required:
        - index
        - document
        - relevance_score
      title: RerankResult
      type: object
    ContentPartText:
      additionalProperties: true
      properties:
        type:
          const: text
          default: text
          title: Type
          type: string
        text:
          title: Text
          type: string
      required:
        - text
      title: ContentPartText
      type: object
    ContentPartImage:
      additionalProperties: true
      properties:
        type:
          const: image_url
          default: image_url
          title: Type
          type: string
        image_url:
          $ref: '#/components/schemas/ImageURL'
      required:
        - image_url
      title: ContentPartImage
      type: object
    ContentPartAudio:
      additionalProperties: true
      properties:
        type:
          const: input_audio
          default: input_audio
          title: Type
          type: string
        input_audio:
          $ref: '#/components/schemas/InputAudio'
      required:
        - input_audio
      title: ContentPartAudio
      type: object
    ContentPartVideo:
      additionalProperties: true
      properties:
        type:
          const: video_url
          default: video_url
          title: Type
          type: string
        video_url:
          $ref: '#/components/schemas/VideoURL'
      required:
        - video_url
      title: ContentPartVideo
      type: object
    RerankDocument:
      properties:
        text:
          anyOf:
            - type: string
            - type: 'null'
          default: null
          title: Text
        multi_modal:
          anyOf:
            - items:
                anyOf:
                  - $ref: '#/components/schemas/ContentPartText'
                  - $ref: '#/components/schemas/ContentPartImage'
                  - $ref: '#/components/schemas/ContentPartAudio'
                  - $ref: '#/components/schemas/ContentPartVideo'
              type: array
            - type: 'null'
          default: null
          title: Multi Modal
      title: RerankDocument
      type: object
    ImageURL:
      additionalProperties: true
      properties:
        url:
          description: Either an http(s) URL or a `data:image/...;base64,...` URI.
          title: Url
          type: string
        detail:
          anyOf:
            - enum:
                - auto
                - low
                - high
              type: string
            - type: 'null'
          default: auto
          title: Detail
      required:
        - url
      title: ImageURL
      type: object
    InputAudio:
      additionalProperties: true
      properties:
        data:
          description: Base64-encoded audio bytes.
          title: Data
          type: string
        format:
          anyOf:
            - type: string
            - type: 'null'
          default: null
          description: e.g. `wav`, `mp3`.
          title: Format
      required:
        - data
      title: InputAudio
      type: object
    VideoURL:
      additionalProperties: true
      properties:
        url:
          title: Url
          type: string
      required:
        - url
      title: VideoURL
      type: object
  securitySchemes:
    APIKeyHeader:
      type: apiKey
      description: >-
        Your Seekr API key, sent in the Authorization header with no 'Bearer'
        prefix.
      in: header
      name: Authorization

````

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