MODULE m2 · 8.0 HOURS

Evaluation Document Corpus Curation

0% complete

LEARNING OBJECTIVES

Module objectives

  1. Understand the importance of a fixed document corpus for RAG evaluation.
  2. Learn the quality determination factors (accuracy, diversity, de-duplication) for evaluation document data.
  3. Master strategies for building Document-Question-Answer pair (QA Pair) datasets for quantitative evaluation.
  4. Learn training/evaluation split methods to prevent data leakage.

Corpus Curation for RAG Evaluation

Large Language Models (LLMs) carry a risk of Hallucination when relying on knowledge within learned parameters. Retrieval-Augmented Generation (RAG) overcomes this limitation by allowing models to access external knowledge in real-time [S2]. A Fixed Evaluation Corpus that is controlled and stable is essential to quantitatively evaluate the reliability of an effective RAG system.

1. Corpus Quality Determination Factors

  • Factuality: Information within documents must be up-to-date and factual. A corpus containing incorrect information leads to the generation of incorrect answers.
  • Domain Suitability: It must include topics and vocabulary similar to the actual service environment being evaluated.
  • De-duplication: If identical information is duplicated across multiple documents, it hinders retrieval result diversity and introduces bias into evaluation statistics.

2. Building QA Evaluation Datasets

Evaluation is impossible with only a document corpus. You must build ‘Document-Question-Answer’ pairs to measure whether the retriever brings in relevant documents and whether the generator provides accurate answers based on them.

  • Question Generation: Automatically generate questions from documents using an LLM, or have them written directly by domain experts.
  • Answer Definition: Clearly specify the document segment (Chunk) that serves as the evidence for the answer.

3. Data Splitting and Integrity

For evaluation set reliability, you must strictly split the data into a Development Set and a Hold-out Test Set. You must prevent ‘data leakage’, where questions in the evaluation set are directly exposed because they are contained in the retrieval target documents.

WORKED EXAMPLES

Worked examples

  1. Example 1: Document Chunking strategy. How to write Python scripts that divide text into fixed sizes, such as by paragraph or semantic unit, so context is not broken.
  2. Example 2: Question-Answer data construction. Example of generating a JSON object in the format { 'question': '...', 'ground_truth': '...', 'context_chunk_id': '...' }.

LAB PROTOCOL

Evaluation Corpus Construction Practice

  1. 1

    Obtain open-license text files (.txt) in the domain to be evaluated.

  2. 2

    Write a script using Python to read text files and divide them into chunk units.

  3. 3

    Assign a unique identifier (ID) to each chunk and record metadata (title, source).

  4. 4

    Generate questions from the created chunks and compose 50 QA pairs by recording the Chunk ID that serves as the evidence for the answer.

  5. 5

    Divide and save the entire corpus into development and test sets in an 8:2 ratio.

Safety check
  • Do not include documents containing personal information in the evaluation corpus.
  • Control costs by setting request limits when using external APIs.
  • Manage versions of data generated during work via Git to ensure reproducibility.

Lab deliverables

  • Constructed document corpus file (JSONL format)
  • QA dataset containing questions and answers (JSON format)
  • Jupyter Notebook file containing corpus split records

ASSIGNMENT

Domain-based RAG Dataset Completion

Deliverables

Rubric

  • Completion of duplicate chunk removal in the corpus
  • Verification of data leakage between test and development sets
  • Accurate mapping of document segments (Chunk ID) serving as evidence for answers

KNOWLEDGE CHECK

Knowledge check

1What is the best way to prevent 'Data Leakage' in a RAG system?
2Why is 'de-duplication' important during the corpus curation process?

FIELD CHECK

Completion criteria

  • Evaluation document corpus (at least 100 chunks) construction complete
  • Verifiable QA dataset (at least 100 questions) generation complete
  • Confirmation of adherence to dataset splitting policy
  • Peer review or self-evaluation checklist completed for results

MODULE SOURCES

Module sources

  1. Natural Language Processing with Deep Learning CS224N/Ling284web.stanford.edu · university