Implementation:Explodinggradients Ragas InMemoryBackend Class
Appearance
| Knowledge Sources | |
|---|---|
| Domains | Storage, Backend |
| Last Updated | 2026-02-10 00:00 GMT |
Overview
Non-persistent in-memory backend for temporary storage of datasets and experiments with deep-copy isolation.
Description
InMemoryBackend implements BaseBackend to store datasets and experiments in Python dictionaries. Data is deep-copied on save and load to ensure instance isolation. This backend is suitable for testing, prototyping, and transient workflows where persistence is not required.
Usage
Use this backend when you need temporary storage during a single session, such as testing metrics or running experiments without disk I/O.
Code Reference
Source Location
- Repository: Explodinggradients_Ragas
- File: src/ragas/backends/inmemory.py
- Lines: 11-131
Signature
class InMemoryBackend(BaseBackend):
def __init__(self) -> None:
...
def load_dataset(self, name: str) -> List[Dict[str, Any]]:
...
def load_experiment(self, name: str) -> List[Dict[str, Any]]:
...
def save_dataset(self, name: str, data: List[Dict[str, Any]], data_model: Optional[Type[BaseModel]] = None) -> None:
...
def save_experiment(self, name: str, data: List[Dict[str, Any]], data_model: Optional[Type[BaseModel]] = None) -> None:
...
def list_datasets(self) -> List[str]:
...
def list_experiments(self) -> List[str]:
...
Import
from ragas.backends.inmemory import InMemoryBackend
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 (deep-copied) |
| data_model | Optional[Type[BaseModel]] | No | Pydantic model for validation context |
Outputs
| Name | Type | Description |
|---|---|---|
| load returns | List[Dict[str, Any]] | Deep copy of stored records |
| list returns | List[str] | Sorted list of stored names |
Usage Examples
from ragas.backends.inmemory import InMemoryBackend
backend = InMemoryBackend()
# Save a dataset
backend.save_dataset("my_dataset", [{"question": "What is AI?", "answer": "Artificial Intelligence"}])
# Load it back
data = backend.load_dataset("my_dataset")
print(data) # [{"question": "What is AI?", "answer": "Artificial Intelligence"}]
# List datasets
print(backend.list_datasets()) # ["my_dataset"]
Related Pages
Page Connections
Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment