Skip to main content

Alt text describing the image


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, which relies on grid search, or 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:
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()

This will give you the optimal RAG configuration for your dataset.
{
  "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