Modular toolkit for building Retrieval-Augmented Generation (RAG) pipelines.
Project description
RAGToolBox
RAGToolBox is a modular, extensible Python package for building Retrieval-Augmented Generation (RAG) pipelines. It provides end-to-end components for:
- Loading content (local files, web pages, PubMed/PMC articles)
- Chunking text (paragraphs, sentences, sliding windows, section‑aware, hierarchical)
- Storing embeddings (SQLite and optional ChromaVectorStore backends)
- Indexing content with parallel embedding and metadata parsing
- Retrieval via FastEmbed or (optional) openai embeddings and similarity search
- Augmentation using customizable prompts and LLMs (local or Hugging Face)
Table of Contents
Installation
Install the latest release from PyPI:
pip install ragtoolbox
# with optional extras
pip install "ragtoolbox[transformers,chromadb,openai,ncbi]"
Or install from source:
git clone https://github.com/Nick-Nunley/RAGToolBox.git
cd RAGToolBox
pip install .
Prerequisites
- Python 3.10+
- Core dependencies (see also
pyproject.toml):- numpy
- requests
- pyyaml
- pdfplumber
- html2text
- pytest
- beautifulsoup4
- readability-lxml
- nltk
- fastembed
- huggingface_hub
- Optional dependencies (for extended capabilities):
- openai
- chromadb
- torch
- transformers
- biopython
Quickstart
Loading Documents
Use the built‑in factory to detect and process various formats:
from RAGToolBox.loader import BaseLoader
# Raw bytes fetched externally (e.g., via requests or open file)
raw_bytes = open("example.pdf", "rb").read()
LoaderClass = BaseLoader.detect_loader("example.pdf", raw_bytes)
loader = LoaderClass("example.pdf", "assets/kb")
loader.raw_content = raw_bytes
loader.process()
Indexing Pipeline
Chunk, embed, and store your KB in one pipeline:
from pathlib import Path
from RAGToolBox.chunk import SectionAwareChunker, SlidingWindowChunker, HierarchicalChunker
from RAGToolBox.index import Indexer, IndexerConfig
chunker = HierarchicalChunker([
SectionAwareChunker(max_chunk_size=1000, overlap=200),
SlidingWindowChunker(window_size=1000, overlap=200)
])
indexer = Indexer(
chunker=chunker,
embedding_model="fastembed",
config = IndexerConfig(
vector_store_backend="sqlite",
vector_store_config={"db_path": Path("assets/kb/embeddings/embeddings.db")}
)
)
indexer.index(chunked_results)
Retrieval & Augmentation
Retrieve relevant chunks and generate an LLM response:
from pathlib import Path
from RAGToolBox.retriever import Retriever, RetrievalConfig
from RAGToolBox.augmenter import Augmenter, GenerationConfig
# Example query
user_query = "What is RAG?"
# Initialize retriever
retriever = Retriever(
embedding_model="fastembed",
db_path=Path("assets/kb/embeddings/embeddings.db")
)
# Perform retrieval
contexts = retriever.retrieve(user_query, RetrievalConfig(top_k=5))
# Initialize augmenter
augmenter = Augmenter(
model_name="google/gemma-2-2b-it",
prompt_type="default",
api_key="${HUGGINGFACE_API_KEY}",
use_local=False
)
# Generate a response with sources
result = augmenter.generate_response_with_sources(
query=user_query,
retrieved_chunks=contexts,
gen_config=GenerationConfig(temperature=0.25, max_new_tokens=200)
)
print(result["response"])
CLI Usage
Each module exposes a CLI entrypoint. Use -h for details:
# Load documents from URLs or files
python -m RAGToolBox.loader https://example.com/article.pdf --output-dir assets/kb
# Build index (chunk + embed)
python -m RAGToolBox.index --kb-dir assets/kb --embedding-model fastembed --vector-store sqlite
# Retrieve top-10 chunks\ npython -m RAGToolBox.retriever --query "Explain RAG" --embedding-model openai
# Augment with LLM
python -m RAGToolBox.augmenter "What is RAG?" --sources
# For a concise one-liner answer
python -m RAGToolBox.augmenter "What is RAG?" --prompt-type concise
# Interactively chat with your knowledgebase
python -m RAGToolBox.augmenter --chat
Testing
Run the full test suite:
bash tests/Run_tests.sh
Continuous integration is configured via GitHub Actions (see .github/workflows/ci.yml).
Note
RAGToolBox is in active development. The current release (v0.1.0) is an unstable preview. APIs and behavior may change, and some features may not yet be fully tested.
Contributing
- Fork the repo
- Create a feature branch:
git checkout -b feature/your-feature - Commit changes:
git commit -m "Add new feature" - Push to your fork and open a PR
Please follow the Contributing Guidelines.
License
This project is licensed under the MIT License. See LICENSE for details.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file ragtoolbox-0.1.0.tar.gz.
File metadata
- Download URL: ragtoolbox-0.1.0.tar.gz
- Upload date:
- Size: 37.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
774a44137b31173b04180a1ce9db8be980641f4de5aed8c37c88c58ef4c0dd99
|
|
| MD5 |
8f6f9089be54cd6561906b49e42ad4a2
|
|
| BLAKE2b-256 |
944d32da61d6df9705bf2ef3fa92779b466c1cb2cbe9c166b5d26021126532ff
|
Provenance
The following attestation bundles were made for ragtoolbox-0.1.0.tar.gz:
Publisher:
Package.yml on Nick-Nunley/RAGToolBox
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
ragtoolbox-0.1.0.tar.gz -
Subject digest:
774a44137b31173b04180a1ce9db8be980641f4de5aed8c37c88c58ef4c0dd99 - Sigstore transparency entry: 451721182
- Sigstore integration time:
-
Permalink:
Nick-Nunley/RAGToolBox@0386bacb788dc974f573cc0f82ec67747afa0b73 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/Nick-Nunley
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
Package.yml@0386bacb788dc974f573cc0f82ec67747afa0b73 -
Trigger Event:
push
-
Statement type:
File details
Details for the file ragtoolbox-0.1.0-py3-none-any.whl.
File metadata
- Download URL: ragtoolbox-0.1.0-py3-none-any.whl
- Upload date:
- Size: 43.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
14e1690c72887191a09f2ef94a8fc4e7609ab03b19d15d22cbbdaeb20a6f25fb
|
|
| MD5 |
b9d6f667500c4815d0da7653a18e1b29
|
|
| BLAKE2b-256 |
7dd2eeca845539116249bcb8f137a4b070cd32958c5af598c0ba50b8a66d6791
|
Provenance
The following attestation bundles were made for ragtoolbox-0.1.0-py3-none-any.whl:
Publisher:
Package.yml on Nick-Nunley/RAGToolBox
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
ragtoolbox-0.1.0-py3-none-any.whl -
Subject digest:
14e1690c72887191a09f2ef94a8fc4e7609ab03b19d15d22cbbdaeb20a6f25fb - Sigstore transparency entry: 451721190
- Sigstore integration time:
-
Permalink:
Nick-Nunley/RAGToolBox@0386bacb788dc974f573cc0f82ec67747afa0b73 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/Nick-Nunley
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
Package.yml@0386bacb788dc974f573cc0f82ec67747afa0b73 -
Trigger Event:
push
-
Statement type: