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.3.1.tar.gz (42.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.3.1-py3-none-any.whl (43.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: ragaeval-0.3.1.tar.gz
  • Upload date:
  • Size: 42.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.3.1.tar.gz
Algorithm Hash digest
SHA256 1807d10a149f3d5b5319a2e5b82f55009df97eae249d34f5cc296a32244ba470
MD5 4e5c3e0ed6221119d030a6838249ec94
BLAKE2b-256 b4877eac66356cc50fe068f37a6a357b44c6c17f27a55c793e373a679133427b

See more details on using hashes here.

File details

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

File metadata

  • Download URL: ragaeval-0.3.1-py3-none-any.whl
  • Upload date:
  • Size: 43.8 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.3.1-py3-none-any.whl
Algorithm Hash digest
SHA256 a9fed098c46f54457aa88a048d72d9c884374b7fcbc70a717035f85edde07a8a
MD5 f051db1992a204d7443254dfe0d3f903
BLAKE2b-256 5857185e40f439202b9d3d60e8d95fa34fa2b23502e8266239de846d100d6b2c

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