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

# Code reranking/semantic search

> Uses Relace's code reranking model to find the most relevant files for a given query. This is useful as a first pass in agentic exploration to narrow down the search space.

Based on: https://docs.relace.ai/docs/code-reranker/agent

Query Construction: The query can be a short question or a more detailed conversation with the user request included. For a first pass, use the full conversation; for subsequent calls, use more targeted questions.

Token Limit and Score Threshold: For 200k token context models like Claude 4 Sonnet, recommended defaults are scoreThreshold=0.5 and tokenLimit=30000.

The response will be a list of file paths and contents ordered from most relevant to least relevant.



## OpenAPI

````yaml /reference/sandbox-api/openapi.json get /codegen/reranking/{path}
openapi: 3.0.0
info:
  description: API for manipulating filesystem, processes and network.
  title: Sandbox API
  contact: {}
  version: 0.0.1
servers:
  - url: https://{sandbox_host}
    description: >-
      Host from the sandbox's returned url, without the scheme or trailing
      slash.
    variables:
      sandbox_host:
        default: sandbox.example.com
security:
  - BearerAuth: []
paths:
  /codegen/reranking/{path}:
    get:
      tags:
        - codegen
      summary: Code reranking/semantic search
      description: >-
        Uses Relace's code reranking model to find the most relevant files for a
        given query. This is useful as a first pass in agentic exploration to
        narrow down the search space.


        Based on: https://docs.relace.ai/docs/code-reranker/agent


        Query Construction: The query can be a short question or a more detailed
        conversation with the user request included. For a first pass, use the
        full conversation; for subsequent calls, use more targeted questions.


        Token Limit and Score Threshold: For 200k token context models like
        Claude 4 Sonnet, recommended defaults are scoreThreshold=0.5 and
        tokenLimit=30000.


        The response will be a list of file paths and contents ordered from most
        relevant to least relevant.
      parameters:
        - description: Path to search in (relative to workspace)
          name: path
          in: path
          required: true
          schema:
            type: string
        - description: Natural language query to search for
          name: query
          in: query
          required: true
          schema:
            type: string
        - description: 'Minimum relevance score (default: 0.5)'
          name: scoreThreshold
          in: query
          schema:
            type: number
        - description: 'Maximum tokens to return (default: 30000)'
          name: tokenLimit
          in: query
          schema:
            type: integer
        - description: Regex pattern to filter files (e.g., .*\\.ts$ for TypeScript files)
          name: filePattern
          in: query
          schema:
            type: string
      responses:
        '200':
          description: Relevant files found
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/RerankingResponse'
        '400':
          description: Invalid request
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '422':
          description: Unprocessable entity - failed to process the request
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '503':
          description: Service unavailable - Relace not configured
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
components:
  schemas:
    RerankingResponse:
      type: object
      properties:
        files:
          type: array
          items:
            $ref: '#/components/schemas/RankedFile'
        message:
          type: string
          example: Found 5 relevant files
        success:
          type: boolean
          example: true
    ErrorResponse:
      type: object
      required:
        - error
      properties:
        error:
          type: string
          example: Error message
    RankedFile:
      type: object
      properties:
        content:
          type: string
        path:
          type: string
        score:
          type: number
  securitySchemes:
    BearerAuth:
      type: http
      scheme: bearer
      description: Sandbox access token created through POST /v1/token.

````