A Budget-Aware RAG Middleware.
RAGtune transforms static RAG pipelines into dynamic, cost-sensitive feedback loops. It treats cost and latency as first-class constraints, optimizing information gain by iteratively sampling and reranking documents based on real-time feedback.
Explore Docs · View Roadmap · Release Notes
Traditional RAG pipelines are linear (Retrieve → Rerank → Generate) and cost-blind. They either retrieve too little (missing context) or too much (wasting tokens and latency).
RAGtune introduces an Active Learning Loop:
| Feature | Description |
|---|---|
| 💰 Budget-First | Define precise budgets for Token Count, Latency (ms), and GPU/API Costs. The loop stops exactly when the budget is hit. |
| 🔄 Iterative Feedback | Uses a Controller to fetch documents in batches. High-scoring docs boost the priority of similar unranked candidates in real-time. |
| 🧠 Intelligence Layer | Pluggable Estimators (Similarity, Utility) predict which documents are worth paying to rerank next. |
| 🔌 Ecosystem Ready | Drop-in decorators for LangChain, LlamaIndex, and PyTerrier components. |
# Clone the repository
git clone https://github.com/yourusername/ragtune.git
cd ragtune
# Install in editable mode
pip install -e .The fastest way to use RAGtune is via the CLI using declarative YAML or JSON configurations.
Scaffold a new configuration file with default settings.
ragtune init
# Created 'ragtune_config.yaml'Edit ragtune_config.yaml to define your budget and components.
pipeline:
budget:
tokens: 4000
latency_ms: 1500
components:
retriever:
type: "bm25"
reranker:
type: "cross-encoder"Execute the pipeline instantly from the terminal.
ragtune run ragtune_config.yaml --query "How does Active Learning optimize RAG?"RAGtune is built on a declarative philosophy. Every pipeline, from simple BM25 to complex iterative estimators, can be described in a single file.
Whether you prefer the readability of YAML or the machine-compatibility of JSON, RAGtune supports both.
YAML Configuration:
# ragtune_config.yaml
pipeline:
name: "My Pipeline"
budget: { tokens: 2000 }
components:
retriever: { type: "bm25" }JSON Configuration:
{
"pipeline": {
"name": "My Pipeline",
"budget": { "tokens": 2000 },
"components": {
"retriever": { "type": "bm25" }
}
}
}Understand your pipeline flow instantly with ASCII diagrams:
ragtune visualize ragtune_config.yamlThe visualization renders a box-and-arrow diagram representing the pipeline:
╭─────────────────── RAGtune Pipeline: My Pipeline ────────────────────╮
│ │
│ ┌────────────┐ ┌────────────┐ ┌────────────┐ ┌────────────┐│
│ │ RETRIEVER │───▶│REFORMULATOR│───▶│ RERANKER │───▶│ ASSEMBLER ││
│ ├────────────┤ ├────────────┤ ├────────────┤ ├────────────┤│
│ │ type: bm25 │ │ type: llm │ │ type: cross│ │ type: greed││
│ └────────────┘ └────────────┘ └────────────┘ └────────────┘│
│ ▲ │
│ ┌────────────┐ ┌───────┴────┐ │
│ │ SCHEDULER │◀───│ ESTIMATOR │ │
│ ├────────────┤ ├────────────┤ │
│ │ graceful │ │ type: base │ │
│ └────────────┘ └────────────┘ │
│ │
│ Budget: tokens=5000 | rerank_docs=50 | latency_ms=2000 │
╰──────────────────────────────────────────────────────────────────────╯
For a full breakdown of all commands (init, index, validate, run, list, visualize) and the v0.2 configuration schema, see the CLI Reference Guide.
RAGtune sits between your application and your data sources.
graph LR
User[User Query] --> Controller
subgraph "RAGtune Middleware"
Controller -- "Budget Check" --> Tracker[CostTracker]
Controller -- "Next Batch?" --> Scheduler
Scheduler -- "Propose" --> Reranker
Reranker -- "Feedback" --> Estimator
Estimator -- "Prioritize" --> Scheduler
end
Reranker --> FinalContext
See Architecture Docs for deep dives.
RAGtune plays nicely with your existing stack.
- LangChain: Wrap any
Retrieveras a RAGtune source. - LlamaIndex: Use
QueryEngineor retrievers directly. - PyTerrier: Full compatibility for IR research benchmarks.
We welcome contributions! Please see our Roadmap to find open tasks.
- Fork the Project
- Create your Feature Branch (
git checkout -b feature/AmazingFeature) - Commit your Changes (
git commit -m 'Add some AmazingFeature') - Push to the Branch (
git push origin feature/AmazingFeature) - Open a Pull Request
Distributed under the MIT License. See pyproject.toml for details.
Built with ❤️ by the RAGtune Team.