From fc87c4783a615eb2b69cab7d958d14d8697ef30c Mon Sep 17 00:00:00 2001 From: shipitdev Date: Tue, 1 Dec 2026 22:32:57 +0530 Subject: [PATCH] Refresh the TechQA pipeline and evaluation guide --- README.md | 71 ++++++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 54 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index f88e324..3b7d7a9 100644 --- a/README.md +++ b/README.md @@ -8,23 +8,44 @@ The repository contains application code, preparation/evaluation tools and offli ```text Question → Gemma embedding → Qdrant exact search → BGE reranking - → evidence selection → Groq answer → separate verification - → cited answer + checked OpenUI components + → rank fusion → evidence selection → writer → citation check → verifier + → cited answer, clarification, or insufficient evidence + → optional checked OpenUI for released answers ``` - **Retrieval:** pinned `google/embeddinggemma-2`, cosine search over structured HTML chunks, BGE reranking and reciprocal-rank fusion with the dense ranking. - **Evidence:** a bounded context pack retains source identities and coordinates. The serving retriever currently uses dense search; BM25/hybrid helpers are available for evaluation, not enabled in the live path. -- **Answers:** Groq `openai/gpt-oss-120b` writes and separately verifies an answer. One repair is allowed; unresolved evidence gaps withhold the answer. -- **Prompts:** `strict_v5_message_roles` puts task instructions in system messages and questions, evidence, drafts and repair findings in JSON user messages. Follow-ups, memory summaries and OpenUI use the same structure. Output schemas remain explicit in the provider request. +- **Answers:** One writer drafts a cited answer. Python checks its citation IDs and formats valid IDs chosen by the writer. A separate verifier checks factual support, completeness and applicability. An evidence gap withholds the answer, and a missing user detail can prompt clarification. +- **Prompts:** `strict_v8_concise_task_scope` uses short system instructions and passes questions, evidence and drafts as JSON user data. The default provider is Groq with `openai/gpt-oss-120b`. TokenHarbor with DeepSeek is configurable. - **UI:** Next.js/React and OpenUI render finding cards, steps, configuration rows and citations. All generated factual fields, including hidden tabs, are checked before release. Invalid layouts fall back to verified text. - **Sessions:** recent conversation plus a summary, current-session memory, exact answer caching and an explicit regeneration bypass. -- **Evaluation:** an offline RAGAS runner scores saved evidence and released answers. Judge decisions and local query embeddings are cached; withheld responses and evaluation errors stay visible. +- **Evaluation:** Python compares matched saved runs without model calls. A human reviews factual support, completeness and whether withholding was appropriate. Optional RAGAS checks add semantic scores to selected cases. ## Inspect a run in LangSmith -Add `LANGSMITH_API_KEY` to the server's `.env`. The default project is `techqa-rag`. Set `LANGSMITH_TRACING=false` to disable export. Traces contain questions, retrieved passages, private drafts and verification decisions, so keep this project private. +Add `LANGSMITH_API_KEY` to the server's `.env`. The example config uses `TechQA / Pipeline / Live`, and the fallback project is `techqa-rag`. Set `LANGSMITH_TRACING=false` to disable export. Traces contain questions, retrieved passages, private drafts and verification decisions, so keep this project private. -Each question has a parent trace with child steps for query embedding, exact search, reranking, context selection and model calls. Inspect timings, actual token usage, cache hits, source passages, writer/verifier decisions and the released outcome. The answer workspace links to its trace. Local diagnostic logs continue to work when tracing is disabled or export fails. +Open **Traces** and expand **Pipeline / Question**. Use **Threads** to review turns from the same session together. + +```text +Pipeline / Question +├── Resolve follow-up (when needed) +├── Exact answer cache → hit, miss or bypass +├── Retrieval +│ ├── Embed query → model, dimensions and cache status +│ ├── Qdrant exact search → ranked chunk IDs and scores +│ ├── Rerank and fuse +│ │ ├── Cross-encoder scores → scores and cache counts +│ │ └── Reciprocal rank fusion → final chunk order +│ └── Pack context → selected excerpts and token count +├── Generation +│ ├── Write → cited draft +│ ├── Check citations → format and source-ID verdict +│ └── Verify → support and completeness verdict +└── OpenUI presentation (when enabled for a released answer) +``` + +A cache hit returns the saved answer. Optional stages appear when they run. Expand model calls for reported usage. The workspace links each answer to its trace. Saved imports show recorded retrieval summaries and passage coordinates where available. The workspace streams actual activity and retrieved excerpts. Verified answers and checked OpenUI layouts appear after their release checks. The run history remains available after completion. Desktop uses a compact navigation rail, while smaller screens stack the answer and evidence. @@ -40,7 +61,7 @@ python -m scripts.publish_langsmith --cases data/ragas/review/completed.json Publishing replays saved outputs into a LangSmith experiment with response status, selected-reference-article presence and citation-format checks. It makes **zero new model calls**. Add `--ragas path/to/matching-report.json` to publish existing semantic scores too. RAGAS judging remains a separate, explicitly budgeted command below. Reviewed or failed judge results retain their flags. -The [November 10 observability batch](evaluations/results/observability_v1.json) selected **12 training questions**. Retrieval selected the labeled article for **11/12**. **3 answers** were released and passed citation-format checks. **9 provider quota failures** prevented completion. The run used **15 HTTP attempts and 33,230 reported tokens**. This batch establishes dashboard visibility and exposes a quota-handling issue, which is now covered by a stop-on-quota regression test. New semantic RAGAS scores await available provider quota. +The [November 10 observability batch](evaluations/results/observability_v1.json) was an early tracing and quota check. Retrieval selected the labeled article for **11/12** training questions. Three answers were released and nine provider quota failures prevented completion. ## Feedback and future evaluation cases @@ -62,19 +83,35 @@ Approval and review notes are required for feedback-based RAGAS evaluation. Use ![Evaluation layers: components, pipeline, application, regression and planned monitoring](evaluations/overview.svg) -The suite records retrieval quality, generated-answer quality and API workflow behavior. RAGAS supplies semantic judgments. Python checks source/citation contracts, session/cache behavior, recorded usage and paired regressions. +The suite records retrieval, answer and API workflow behavior. Python checks source and citation contracts, session and cache behavior, recorded usage and paired changes. Human review decides whether a change improved answer quality. RAGAS remains available for optional, budgeted semantic diagnostics. | Layer | What we check | Implemented measurements | |---|---|---| | Component | Retriever ranking and generator with supplied original article evidence | Recall@K, MRR and nDCG in the retrieval benchmark. Two supplied-evidence generator cases scored with RAGAS faithfulness, relevancy and reference metrics. | -| Pipeline | Actual retrieved context through writing and verification | Ten fixed training questions. All six metric types scored for eligible cases, with explicit skipped/error states and denominators. | +| Pipeline | Actual retrieved context through writing and verification | Document selection, citation contract and answer outcomes on matched cases. Historical RAGAS runs include explicit scored, skipped and error counts. | | Workflow | API conversation turns, follow-up resolution and exact answer caching | Two real API turns scored with RAGAS. Same-session follow-up and repeated-question cache checks also run. [Layer collector](scripts/eval_layers.py). | | Regression | Matched cases and references | [Comparison CLI](scripts/eval_suite.py) checks cohort and judge identity. The saved v5/v6 outputs were rescored with the same DeepSeek judge. | | Online | Feedback and run inspection | LangSmith traces, user ratings and reviewed regression exports. Live sampled judging and drift monitoring are planned. | -### Ten-question evaluation audit +### Current prompt comparison + +V6 and V8 used the same ten training questions, IBM references, saved evidence, DeepSeek model and reasoning setting. The report reused the saved outputs and made zero model calls. + +| Check | V6 | V8 | +|---|---:|---:| +| Labeled article in selected evidence | 10/10 | 10/10 | +| Released answers | 7/10 | 7/10 | +| Released answers passing the citation contract | 7/7 | 7/7 | +| Generation errors | 0 | 0 | +| Reported generation tokens | 107,269 | 95,871 | + +Four questions changed outcome. V8 released two answers that V6 withheld or asked to clarify, and withheld two that V6 released. Human review of those changes is pending. The citation contract checks format and source IDs. Broader answer quality needs a reserved evaluation. + +For the next experiment, save a baseline, state the hypothesis and change one part. Use the same questions and references, and hold evidence fixed for prompt comparisons. Run the [offline comparison](#try-the-suite-without-a-model-or-dataset) and review changed answers and withheld cases before promoting the change. Use Git to revert a code or prompt change and [activate a previous build](#update-documents-and-roll-back) to roll back the data index. + +### Historical ten-question RAGAS audit -The [redacted audit](evaluations/results/layered_audit_10.json) uses the first ten IDs from the fixed training sample. Today's writer, verifier and judge use TokenHarbor `deepseek-v4.1-flash:free`. Historical v5/v6 outputs retain their original Groq model attribution. The judge passed supported/unsupported faithfulness sanity checks at 1.0/0.0. +The [redacted audit](evaluations/results/layered_audit_10.json) uses the first ten IDs from the fixed training sample. Its writer, verifier and judge used TokenHarbor `deepseek-v4.1-flash:free`. Earlier Groq runs retain their original model attribution. The judge scored supported and unsupported calibration answers at 1.0 and 0.0. | Metric | DeepSeek pipeline mean | Scored / eligible | |---|---:|---:| @@ -238,7 +275,7 @@ The report checks selected-document hits, citation contracts and outcomes. It do ## Requirements -Python 3.13, Node.js 22, npm, uv, Docker Compose, a Groq API key, and prepared TechQA/model artifacts. The frontend and API run locally; Qdrant runs in Docker. +Python 3.13, Node.js 22, npm, uv, Docker Compose, a Groq or TokenHarbor API key, and prepared TechQA/model artifacts. The frontend and API run locally with Qdrant in Docker. ### Run the offline checks first @@ -267,7 +304,7 @@ uv pip install --python .venv-ingest/bin/python -r requirements-app.txt cp .env.example .env ``` -Set `GROQ_API_KEY` in the root `.env`. Existing installations can use the `GROK_API_KEY` alias. Keep the key server-side; do not use a `NEXT_PUBLIC_` variable. +Set `GROQ_API_KEY` in the root `.env` for the default Groq provider. Existing installations can use the `GROK_API_KEY` alias. For TokenHarbor, set `RAG_LLM_PROVIDER=tokenharbor` and `TOKENHARBOR_API_KEY`. The example config pins the base URL, model and reasoning setting. Keep provider keys server-side. The model namespace starts with `openai/`, but requests go to **Groq's API**. The model is configured centrally in `rag_app/generation.py`. @@ -415,7 +452,7 @@ Choose metrics for the change you are investigating: - Retrieval/context change: `--metrics context_precision context_recall`. - Answer-writing change: `--metrics faithfulness answer_relevancy`. -- Reference-based application review: `--metrics factual_correctness answer_completeness` (opt-in; no pilot scores yet). +- Reference-based application review: `--metrics factual_correctness answer_completeness` (opt-in). The default scoring limit is three cases and **12 HTTP attempts, including retries**. Set `--max-requests 0` for cache-only execution; missing decisions become `budget_exhausted`, not zero quality. Use a fresh `--output` for a comparison; omitted output names are timestamped so earlier reports survive. These are request caps, **not a dollar/token spending guarantee**. Inspect actual usage before raising them; one metric can make several calls. @@ -433,9 +470,9 @@ Failed evaluations are not zero scores; answer metrics are skipped on withheld c ## Operating limits - Intended for controlled local/demo use. Authentication and a public multi-user deployment are not implemented. -- Sessions and answer caches are process-local. Persistent query/pair caches need an eviction policy before sustained public traffic. +- Sessions and the exact answer cache are scoped to the local service. Persistent query and reranker caches have size limits. - Requests have queue, rate and deadline controls. Groq quota waits can dominate latency. - Verified components appear progressively after checking; unverified draft tokens are not streamed to users. -- Backup restoration, broader answer-quality evaluation and production load testing remain separate work. +- Local backup restoration has been tested. Reserved answer-quality evaluation and production load testing are pending. The initial history is a reconstructed import of local build stages from October 28–November 3, 2026. Author and committer dates identify those reconstructed stages; the repository was first published on November 3, 2026. It is not an archive of the exact working tree at each historical moment. Subsequent commits record ongoing development normally.