LightRAG/lightrag
anouarbm 026bca00d9 fix: Use actual retrieved contexts for RAGAS evaluation
**Critical Fix: Contexts vs Ground Truth**
- RAGAS metrics now evaluate actual retrieval performance
- Previously: Used ground_truth as contexts (always perfect scores)
- Now: Uses retrieved documents from LightRAG API (real evaluation)

**Changes to generate_rag_response (lines 100-156)**:
- Remove unused 'context' parameter
- Change return type: Dict[str, str] → Dict[str, Any]
- Extract contexts as list of strings from references[].text
- Return 'contexts' key instead of 'context' (JSON dump)
- Add response.raise_for_status() for better error handling
- Add httpx.HTTPStatusError exception handler

**Changes to evaluate_responses (lines 180-191)**:
- Line 183: Extract retrieved_contexts from rag_response
- Line 190: Use [retrieved_contexts] instead of [[ground_truth]]
- Now correctly evaluates: retrieval quality, not ground_truth quality

**Impact on RAGAS Metrics**:
- Context Precision: Now ranks actual retrieved docs by relevance
- Context Recall: Compares ground_truth against actual retrieval
- Faithfulness: Verifies answer based on actual retrieved contexts
- Answer Relevance: Unchanged (question-answer relevance)

Fixes incorrect evaluation methodology. Based on RAGAS documentation:
- contexts = retrieved documents from RAG system
- ground_truth = reference answer for context_recall metric

References:
- https://docs.ragas.io/en/stable/concepts/components/eval_dataset/
- https://docs.ragas.io/en/stable/concepts/metrics/
2025-11-02 16:16:00 +01:00
..
api Add PDF decryption support for password-protected files 2025-11-01 15:01:17 +08:00
evaluation fix: Use actual retrieved contexts for RAGAS evaluation 2025-11-02 16:16:00 +01:00
kg Add Qdrant legacy collection migration with workspace support 2025-10-30 19:16:33 +08:00
llm Add offline deployment support with cache management and layered deps 2025-10-11 10:28:14 +08:00
tools Add offline deployment support with cache management and layered deps 2025-10-11 10:28:14 +08:00
__init__.py Bump core version to 1.4.9.8 and API version to 0250 2025-10-31 05:23:48 +08:00
base.py Fix RayAnything compatible problem 2025-10-22 20:15:29 +08:00
constants.py Refactor entity merging with unified attribute merge function 2025-10-27 00:04:17 +08:00
exceptions.py Add Qdrant legacy collection migration with workspace support 2025-10-30 19:16:33 +08:00
lightrag.py Fix edge cleanup when deleting entities to prevent orphaned relationships 2025-10-31 02:36:15 +08:00
namespace.py Add entity/relation chunk tracking with configurable source ID limits 2025-10-20 15:24:15 +08:00
operate.py Rename function and variables for clarity in context building 2025-11-01 12:15:24 +08:00
prompt.py Fix typo in 'equipment' in prompt.py 2025-10-22 11:13:22 +08:00
rerank.py
types.py
utils.py Enhance entity/relation editing with chunk tracking synchronization 2025-10-26 14:34:56 +08:00
utils_graph.py Improve entity merge logging by removing redundant message and fixing typo 2025-10-31 17:16:59 +08:00