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

# Introduction

<p align="center">
  <img src="https://mintcdn.com/grpo/-04D4Zy0ca7um31C/logo/light2.svg?fit=max&auto=format&n=-04D4Zy0ca7um31C&q=85&s=096f0ac3da2c687dfb2c3ec005d0db99" alt="Alt text describing the image" width="400" className="block dark:hidden" data-path="logo/light2.svg" />

  <br />

  <figcaption>
    <small>Light version of the company logo</small>
  </figcaption>
</p>

<p align="center">
  <img src="https://mintcdn.com/grpo/-04D4Zy0ca7um31C/logo/dark2.svg?fit=max&auto=format&n=-04D4Zy0ca7um31C&q=85&s=7e6a18b29d56d8277736c8c11d431d3a" alt="Alt text describing the image" width="400" className="hidden dark:block" data-path="logo/dark2.svg" />

  <br />

  <figcaption>
    <small>Dark version of the company logo</small>
  </figcaption>
</p>

**RAGOpt** is a Python optimization framework that eliminates manual hyperparameter guesswork in your RAG pipelines.
It uses Bayesian optimization to systematically tune over 20+ hyperparameters, from chunk size and overlap to model selection and embedding strategies automatically discovering the best configurations for your specific use case

***

### Why RAGOpt?

Optimizing Retrieval-Augmented Generation (RAG) pipelines is complex and highly dependent on configuration choices that impact quality, latency, and cost.
Unlike [AutoRAG](https://github.com/Marker-Inc-Korea/AutoRAG), which relies on grid search, or [Ragas](https://github.com/explodinggradients/ragas), which enforces rigid evaluation frameworks, RAGOpt is partially opinionated: it provides smart defaults while staying flexible with any LangChain-compatible model or provider.

RAGOpt helps answer a question like:

> **What’s the best RAG configuration to minimize cost and latency while maintaining accuracy and safety ?**

For example, here's you can get best RAG configurations in a few iterations using RAGOpt optimizer:

<CodeGroup>
  ```python 📈 optimize.py theme={null}
  from rag_opt.dataset import TrainDataset
  from rag_opt.optimizer import Optimizer

  # First you have to run generate_questions_.py
  # to get a list of QAs to be used in the evaluation process

  # Load the training dataset (questions/answers)
  train_dataset = TrainDataset.from_json("rag_dataset.json")

  # Initialize the optimizer
  optimizer = Optimizer(
  train_dataset=train_dataset,
  config_path="rag_config.yaml",
  verbose=True
  )

  # Run optimization
  # Increase n_trials for better results
  best_config = optimizer.optimize(n_trials=2, best_one=True,plot_hypervolume=True)
  best_config.to_json()

  ```

  ```yaml ⚙️ rag_config.yaml theme={null}
  # 1- define here the RAG Hyperparameters u would like to optimize
  chunk_size:
    bounds: [512, 1024]
    dtype: int

  max_tokens:
  bounds: [256, 512]
  dtype: int

  vector_store:
  ---
  # More Parameters
  ```

  ```python 🤖 generate_questions.py theme={null}
  from langchain.chat_models import init_chat_model
  from rag_opt.rag import DatasetGenerator

  # 1- Generate list of questions / answers to be used in RAG evaluation

  # Initialize the language model
  llm = init_chat_model(
  model="gpt-3.5-turbo",
  model_provider="openai",
  api_key="sk-\*\*\*"
  )

  # Generates 3 training questions
  # you can also path a file like dataset_path=myfile.pdf
  data_gen = DatasetGenerator(llm,dataset_path="./data")
  dataset = data_gen.generate(3)
  dataset.to_json("./questions.json")

  ```

  ```json 🧾 questions.json theme={null}
  {
    "items": [
      {
        "question": "What is the capital city of Japan?",
        "answer": "The capital city of Japan is Tokyo.",
        "contexts": [
          "Tokyo is the capital of Japan, though some still picture Kyoto when they hear 'old Japan'.",
          "Neon lights and ancient temples coexist where decisions shape the nation.",
          "It’s a city where tradition bows to innovation every single day."
        ],
        "metadata": {}
      },
      {
        "question": "Who won the Nobel Peace Prize in 2025?",
        "answer": "The Nobel Peace Prize in 2025 was awarded to María Corina Machado.",
        "contexts": [
          "María Corina Machado received the Nobel Peace Prize in 2025, proving persistence can echo louder than politics.",
          "Donald Trump didn’t get the Nobel Prize; however, the announcement stirred global chatter.",
          "Sometimes peace arrives wearing the voice of defiance and hope."
        ],
        "metadata": {}
      }
    ]
  }
  ```
</CodeGroup>

This will give you the optimal RAG configuration for your dataset.

```yaml theme={null}
{
  "chunk_size": 500,
  "max_tokens": 100,
  "chunk_overlap": 200,
  "search_type": "hybrid",
  "k": 1,
  "temperature": 1.0,
  "embedding": { "provider": "openai", "model": "text-embedding-3-large" },
  "llm": { "provider": "openai", "model": "gpt-4o" },
  "vector_store": { "provider": "faiss" },
  "use_reranker": true,
}
```

## Get Started

<Columns cols={2}>
  <Card title="Quick Start" icon="rocket" href="/quickstart">
    Get started with RAGOpt in under 5 minutes.
  </Card>

  <Card title="Main Concepts" icon="book" href="/concepts">
    Get familiar with the underlying architecture and key design of RAGOpt
  </Card>

  <Card title="Configuration Guide" icon="sliders" href="/rag/overview">
    Learn about the Hyperparameters RAG Configuration file in details
  </Card>

  <Card title="Optimization Workflows" icon="diagram-project" href="/optimization/overview">
    Integrate RAGOpt with your custom RAG pipeline.
  </Card>
</Columns>
