Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:Explodinggradients Ragas BaseBackend Class

From Leeroopedia


Knowledge Sources
Domains Storage, Backend
Last Updated 2026-02-10 00:00 GMT

Overview

Abstract base class defining the contract all storage backends must implement for persisting datasets and experiments.

Description

BaseBackend is an abstract class from the Ragas backends module that establishes the standard interface for storage backends. All concrete backends (InMemory, CSV, JSONL, Google Drive) must implement this contract. It defines six abstract methods for loading, saving, and listing both datasets and experiments.

Usage

Extend this class when creating a custom storage backend for Ragas. Implement all six abstract methods to provide persistent storage for datasets and experiments.

Code Reference

Source Location

Signature

class BaseBackend(ABC):
    @abstractmethod
    def load_dataset(self, name: str) -> List[Dict[str, Any]]:
        ...
    @abstractmethod
    def load_experiment(self, name: str) -> List[Dict[str, Any]]:
        ...
    @abstractmethod
    def save_dataset(self, name: str, data: List[Dict[str, Any]], data_model: Optional[Type[BaseModel]] = None) -> None:
        ...
    @abstractmethod
    def save_experiment(self, name: str, data: List[Dict[str, Any]], data_model: Optional[Type[BaseModel]] = None) -> None:
        ...
    @abstractmethod
    def list_datasets(self) -> List[str]:
        ...
    @abstractmethod
    def list_experiments(self) -> List[str]:
        ...

Import

from ragas.backends.base import BaseBackend

I/O Contract

Inputs

Name Type Required Description
name str Yes Name identifier for the dataset or experiment
data List[Dict[str, Any]] Yes List of records to save
data_model Optional[Type[BaseModel]] No Pydantic model for validation context

Outputs

Name Type Description
load_dataset returns List[Dict[str, Any]] Loaded dataset records
load_experiment returns List[Dict[str, Any]] Loaded experiment records
list_datasets returns List[str] Sorted list of dataset names
list_experiments returns List[str] Sorted list of experiment names

Usage Examples

Custom Backend Implementation

from ragas.backends.base import BaseBackend
from typing import Any, Dict, List, Optional, Type
from pydantic import BaseModel

class MyCustomBackend(BaseBackend):
    def __init__(self):
        self._store = {}

    def load_dataset(self, name: str) -> List[Dict[str, Any]]:
        if name not in self._store:
            raise FileNotFoundError(f"Dataset '{name}' not found")
        return self._store[name]

    def save_dataset(self, name: str, data: List[Dict[str, Any]], data_model: Optional[Type[BaseModel]] = None) -> None:
        self._store[name] = data

    def load_experiment(self, name: str) -> List[Dict[str, Any]]:
        raise FileNotFoundError(f"Not implemented")

    def save_experiment(self, name: str, data: List[Dict[str, Any]], data_model: Optional[Type[BaseModel]] = None) -> None:
        pass

    def list_datasets(self) -> List[str]:
        return sorted(self._store.keys())

    def list_experiments(self) -> List[str]:
        return []

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment