Skip to main content

Generate high-quality QA datasets to evaluate RAG systems

Project description

RAGScore Logo

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.3.tar.gz (35.9 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.3-py3-none-any.whl (34.1 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: ragscore-0.1.3.tar.gz
  • Upload date:
  • Size: 35.9 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.3.tar.gz
Algorithm Hash digest
SHA256 b1355e0c814974e966c6d243a18a2f5cc5f89b925b8b780ab57dd3ce62415b52
MD5 88300328ce2778690426a4244281ac26
BLAKE2b-256 3076f9449e7433af9768ca64b5fbb88eedc97334c026542d1ac2ba5a62d766be

See more details on using hashes here.

File details

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

File metadata

  • Download URL: ragscore-0.1.3-py3-none-any.whl
  • Upload date:
  • Size: 34.1 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.3-py3-none-any.whl
Algorithm Hash digest
SHA256 25801fe9b4fd549ff3823cae795cb5ccc68b61c12947063e88a9ec74f8204d37
MD5 70e37f45588bf282ccb08833bdc6f6fa
BLAKE2b-256 784ae7d4a0a476947a3c30bd1cf40b6b90a243e7d11192b82dc68316704da42f

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