Skip to content

Latest commit

ย 

History

104 Commits

Folders and files

NameName
Last commit message
Last commit date
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

RAGtune ๐ŸŽ›๏ธ

Python 3.9+ License: Apache 2.0 Code Style: Black Status: Beta

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


๐Ÿš€ Why RAGtune?

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.

๐Ÿ“ฆ Installation

# 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.

1. Initialize a Project

Scaffold a new configuration file with default settings.

ragtune init
# Created 'ragtune_config.yaml'

2. Configure Your Pipeline

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"

3. Run the Pipeline

Execute the pipeline instantly from the terminal.

ragtune run ragtune_config.yaml --query "How does Active Learning optimize RAG?"

๐Ÿ› ๏ธ CLI & Configuration

RAGtune is built on a declarative philosophy. Every pipeline, from simple BM25 to complex iterative estimators, can be described in a single file.

Declarative Pipelines (YAML/JSON)

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" }
    }
  }
}

Visual Inspection

Understand your pipeline flow instantly with ASCII diagrams:

ragtune visualize ragtune_config.yaml

The 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.


๐Ÿ—๏ธ Architecture

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
Loading

See Architecture Docs for deep dives.


๐Ÿงฉ Integrations

RAGtune plays nicely with your existing stack.

  • LangChain: Wrap any Retriever as a RAGtune source.
  • LlamaIndex: Use QueryEngine or retrievers directly.
  • PyTerrier: Full compatibility for IR research benchmarks.

๐Ÿค Contributing

We welcome contributions! Please see our Roadmap to find open tasks.

  1. Fork the Project
  2. Create your Feature Branch (git checkout -b feature/AmazingFeature)
  3. Commit your Changes (git commit -m 'Add some AmazingFeature')
  4. Push to the Branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

By submitting a contribution, you agree to the project's Contributor License Agreement, which is required before any pull request can be merged.


๐Ÿ“„ License

Distributed under the Apache License 2.0. See LICENSE and NOTICE for details.


Built with โค๏ธ by the RAGtune Team.

About

Self improving Retrieval Systems

Resources

Stars

4 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages