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

# Quickstart

> Retrieve only relevant files from your codebase for a user request

## Overview

Given a user request for how to change a codebase, you want to retrieve only the files relevant to implementing that request.

This is important for two reasons:

* Polluting the context window with irrelevant files makes the generated code worse.
* The fewer files you pass in, the more you save on input tokens.

We trained our reranker on hundreds of thousands of user query and code pairs to make it best in class for AI codegen applications.

## Prerequisites

* [Sign up](https://app.relace.ai) for a Relace account.
* Create an [API key](https://app.relace.ai/settings/api-keys).

<Steps>
  <Step title="Prepare Your Query and Codebase">
    Define your user request and collect the files from your codebase that need to be ranked for relevance.

    ```typescript theme={null}
    const userQuery = "Add a user profile component with avatar and edit functionality";
    const codebaseFiles = [
      { filename: "src/components/UserProfile.tsx", content: "..." },
      { filename: "src/types/user.ts", content: "..." },
      { filename: "src/components/Header.tsx", content: "..." },
      // ... more files
    ];
    ```
  </Step>

  <Step title="Call the Code Reranker API">
    Send your query and codebase to the reranker to get relevance scores for each file.

    ```typescript theme={null}
    const url = "https://ranker.endpoint.relace.run/v2/code/rank";
    const apiKey = "[YOUR_API_KEY]";

    const headers = {
      "Authorization": `Bearer ${apiKey}`,
      "Content-Type": "application/json"
    };

    const data = {
      query: userQuery,
      codebase: codebaseFiles,
      token_limit: 150000,  // Set to your model's context limit with buffer room for system prompt
    };

    const response = await fetch(url, {
      method: "POST",
      headers: headers,
      body: JSON.stringify(data)
    });

    const rankedFiles = await response.json();
    ```
  </Step>

  <Step title="Parse Ranked Results from Response">
    The API returns files ranked by relevance with scores between 0 and 1 up to the token limit you set.

    ```json theme={null}
    [
      {
        "filename": "src/components/UserProfile.tsx",
        "score": 0.9598
      },
      {
        "filename": "src/types/user.ts",
        "score": 0.0321
      },
      {
        "filename": "src/components/Header.tsx",
        "score": 0.0014
      }
    ]
    ```

    We recommend additionally filtering out results with low relevance scores. See the [agent tool definition](/docs/code-reranker/agent) or [workflow guide](/docs/code-reranker/workflow) for specific recommendations based on your system.
  </Step>
</Steps>
