Skip to main content

AutoRAG (Legacy)

RAG AutoML tool for automatically finding an optimal RAG pipeline for your data.

Thumbnail

PyPI - Downloads LinkedIn X (formerly Twitter) Follow Hugging Face

Marker-Inc-Korea%2FAutoRAG | Trendshift

There are many RAG pipelines and modules out there, but you don’t know what pipeline is great for “your own data” and "your own use-case." Making and evaluating all RAG modules is very time-consuming and hard to do. But without it, you will never know which RAG pipeline is the best for your own use-case.

AutoRAG is a tool for finding the optimal RAG pipeline for “your data.” You can evaluate various RAG modules automatically with your own evaluation data and find the best RAG pipeline for your own use-case.

AutoRAG supports a simple way to evaluate many RAG module combinations. Try now and find the best RAG pipeline for your own use-case.

Explore our 📖 Document!!


YouTube Tutorial

https://github.com/Marker-Inc-Korea/AutoRAG/assets/96727832/c0d23896-40c0-479f-a17b-aa2ec3183a26

Muted by default, enable sound for voice-over

You can see on YouTube

Use AutoRAG in HuggingFace Space 🚀

Colab Tutorial

Index

Quick Install

We recommend using Python version 3.10 or higher for AutoRAG.

pip install AutoRAG

If you want to use the local models, you need to install gpu version.

pip install "AutoRAG[gpu]"

Or for parsing, you can use the parsing version.

pip install "AutoRAG[gpu,parse]"

Data Creation

Hugging Face Sticker

Image

image

RAG Optimization requires two types of data: QA dataset and Corpus dataset.

  1. QA dataset file (qa.parquet)
  2. Corpus dataset file (corpus.parquet)

QA dataset is important for accurate and reliable evaluation and optimization.

Corpus dataset is critical to the performance of RAGs. This is because RAG uses the corpus to retrieve documents and generate answers using it.

📌 Supporting Data Creation Modules

Image

Quick Start

1. Parsing

Set YAML File

modules:
  - module_type: langchain_parse
    parse_method: pdfminer

You can also use multiple Parse modules at once. However, in this case, you'll need to return a new process for each parsed result.

Start Parsing

You can parse your raw documents with just a few lines of code.

from autorag.parser import Parser

parser = Parser(data_path_glob="your/data/path/*")
parser.start_parsing("your/path/to/parse_config.yaml")

2. Chunking

Set YAML File

modules:
  - module_type: llama_index_chunk
    chunk_method: Token
    chunk_size: 1024
    chunk_overlap: 24
    add_file_name: en

You can also use multiple Chunk modules at once. In this case, you need to use one corpus to create QA and then map the rest of the corpus to QA Data. If the chunk method is different, the retrieval_gt will be different, so we need to remap it to the QA dataset.

Start Chunking

You can chunk your parsed results with just a few lines of code.

from autorag.chunker import Chunker

chunker = Chunker.from_parquet(parsed_data_path="your/parsed/data/path")
chunker.start_chunking("your/path/to/chunk_config.yaml")

3. QA Creation

You can create QA dataset with just a few lines of code.

import pandas as pd
from llama_index.llms.openai import OpenAI

from autorag.data.qa.filter.dontknow import dontknow_filter_rule_based
from autorag.data.qa.generation_gt.llama_index_gen_gt import (
	make_basic_gen_gt,
	make_concise_gen_gt,
)
from autorag.data.qa.schema import Raw, Corpus
from autorag.data.qa.query.llama_gen_query import factoid_query_gen
from autorag.data.qa.sample import random_single_hop

llm = OpenAI()
raw_df = pd.read_parquet("your/path/to/parsed.parquet")
raw_instance = Raw(raw_df)

corpus_df = pd.read_parquet("your/path/to/corpus.parquet")
corpus_instance = Corpus(corpus_df, raw_instance)

initial_qa = (
	corpus_instance.sample(random_single_hop, n=3)
	.map(
		lambda df: df.reset_index(drop=True),
	)
	.make_retrieval_gt_contents()
	.batch_apply(
		factoid_query_gen,  # query generation
		llm=llm,
	)
	.batch_apply(
		make_basic_gen_gt,  # answer generation (basic)
		llm=llm,
	)
	.batch_apply(
		make_concise_gen_gt,  # answer generation (concise)
		llm=llm,
	)
	.filter(
		dontknow_filter_rule_based,  # filter don't know
		lang="en",
	)
)

initial_qa.to_parquet('./qa.parquet', './corpus.parquet')

RAG Optimization

Hugging Face Sticker

Image

rag

How AutoRAG optimizes RAG pipeline?

Here is the AutoRAG RAG Structure that only show Nodes.

Image

Here is the image showing all the nodes and modules.

Image

rag_opt_gif

📌 Supporting RAG Optimization Nodes & modules

Metrics

The metrics used by each node in AutoRAG are shown below.

Image

Image

Here is the detailed information about the metrics that AutoRAG supports.

Quick Start

1. Set YAML File

First, you need to set the config YAML file for your RAG optimization.

We highly recommend using pre-made config YAML files for starter.

Here is an example of the config YAML file to use three retrieval nodes, prompt_maker, and generator nodes.

node_lines:
  - node_line_name: retrieve_node_line
    nodes:
      - node_type: lexical_retrieval
        strategy:
          metrics: [ retrieval_f1, retrieval_recall, retrieval_ndcg, retrieval_mrr ]
        top_k: 3
        modules:
          - module_type: bm25
      - node_type: semantic_retrieval
        strategy:
          metrics: [ retrieval_f1, retrieval_recall, retrieval_ndcg, retrieval_mrr ]
        top_k: 3
        modules:
          - module_type: vectordb
            vectordb: default
      - node_type: hybrid_retrieval
        strategy:
          metrics: [ retrieval_f1, retrieval_recall, retrieval_ndcg, retrieval_mrr ]
        top_k: 3
        modules:
          - module_type: hybrid_rrf
            weight_range: (4,80)
  - node_line_name: post_retrieve_node_line
    nodes:
      - node_type: prompt_maker  # Set Prompt Maker Node
        strategy:
          metrics: # Set Generation Metrics
            - metric_name: meteor
            - metric_name: rouge
            - metric_name: sem_score
              embedding_model: openai
        modules:
          - module_type: fstring
            prompt: "Read the passages and answer the given question. \n Question: {query} \n Passage: {retrieved_contents} \n Answer : "
      - node_type: generator  # Set Generator Node
        strategy:
          metrics: # Set Generation Metrics
            - metric_name: meteor
            - metric_name: rouge
            - metric_name: sem_score
              embedding_model: openai
        modules:
          - module_type: openai_llm
            llm: gpt-4o-mini
            batch: 16

2. Run AutoRAG

You can evaluate your RAG pipeline with just a few lines of code.

from autorag.evaluator import Evaluator

evaluator = Evaluator(qa_data_path='your/path/to/qa.parquet', corpus_data_path='your/path/to/corpus.parquet')
evaluator.start_trial('your/path/to/config.yaml')

or you can use the command line interface

autorag evaluate --config your/path/to/default_config.yaml --qa_data_path your/path/to/qa.parquet --corpus_data_path your/path/to/corpus.parquet

Once it is done, you can see several files and folders created in your current directory. At the trial folder named to numbers (like 0), you can check summary.csv file that summarizes the evaluation results and the best RAG pipeline for your data.

For more details, you can check out how the folder structure looks like at here.

3. Run Dashboard

You can run a dashboard to easily see the result.

autorag dashboard --trial_dir /your/path/to/trial_dir

sample dashboard

dashboard

4. Deploy your optimal RAG pipeline

4-1. Run as a Code

You can use an optimal RAG pipeline right away from the trial folder. The trial folder is the directory used in the running dashboard. (like 0, 1, 2, ...)

from autorag.deploy import Runner

runner = Runner.from_trial_folder('/your/path/to/trial_dir')
runner.run('your question')

4-2. Run as an API server

You can run this pipeline as an API server.

Check out the API endpoint at here.

import nest_asyncio
from autorag.deploy import ApiRunner

nest_asyncio.apply()

runner = ApiRunner.from_trial_folder('/your/path/to/trial_dir')
runner.run_api_server()
autorag run_api --trial_dir your/path/to/trial_dir --host 0.0.0.0 --port 8000

The cli command uses extracted config YAML file. If you want to know it more, check out here.

4-3. Run as a Web Interface

you can run this pipeline as a web interface.

Check out the web interface at here.

autorag run_web --trial_path your/path/to/trial_path

sample web interface

web_interface

☎️ FaQ

💻 Hardware Specs

⭐ Running AutoRAG

🍯 Tips/Tricks

☎️ TroubleShooting

Thanks for shoutout

Company

llama index

Individual


✨ Contributors ✨

Thanks go to these wonderful people:

Contribution

We are developing AutoRAG as open-source.

So this project welcomes contributions and suggestions. Feel free to contribute to this project.

Plus, check out our detailed documentation at here.

Citation

@misc{kim2024autoragautomatedframeworkoptimization,
      title={AutoRAG: Automated Framework for optimization of Retrieval Augmented Generation Pipeline},
      author={Dongkyu Kim and Byoungwook Kim and Donggeon Han and Matouš Eibich},
      year={2024},
      eprint={2410.20878},
      archivePrefix={arXiv},
      primaryClass={cs.CL},
      url={https://arxiv.org/abs/2410.20878},
}

Metadata

Release files for AutoRAG 0.3.27

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for AutoRAG 0.3.27
File Size Uploaded
autorag-0.3.27.tar.gz 10.3 MB Details

Built distribution (wheel)

Table of built distributions (wheels) for AutoRAG 0.3.27
File Interpreter ABI Platform
autorag-0.3.27-py3-none-any.whl Python 3 none any Details

Total release size: 10.6 MB

Release files / autorag-0.3.27.tar.gz

Download URL autorag-0.3.27.tar.gz
Size 10.3 MB
Tags Source
SHA-256 checksum
How to use checksums
44315ae2b942cd22abc8e0de5f6a6368912341f21a8c62f103569dcf21832dda
BLAKE2b-256 checksum
How to use checksums
786a2d87d38f627d48a6f8c8619965dfbd96f616b5a3c35d84acf942dfcafa4e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.12.23 {"installer":{"name":"uv","version":"0.12.23","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / autorag-0.3.27-py3-none-any.whl

Download URL autorag-0.3.27-py3-none-any.whl
Size 268.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
0f6a6c6bf38bb3667afc30a7a8deda9e73ed9286496393678aa66f1d80887e2e
BLAKE2b-256 checksum
How to use checksums
2689c9b8677376ad2394feb1ee1bb3105250b81e30ff38c633138d785e344f71
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.12.23 {"installer":{"name":"uv","version":"0.12.23","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release history Release notifications | RSS feed

This release

0.3.27 This release

2 release files

0.3.26

2 release files

0.3.25

2 release files

0.3.24

2 release files

0.3.23

2 release files

0.3.21

2 release files

0.3.19

2 release files

0.3.18

2 release files

0.3.17

2 release files

0.3.16

2 release files

0.3.13

2 release files

0.3.11

2 release files

0.3.10

2 release files

0.3.9

2 release files

0.3.8

2 release files

0.3.7

2 release files

0.3.6

2 release files

0.3.5

2 release files

0.3.4

2 release files

0.3.3

2 release files

0.3.2

2 release files

0.3.1

2 release files

0.3.0

2 release files

0.2.18

2 release files

0.2.17

2 release files

0.2.16

2 release files

0.2.15

2 release files

0.2.14

2 release files

0.2.11

2 release files

0.2.10

2 release files

0.2.9

2 release files

0.2.8

2 release files

0.2.7

2 release files

0.2.6

2 release files

0.2.5

2 release files

0.2.4

2 release files

0.2.3

2 release files

0.2.2

2 release files

0.2.1

2 release files

0.2.0

2 release files

0.1.12

2 release files

0.1.11

2 release files

0.1.9

2 release files

0.1.8

2 release files

0.1.7

2 release files

0.1.6

2 release files

0.1.5

2 release files

0.1.4

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 release files

0.0.14

2 release files

0.0.13

2 release files

0.0.12

2 release files

0.0.10

2 release files

0.0.9

2 release files

0.0.8

2 release files

0.0.7

2 release files

0.0.6

2 release files

0.0.5

2 release files

0.0.4

2 release files

0.0.3

2 release files

0.0.2

2 release files

0.0.1

2 release files

0.0.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page