Skip to main content

RAGAS integration adapter for Metrics Computation Engine

Project description

MCE Ragas Adapter

A Python adapter library that integrates Ragas metrics as third-party plugins for the Metric Computation Engine (MCE). This adapter enables seamless use of Ragas's LLM evaluation metrics within the MCE framework for evaluating agentic applications.

Installation

pip install mce-ragas-adapter

Prerequisites

Supported Ragas Metrics

The adapter supports a wide range of Ragas metrics, including but not limited to:

  • TopicAdherenceScore - Evaluates whether the model response adheres to the intended topic from the user request.

For a complete list of supported metrics, refer to the Ragas documentation. Many metrics in this library will require context which this adapter does not yet support. As we confirm compatibility of metrics, we will add it to the above list.

Usage

Basic Usage

import asyncio
from mce_ragas_adapter.adapter import RagasMetricAdapter
from metrics_computation_engine.models.requests import LLMJudgeConfig
from metrics_computation_engine.registry import MetricRegistry

# Initialize LLM configuration
llm_config = LLMJudgeConfig(
    LLM_BASE_MODEL_URL="https://api.openai.com/v1",
    LLM_MODEL_NAME="gpt-4o",
    LLM_API_KEY="your-api-key-here"
)

# Create registry and register Ragas metrics
registry = MetricRegistry()

# Method 1: Direct registration with metric name
registry.register_metric(RagasMetricAdapter, "TopicAdherenceScore")

# Method 2: Using get_metric_class helper with prefix
from metrics_computation_engine.util import get_metric_class
metric, metric_name = get_metric_class("ragas.TopicAdherenceScore")
registry.register_metric(metric, metric_name)

Using with MCE REST API

When using the MCE as a service, include Ragas metrics in your API request:

{
  "metrics": [
    "ragas.TopicAdherenceScore"
  ],
  "llm_judge_config": {
    "LLM_API_KEY": "your-api-key",
    "LLM_MODEL_NAME": "gpt-4o",
    "LLM_BASE_MODEL_URL": "https://api.openai.com/v1"
  },
  "batch_config": {
    "num_sessions": 10
  }
}

Configuration

Environment Variables

Set up your environment variables for LLM access:

# .env file
LLM_BASE_MODEL_URL=https://api.openai.com/v1
LLM_MODEL_NAME=gpt-4o
LLM_API_KEY=sk-your-openai-api-key

Supported Aggregation Levels

The adapter maps Ragas metrics to different aggregation levels:

  • Span Level: Evaluate individual agent interactions or tool calls
  • Session Level: Evaluate complete conversation sessions

Contributing

Contributions are welcome! Please follow these steps to contribute:

  1. Fork the repository.
  2. Create a new branch (git checkout -b feature-branch).
  3. Commit your changes (git commit -am 'Add new feature').
  4. Push to the branch (git push origin feature-branch).
  5. Create a new Pull Request.

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

mce_ragas_adapter-0.1.1.tar.gz (11.9 kB view details)

Uploaded Source

Built Distribution

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

mce_ragas_adapter-0.1.1-py3-none-any.whl (13.2 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: mce_ragas_adapter-0.1.1.tar.gz
  • Upload date:
  • Size: 11.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for mce_ragas_adapter-0.1.1.tar.gz
Algorithm Hash digest
SHA256 005401be075be9e8d78c2b74d5daeb351913f40270ba278c863ca9a942373a21
MD5 cc926959144b4f2f6bda51d405e9c4ca
BLAKE2b-256 1f4017ba22f36d3ce160c7ad6a670dd5f13ebafa60c6bd9e90c3c6e0d6eda0d1

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for mce_ragas_adapter-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 59e28c3e64dd98f27cc278860807df0b5a3beda9ad5c5c73b2e7ce931b12a7d7
MD5 27fb54718dfeb70657a83dfecdf3af61
BLAKE2b-256 e0bf170e2e1ae16648173be0727b19031055555308dee440964349bab5514e8a

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