Implementation:Explodinggradients Ragas LocalJSONLBackend Class
Appearance
| Knowledge Sources | |
|---|---|
| Domains | Storage, Backend |
| Last Updated | 2026-02-10 00:00 GMT |
Overview
File-based storage backend using JSONL format for local persistence with data type preservation and datetime handling.
Description
LocalJSONLBackend implements BaseBackend to store data as JSONL (JSON Lines) files on the local filesystem. Unlike the CSV backend, it preserves nested structures and supports datetime serialization/deserialization. Each line in the file is a valid JSON object.
Usage
Use this backend when you need persistent local storage with support for complex nested data structures and datetime fields.
Code Reference
Source Location
- Repository: Explodinggradients_Ragas
- File: src/ragas/backends/local_jsonl.py
- Lines: 13-206
Signature
class LocalJSONLBackend(BaseBackend):
def __init__(self, root_dir: str) -> None:
...
Import
from ragas.backends.local_jsonl import LocalJSONLBackend
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| root_dir | str | Yes | Root directory for JSONL storage |
| name | str | Yes | Name of the dataset or experiment |
| data | List[Dict[str, Any]] | Yes | Records to save as JSONL lines |
Outputs
| Name | Type | Description |
|---|---|---|
| load returns | List[Dict[str, Any]] | Records with datetime fields deserialized |
| list returns | List[str] | Sorted list of JSONL file names (without extension) |
Usage Examples
from ragas.backends.local_jsonl import LocalJSONLBackend
from datetime import datetime
backend = LocalJSONLBackend(root_dir="./my_data")
# Save a dataset with nested data and datetime
backend.save_dataset("eval_results", [
{
"question": "What is AI?",
"contexts": ["AI is a field of computer science.", "AI simulates human intelligence."],
"score": 0.85,
"evaluated_at": datetime.now(),
},
])
# Load the dataset (datetime is preserved)
data = backend.load_dataset("eval_results")
print(data[0]["evaluated_at"]) # datetime object
Related Pages
Page Connections
Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment