Documentation Index
Fetch the complete documentation index at: https://mintlify.com/JhonHander/obstetrics-rag-benchmark/llms.txt
Use this file to discover all available pages before exploring further.
Utils Module
Theutils.py module provides utility functions for exporting RAGAS evaluation results to various file formats.
Overview
Located atsrc/common/utils.py, this module contains helper functions for:
- Exporting RAGAS results to CSV and Excel formats
- Merging performance metadata with evaluation results
- Automated timestamp-based file naming
Functions
export_ragas_analysis()
Export RAGAS evaluation results to CSV and optionally Excel files with performance metadata.RAGAS evaluation result object (must support
.to_pandas() method)Short label used in the output file names (e.g., “hybrid_gpt4o”)
Directory where files will be saved. If not specified, defaults to the project’s
results/ directory.Optional list of per-question performance dictionaries containing:
execution_time: Time taken for query executioninput_tokens: Number of input tokens consumedoutput_tokens: Number of output tokens generatedtotal_cost: Total API cost for the query
Dictionary mapping file type labels to saved file paths:
"csv": Path to the CSV file (always created)"excel": Path to the Excel file (only if openpyxl is installed)
Usage Example
Output Files
File Naming Convention
Files are automatically named with the pattern:CSV Format
The CSV file includes:- All RAGAS metric columns (faithfulness, answer_relevancy, context_precision, context_recall)
- Question and answer text
- Ground truth values
- Performance metadata (if provided): execution_time, input_tokens, output_tokens, total_cost
Excel Format
The Excel file contains the same data as CSV with:- Proper column formatting
- UTF-8 encoding support
- Automatic column width adjustment (if using modern openpyxl)
Excel export requires the
openpyxl package. If not installed, only the CSV file will be created. The function silently skips Excel export without raising an error.Performance Metadata Integration
Whenperformance_metadata is provided, the function:
- Converts the list of performance dictionaries to a DataFrame
- Aligns it with the RAGAS results by row position
- Removes duplicate
questioncolumns if present - Concatenates the DataFrames horizontally
Error Handling
The function handles several edge cases:Results Object Type
Results Object Type
If the
results object doesn’t have a .to_pandas() method, raises TypeError with a descriptive message.Missing openpyxl
Missing openpyxl
If
openpyxl is not installed, silently skips Excel export and only creates CSV. No error is raised.Missing Output Directory
Missing Output Directory
Automatically creates the output directory (including parent directories) if it doesn’t exist using
mkdir(parents=True, exist_ok=True).Implementation Details
Source:src/common/utils.py:10-69
The function:
- Uses pandas for DataFrame operations
- Employs timestamp-based naming to prevent file overwrites
- Creates output directories automatically
- Handles optional dependencies gracefully
Related
- RAGASEvaluator - Generates the results objects used by this function
- Pricing - Calculates the cost values included in performance metadata
- Usage Metrics - Extracts token counts for performance tracking
