Eval Framework + Small LLMs improvements

Merged
SO
1y ago
+11028-43

Key changes

  1. Removed response_format: { type: "json_object" } for localLLMs
  2. Simplified prompts with few-shot examples that the smaller model could follow
  3. Flexible JSON parsing that can extract JSON from various response formats
  4. Fuzzy category matching to handle minor naming variations
  5. Smaller batch sizes (5 instead of 25) to reduce context length

Extra changes:
Options: "strict", "json_object", "none"
LLM_JSON_MODE=json_object bin/rails 'evals:run[...]'

JSON Modes Explained

ModeDescriptionUse Case
strictFull JSON schema with strict: trueOpenAI API, large models with schema support
json_objectSimple { type: "json_object" } formatModels with basic JSON mode (e.g., some vLLM setups)
noneNo response format constraintLocal LLMs without JSON mode support

Results

MetricBeforeAfterImprovement
Accuracy15.0%89.0%+74 points
Precision100.0%88.37%(slightly lower but with much higher coverage)
Recall2.3%98.7%+96.4 points
F1 Score4.593.25+88.75 points
Easy2.86%94.29%+91.4 points
Medium2.94%94.12%+91.2 points
Hard5.26%63.16%+57.9 points
Edge Cases100%100%Maintained

BEFORE:

By Difficulty:
  easy: 2.86% accuracy (1/35)
  medium: 2.94% accuracy (1/34)
  hard: 5.26% accuracy (1/19)
  edge_case: 100.0% accuracy (12/12)

AFTER:

By Difficulty:
	easy: 94.29% accuracy (33/35)
	medium: 94.12% accuracy (32/34)
	hard: 63.16% accuracy (12/19)
	edge_case: 100.0% accuracy (12/12)

Summary by CodeRabbit

  • New Features

    • Full evaluation toolkit: create/manage datasets, run evaluations (categorization, merchant detection, chat), export/trace to Langfuse, experiment orchestration, comparison reports, and CLI tasks.
  • Data

    • Multiple golden benchmark datasets added (categorization, merchant detection, chat; light and v2 variants).
  • Documentation / UI

    • OpenAI JSON Mode setting with UI control and translations.
  • Chores (DB)

    • New evaluation schema/tables and added alternative_match column.
  • Tests

    • New tests for dataset import and runner behavior.

✏️ Tip: You can customize this high-level summary in your review settings.