Skip to main content

Generate high-quality QA datasets to evaluate RAG systems

Project description

RAGScore

PyPI version Python 3.9+ License

Generate high-quality QA datasets to evaluate your RAG systems

RAGScore automatically generates question-answer pairs from your documents, which you can then use to benchmark and evaluate your RAG (Retrieval-Augmented Generation) systems.

โœจ Features

  • ๐Ÿ“„ Multi-format support - PDF, TXT, Markdown, HTML
  • ๐ŸŒ Multi-language - English and Chinese out of the box
  • ๐Ÿค– Multi-provider - OpenAI, DashScope (Qwen), or any OpenAI-compatible API
  • ๐ŸŽฏ Difficulty levels - Easy, medium, and hard questions
  • ๐Ÿš€ Simple CLI - Easy command-line interface
  • โšก Fast indexing - FAISS-powered vector search

๐Ÿš€ Quick Start

Installation

# Basic installation through pypi
pip install ragscore

# With OpenAI support
pip install ragscore[openai]

# With DashScope support (Chinese users)
pip install ragscore[dashscope]

# All providers
pip install ragscore[all]

Note: On first run, RAGScore automatically downloads required NLTK data (~35MB). This only happens once.

Setup API Key

# For OpenAI
export OPENAI_API_KEY="your-openai-key"

# For DashScope (Alibaba Cloud)
export DASHSCOPE_API_KEY="your-dashscope-key"

Generate QA Pairs

# Place documents in data/docs/, then:
ragscore generate --docs-dir YOUR-PDF-DIRECTORY

Output

Generated QA pairs are saved to output/generated_qas.jsonl:

{
  "id": "abc123",
  "question": "What is RAG?",
  "answer": "RAG (Retrieval-Augmented Generation) combines information retrieval with text generation...",
  "difficulty": "easy",
  "source_path": "docs/rag_intro.pdf"
}

๐Ÿ“– Usage

Command Line

# Generate QA pairs from documents
ragscore generate  --docs-dir YOUR-PDF-DIRECTORY

# Force re-indexing of documents
ragscore generate --force-reindex

# Use specific provider
ragscore generate --provider openai --model gpt-4o

Python API

from ragscore.pipeline import run_pipeline
from ragscore.data_processing import read_docs
from ragscore.llm import generate_qa_for_chunk

# Run full pipeline
run_pipeline(force_reindex=True)

# Or use individual components
docs = read_docs(dir_path="./my_docs")
for doc in docs:
    qas = generate_qa_for_chunk(doc["text"], difficulty="medium", n=5)
    print(qas)

โš™๏ธ Configuration

Create a .env file or set environment variables:

# LLM Provider (auto-detected from available API keys)
DASHSCOPE_API_KEY="your-key"  # For DashScope/Qwen
OPENAI_API_KEY="your-key"     # For OpenAI

# Optional: Custom settings
RAGSCORE_CHUNK_SIZE=512
RAGSCORE_QUESTIONS_PER_CHUNK=5

๐Ÿ”Œ Supported LLM Providers

RAGScore works with any LLM provider - use your own API keys!

Provider Models Environment Variable
OpenAI gpt-4o, gpt-4o-mini, gpt-3.5-turbo OPENAI_API_KEY
Anthropic claude-3-opus, claude-3-sonnet, claude-3-haiku ANTHROPIC_API_KEY
Groq llama-3.1-70b, mixtral (ultra fast!) GROQ_API_KEY
Together AI llama-3, mistral, many open models TOGETHER_API_KEY
Grok (xAI) grok-beta XAI_API_KEY
Mistral mistral-large, mistral-medium MISTRAL_API_KEY
DeepSeek deepseek-chat, deepseek-coder DEEPSEEK_API_KEY
DashScope qwen-turbo, qwen-plus, qwen-max DASHSCOPE_API_KEY
Ollama llama2, mistral, codellama (local!) No key needed
Custom Any OpenAI-compatible endpoint LLM_BASE_URL

Using Ollama (Free, Local)

# Install Ollama: https://ollama.ai
ollama pull llama2
ollama serve

# RAGScore auto-detects Ollama
ragscore generate

Using Custom Endpoints

# Any OpenAI-compatible API (vLLM, LocalAI, etc.)
export LLM_BASE_URL="http://localhost:8000/v1"
export LLM_MODEL="my-model"
ragscore generate

๐Ÿ“ Project Structure

ragscore/
โ”œโ”€โ”€ data/docs/          # Place your documents here
โ”œโ”€โ”€ output/             # Generated QA pairs and index
โ”‚   โ”œโ”€โ”€ generated_qas.jsonl
โ”‚   โ”œโ”€โ”€ index.faiss
โ”‚   โ””โ”€โ”€ meta.json
โ””โ”€โ”€ src/ragscore/       # Source code
    โ”œโ”€โ”€ cli.py          # Command-line interface
    โ”œโ”€โ”€ pipeline.py     # Main pipeline
    โ”œโ”€โ”€ data_processing.py
    โ”œโ”€โ”€ vector_store.py
    โ”œโ”€โ”€ llm.py
    โ””โ”€โ”€ providers/      # LLM provider implementations

๐Ÿš€ RAGScore Pro (Coming Soon)

Need to evaluate your RAG system? RAGScore Pro offers:

  • ๐Ÿ” Hallucination Detection - Catch when your RAG makes things up
  • ๐Ÿ“ Citation Quality Scoring - Verify source attribution accuracy
  • ๐Ÿ“Š Multi-dimensional Scoring - Accuracy, relevance, completeness
  • ๐Ÿ“ˆ Executive Reports - Excel reports for stakeholders
  • โšก API Access - Integrate evaluation into your CI/CD

Join the waitlist โ†’

๐Ÿงช Development

# Clone repository
git clone https://github.com/HZYAI/RagScore.git
cd RagScore

# Install with dev dependencies
pip install -e ".[dev,all]"

# Run tests
pytest

# Run linting
ruff check src/
black --check src/

๐Ÿค Contributing

We welcome contributions! See CONTRIBUTING.md for guidelines.

๐Ÿ“„ License

Apache 2.0 License - see LICENSE for details.

๐Ÿ”— Links


Made with โค๏ธ for the RAG community

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ragscore-0.1.2.tar.gz (35.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ragscore-0.1.2-py3-none-any.whl (34.0 kB view details)

Uploaded Python 3

File details

Details for the file ragscore-0.1.2.tar.gz.

File metadata

  • Download URL: ragscore-0.1.2.tar.gz
  • Upload date:
  • Size: 35.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.2

File hashes

Hashes for ragscore-0.1.2.tar.gz
Algorithm Hash digest
SHA256 958db42fa4d5843af9ca04d6d7e0fcf14b8c3b5ff4466e8281155eafae3f0d2f
MD5 0a26e4a8e37fc9b5a0ad044a7d177183
BLAKE2b-256 f4946a458cdada47f81ea728708564b93ccf1ee56671aecc185821a2e9788a41

See more details on using hashes here.

File details

Details for the file ragscore-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: ragscore-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 34.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.2

File hashes

Hashes for ragscore-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 7e197c2c12aa1f23aa9a9d93758991cfbb6abe408c500b75b422e5642467aec7
MD5 5fce8301998b0adb97cfe331b84ba68a
BLAKE2b-256 2d0d70d6f39be97679c1f964e0b9a6b26e72dfdf4a74f188b8da59d0f39547c3

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page