Skip to main content

A pip-installable Python library providing drop-in RAG evaluation capabilities using RAGAS

Project description

ragaeval

A pip-installable Python library providing drop-in RAG (Retrieval-Augmented Generation) evaluation capabilities using the RAGAS framework (version 0.2.15).

Features

  • Three Integration Patterns: Choose from decorator, context manager, or manual logging
  • Secure Credential Management: Multiple sources with precedence (args > env vars > .env > config file)
  • Cross-Platform: Works on Windows, Mac, and Linux
  • Automatic Field Normalization: Supports common field name aliases
  • CLI Tools: Configuration, execution, and status commands
  • Rich Reports: Terminal output with visual indicators and CSV export

Installation

pip install ragaeval

Quick Start

1. Configure API Credentials

Run the interactive configuration wizard:

ragaeval configure

Or set environment variables:

export AZURE_OPENAI_API_KEY="your-api-key"
export AZURE_OPENAI_ENDPOINT="https://your-resource.openai.azure.com/"
export AZURE_OPENAI_DEPLOYMENT_NAME="gpt-4o"
export AZURE_OPENAI_API_VERSION="2024-02-15-preview"

2. Log Evaluation Data

Option A: Decorator Pattern

from ragaeval import evaluate_rag

@evaluate_rag
def my_rag_pipeline(query: str, contexts: list) -> str:
    # Your RAG logic here
    response = generate_answer(query, contexts)
    return response

# Use your function normally - data is captured automatically
result = my_rag_pipeline(
    query="What is the refund policy?",
    contexts=["Returns accepted within 30 days", "Refunds processed in 5-7 days"]
)

Option B: Context Manager Pattern

from ragaeval import EvalSession

with EvalSession() as session:
    query = "What is the refund policy?"
    contexts = retrieve_documents(query)
    response = generate_answer(query, contexts)
    
    session.log(query=query, contexts=contexts, response=response)

Option C: Manual Logging

import ragaeval

query = "What is the refund policy?"
contexts = retrieve_documents(query)
response = generate_answer(query, contexts)

ragaeval.log(query=query, contexts=contexts, response=response)

3. Run Evaluation

ragaeval run

This will:

  • Read logged data from .ragaeval_log.jsonl
  • Execute RAGAS evaluation using Azure OpenAI
  • Display results in terminal with visual indicators
  • Export results to eval_results.csv

CLI Commands

ragaeval run

Execute evaluation on logged data.

ragaeval run                          # Use defaults
ragaeval run --model gpt-4o          # Specify Azure deployment
ragaeval run --output results.csv    # Custom output path

ragaeval configure

Interactive credential setup.

ragaeval configure

ragaeval status

Display configuration and log status.

ragaeval status

ragaeval clear

Clear evaluation logs.

ragaeval clear               # Prompts for confirmation
ragaeval clear --force       # Skip confirmation

ragaeval --version

Display package version.

ragaeval --version

Field Name Aliases

The package supports common field name variations:

  • Query: query, question, input, user_input
  • Response: response, answer, llm_response, output, actual_output
  • Contexts: contexts, context, retrieved_contexts, source_documents
  • Reference: reference, ground_truth, expected

Evaluation Metrics

Always Evaluated (Group A)

  • Faithfulness: Response consistency with retrieved contexts
  • Response Relevancy: Relevance of response to query
  • Aspect Critic: Harmfulness detection

Evaluated When Reference Available (Group B)

  • Factual Correctness: Accuracy against ground truth
  • Semantic Similarity: Semantic closeness to reference
  • BLEU Score: N-gram overlap
  • ROUGE Score: Recall-oriented overlap
  • String Presence: Exact string matching
  • Exact Match: Perfect match detection

Configuration Sources

Credentials are resolved in this order (highest to lowest precedence):

  1. Explicit function arguments
  2. Environment variables (AZURE_OPENAI_API_KEY, etc.)
  3. .env file in current directory
  4. Config file at ~/.ragaeval/config.json

Cross-Platform Notes

  • Config file location: ~/.ragaeval/config.json (user home directory)
  • Log file location: .ragaeval_log.jsonl (current working directory)
  • File permissions: Config file is created with user-only access (0o600)

Requirements

  • Python >= 3.8
  • Azure OpenAI API access (for LLM evaluation)
  • Optional: OpenAI API key (for embeddings, otherwise uses local models)

Development

Install in Development Mode

pip install -e .[dev]

Run Tests

pytest
pytest --cov=ragaeval  # With coverage

License

MIT License - see LICENSE file for details.

Version

Current version: 0.1.0

Check installed version:

import ragaeval
print(ragaeval.__version__)

Or via CLI:

ragaeval --version

Support

For issues and questions, please file an issue on the GitHub repository.

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

ragaeval-0.1.3.tar.gz (23.2 kB view details)

Uploaded Source

Built Distribution

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

ragaeval-0.1.3-py3-none-any.whl (24.1 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: ragaeval-0.1.3.tar.gz
  • Upload date:
  • Size: 23.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.9

File hashes

Hashes for ragaeval-0.1.3.tar.gz
Algorithm Hash digest
SHA256 24fe1ca4ea72cac914dc8296a3738310840e88ebc182fa4acc9d055abf8f4e40
MD5 c3251e47ad08bb1420c0b98c73f1d92c
BLAKE2b-256 c07a04252322b099df11ede2419bf710ce93490eeb99750e8b9ac7705a076c68

See more details on using hashes here.

File details

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

File metadata

  • Download URL: ragaeval-0.1.3-py3-none-any.whl
  • Upload date:
  • Size: 24.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.9

File hashes

Hashes for ragaeval-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 0f37a20551b4972d5ddfdfa3e73ec8183bf077f1abae5a020427eba856e7a15f
MD5 95fc2cb5d8f2b5e0829b87c453eabb4a
BLAKE2b-256 4efad192b889a6fb581f916aef0eb788352ce35b2a8bf288c057c185905efdb3

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