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

# Basic installation through source
python -m pip install -e.

# 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

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

# 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.1.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.1-py3-none-any.whl (34.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: ragscore-0.1.1.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.1.tar.gz
Algorithm Hash digest
SHA256 ecc20545282207d605247df91598d7eaf8d8200a896f2803f356f6b954f2ac8e
MD5 25e8407fa6463073374286667cbbaddf
BLAKE2b-256 24681e0b2fe98a213ccb884034dd94b9a02acda26ece813bd9d44b1fd18fe99f

See more details on using hashes here.

File details

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

File metadata

  • Download URL: ragscore-0.1.1-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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 05652eecd37b3645b6c8689a68408a2f68657df23c53297f46d599bc718ea28e
MD5 c441b71c923afadfb1535184f2cd1de2
BLAKE2b-256 6185267d4d3df995e878cfefa32d9407c06c13463cced9f74f8939b0e6666202

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