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

# Knowledge bases via AI Router

> Integrate knowledge bases through the AI Router. Enable RAG retrieval in LLM calls with automatic context injection for enhanced AI responses.

## Prerequisite

[Knowledge Bases](/docs/knowledge/overview) are made to provide relevant and specific information for an LLM to use. To get started, see [Creating a Knowledge Base](/docs/knowledge/overview), Knowledge Bases need to be enriched with the sources documents and configured to expose chunks fitting your use case.

<Info>
  The **name** of the Knowledge Base will be used as `knowledge_id` in the model generation.
</Info>

## Quick Start

Using the created [Knowledge Base](/docs/knowledge/overview), and its `id`, include the `knowledge_bases` payload within your model generation call.

> The knowledge\_bases payload contains query configuration and search type, to learn more, see [Search Modes](/docs/knowledge/overview#search-modes) and [Chunking Strategy](/docs/knowledge/overview#datasource-and-chunking).

<CodeGroup>
  ```bash cURL theme={"theme":{"light":"github-light","dark":"github-dark"}}
  curl -X POST https://api.orq.ai/v3/router/chat/completions \
    -H "Authorization: Bearer $ORQ_API_KEY" \
    -H "Content-Type: application/json" \
    -d '{
    "model": "openai/gpt-4o",
    "messages": [
      {
        "role": "user",
        "content": "How can I upgrade my account?"
      }
    ],
    "orq": {
      "knowledge_bases": [
        {
          "knowledge_id": "api-documentation",
          "top_k": 5,
          "threshold": 0.7,
          "search_type": "hybrid_search"
        }
      ]
    }
  }'
  ```

  ```typescript Typescript theme={"theme":{"light":"github-light","dark":"github-dark"}}
  import OpenAI from "openai";

  const openai = new OpenAI({
    apiKey: process.env.ORQ_API_KEY,
    baseURL: "https://api.orq.ai/v3/router",
  });

  const response = await openai.chat.completions.create({
    model: 'openai/gpt-4o',
    messages: [{ role: 'user', content: 'How can I upgrade my account?' }],
    orq: {
      knowledge_bases: [
        {
          knowledge_id: 'api-documentation',
          top_k: 5,
          threshold: 0.7,
          search_type: 'hybrid_search'
        }
      ]
    }
  });
  ```

  ```python Python theme={"theme":{"light":"github-light","dark":"github-dark"}}
  from openai import OpenAI
  import os

  openai = OpenAI(
      api_key=os.environ.get("ORQ_API_KEY"),
      base_url="https://api.orq.ai/v3/router"
  )

  response = openai.chat.completions.create(
      model="openai/gpt-4o",
      messages=[
          {
              "role": "user",
              "content": "How can I upgrade my account?"
          }
      ],
      extra_body={
          "orq": {
              "knowledge_bases": [
                  {
                      "knowledge_id": "api_documentation",
                      "top_k": 5,
                      "threshold": 0.7,
                      "search_type": "hybrid_search"
                  }
              ]
          }
      }
  )
  ```
</CodeGroup>

<Check>
  **Orq** will automatically enrich the model generation with the given context and query to the knowledge base
</Check>

<Frame caption="Within the Traces, you can see the knowledge retrieval step Orq.ai automatically injects into your call to enrich the model context with the linked Knowledge Base.">
  <img src="https://mintcdn.com/orqai/E8L3R46ivX7g9-QI/images/docs/9a9e1e0325d8b216f57440026d7006bfc3bf9d0da01828ebfc072b6ab97554d7-Screenshot_2025-10-13_at_22.16.38.png?fit=max&auto=format&n=E8L3R46ivX7g9-QI&q=85&s=8567abc13e87f09ac8e1e4357fd12c65" alt="Within the Traces, you can see the knowledge retrieval step Orq.ai automatically injects into your call to enrich the model context with the linked Knowledge Base." width="491" height="477" data-path="images/docs/9a9e1e0325d8b216f57440026d7006bfc3bf9d0da01828ebfc072b6ab97554d7-Screenshot_2025-10-13_at_22.16.38.png" />

  [Knowledge Base](/docs/knowledge/overview)
</Frame>
