Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,14 @@ ENABLE_GENUI=1

# Optional LangSmith dashboard. Traces include questions, evidence and model outputs.
LANGSMITH_API_KEY=
LANGSMITH_PROJECT=techqa-rag
LANGSMITH_PROJECT="TechQA / Pipeline / Live"
LANGSMITH_TRACING=true

# Select groq or tokenharbor for generation.
RAG_LLM_PROVIDER=groq
TOKENHARBOR_BASE_URL=https://tokenharbor.ai/v1
TOKENHARBOR_MODEL=deepseek-v4.1-flash:free
TOKENHARBOR_API_KEY=

# TokenHarbor reasoning mode. Change only for a separately labeled comparison.
RAG_THINKING=disabled
26 changes: 26 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,32 @@ Set `EVAL_BUDGET_FILE` to a shared ledger path to enforce the $0.50 token-value

Style rubrics and broad toxicity/PII/jailbreak evaluation are also planned. Existing origin/session, withholding and generated-component checks cover specific application contracts; they are not a comprehensive safety benchmark. Optional semantic metrics compare against available references, which may omit valid alternative answers.

### Reasoning comparison after trace verification

The [structured recheck](evaluations/results/layered_audit_10.json) evaluates saved generations from the same ten training questions. Evidence, prompts and the 6,000-token output cap were held fixed. Both arms use the same reasoning-disabled judge. The clean pass reused **422 judgments** and made **19 new judge requests**, with zero judge errors.

| Measure | Reasoning off | Reasoning on |
|---|---:|---:|
| Released answers / 10 | 7 | 6 |
| Generation errors / 10 | 0 | 3 |
| Median recorded generation time | 8.73 s | 19.13 s |
| Reported generation tokens | 107,269 | 143,141 |
| Reference F1, five shared released answers | 33.6% | 50.2% |
| Faithfulness, same five answers | 100.0% | 97.1% |

Reasoning stays disabled under the current output cap. All three reasoning-on errors were truncations. The five-case reference improvement requires a larger independent sample before a broader quality claim. Generation timings come from the saved executions. Replay spans report evaluation time and retain original generation durations in their outputs. The provider did not report reasoning-token counts.

The recheck has **24 question chains, 23 threads and 136 metric verdicts**, with zero missing verdict outputs, thread IDs or reported LLM costs. The two workflow turns share a thread. All **144 metric status cells** are present, including eight metrics outside the component/workflow scoring scope. Reference-score review continues around answer scope, version conditions and bundled claims. The combined audit/comparison ledger reached **$0.392/$0.50** of standard-route token value, with one unresolved reservation. The selected free route records zero billed cost.

### Reading evaluation traces

- Each question opens as one chain. Expand the saved pipeline stages, then each RAGAS metric and its judge steps. Conversation turns share a thread ID. Imported child timestamps have zero duration; their outputs retain the original measured duration.
- Each metric reports its score and status. The categorical `ragas_status_*` fields show success, skipped, not run, error, budget exhausted, undefined or needs review. A missing score stays empty. A zero score records a completed judgment with a zero result.
- Context precision judges each passage, so seven passages can require seven judge calls. Faithfulness uses statement extraction and checking. Relevancy uses three generated questions. Reference F1 uses claim extraction and checking in both directions. Cached judgments report zero HTTP calls.
- The TokenHarbor free route reports explicit `$0.00` billed cost. The shared budget ledger separately tracks standard-route token value. Unknown prices stay unknown. Cache and available reasoning-token counts are recorded.
- Completed traces rejected further updates in the current backend. Earlier flat imports remain archived. Replacement imports preserve saved answers and scores, with complete verdicts and parent/child links created together.
- Set `RAG_THINKING=disabled` for the current serving configuration. Use `enabled` only in a separately labeled fixed-evidence comparison. Generation mode is part of the answer-cache identity. The judge stays fixed while generation reasoning changes.

### Bounded generation comparison with prompt version 6

The [saved comparison](evaluations/results/generation_v6.json) keeps the same 30 questions, references and source passages. The updated flow uses one writer, code-only display of valid writer-selected citation IDs and one verifier. A failed factual check withholds the answer. Code formatted citations in **21/30** cases, so prompt changes alone did not solve citation output.
Expand Down
315 changes: 315 additions & 0 deletions evaluations/results/layered_audit_10.json
Original file line number Diff line number Diff line change
Expand Up @@ -612,5 +612,320 @@
"provenance": {
"scorer_sha256": "4024b7d7422acb2e166f5cf366476e29df778d6a0845425510fe4cc18f9ae00d",
"pipeline_manifest_sha256": "4c69828bb542728f0915e4ead1a88319bc8b445ce9b5e05199c8782a7ba63883"
},
"structured_recheck": {
"run_date": "2026-11-11",
"scope": "Fixed ten training-tuning questions, identical saved evidence and 6000-token generation output cap. Reasoning-on uses provider default effort. The clean evaluation reused saved generations and valid cached judgments after tracing verification.",
"judge": "deepseek-v4.1-flash:free, thinking disabled in both arms",
"limitations": [
"Small training sample",
"Same model family writes and judges",
"Reasoning token breakdown unavailable from provider",
"Latency is observational and includes failures",
"Three reasoning-on truncations limit the comparison; conclusions apply to the current output cap",
"Saved-generation replay spans retain recorded durations separately from evaluation latency"
],
"layers": {
"off": {
"attempted": 10,
"outcomes": {
"answered": 7,
"insufficient_evidence": 2,
"needs_clarification": 1
},
"metrics": {
"context_precision": {
"success": 10,
"error": 0,
"undefined": 0,
"skipped": 0,
"budget_exhausted": 0,
"mean": 0.8385714285112444
},
"context_recall": {
"success": 10,
"error": 0,
"undefined": 0,
"skipped": 0,
"budget_exhausted": 0,
"mean": 1.0
},
"faithfulness": {
"success": 7,
"error": 0,
"undefined": 0,
"skipped": 3,
"budget_exhausted": 0,
"mean": 0.9659863945578231
},
"answer_relevancy": {
"success": 7,
"error": 0,
"undefined": 0,
"skipped": 3,
"budget_exhausted": 0,
"mean": 0.8849442137920638
},
"factual_correctness": {
"success": 7,
"error": 0,
"undefined": 0,
"skipped": 3,
"budget_exhausted": 0,
"mean": 0.40857142857142853
},
"answer_completeness": {
"success": 7,
"error": 0,
"undefined": 0,
"skipped": 3,
"budget_exhausted": 0,
"mean": 0.7857142857142857
}
}
},
"on": {
"attempted": 10,
"outcomes": {
"generation_error": 3,
"answered": 6,
"insufficient_evidence": 1
},
"metrics": {
"context_precision": {
"success": 10,
"error": 0,
"undefined": 0,
"skipped": 0,
"budget_exhausted": 0,
"mean": 0.8385714285112444
},
"context_recall": {
"success": 10,
"error": 0,
"undefined": 0,
"skipped": 0,
"budget_exhausted": 0,
"mean": 1.0
},
"faithfulness": {
"success": 6,
"error": 0,
"undefined": 0,
"skipped": 4,
"budget_exhausted": 0,
"mean": 0.9761904761904762
},
"answer_relevancy": {
"success": 6,
"error": 0,
"undefined": 0,
"skipped": 4,
"budget_exhausted": 0,
"mean": 0.9125643521285411
},
"factual_correctness": {
"success": 6,
"error": 0,
"undefined": 0,
"skipped": 4,
"budget_exhausted": 0,
"mean": 0.4183333333333334
},
"answer_completeness": {
"success": 6,
"error": 0,
"undefined": 0,
"skipped": 4,
"budget_exhausted": 0,
"mean": 0.75
}
}
},
"component": {
"attempted": 2,
"outcomes": {
"answered": 2
},
"metrics": {
"faithfulness": {
"success": 2,
"error": 0,
"undefined": 0,
"skipped": 0,
"budget_exhausted": 0,
"mean": 1.0
},
"answer_relevancy": {
"success": 2,
"error": 0,
"undefined": 0,
"skipped": 0,
"budget_exhausted": 0,
"mean": 0.8169765529503135
},
"factual_correctness": {
"success": 2,
"error": 0,
"undefined": 0,
"skipped": 0,
"budget_exhausted": 0,
"mean": 0.25
},
"answer_completeness": {
"success": 2,
"error": 0,
"undefined": 0,
"skipped": 0,
"budget_exhausted": 0,
"mean": 1.0
}
}
},
"workflow": {
"attempted": 2,
"outcomes": {
"answered": 2
},
"metrics": {
"faithfulness": {
"success": 2,
"error": 0,
"undefined": 0,
"skipped": 0,
"budget_exhausted": 0,
"mean": 1.0
},
"answer_relevancy": {
"success": 2,
"error": 0,
"undefined": 0,
"skipped": 0,
"budget_exhausted": 0,
"mean": 0.9418714459143624
},
"factual_correctness": {
"success": 2,
"error": 0,
"undefined": 0,
"skipped": 0,
"budget_exhausted": 0,
"mean": 0.7350000000000001
},
"answer_completeness": {
"success": 2,
"error": 0,
"undefined": 0,
"skipped": 0,
"budget_exhausted": 0,
"mean": 1.0
}
}
}
},
"generation_operations": {
"off": {
"cases": 10,
"median_generation_seconds": 8.726474104500312,
"reported_generation_tokens": 107269,
"generation_errors": {}
},
"on": {
"cases": 10,
"median_generation_seconds": 19.133343312500074,
"reported_generation_tokens": 143141,
"generation_errors": {
"output_truncated": 3
}
}
},
"paired_released_cases": {
"count": 5,
"question_ids": [
"TRAIN_Q425",
"TRAIN_Q376",
"TRAIN_Q013",
"TRAIN_Q361",
"TRAIN_Q310"
],
"metrics": {
"faithfulness": {
"off": 1.0,
"on": 0.9714285714285714
},
"answer_relevancy": {
"off": 0.9069352095509547,
"on": 0.9002108346996028
},
"factual_correctness": {
"off": 0.33599999999999997,
"on": 0.502
},
"answer_completeness": {
"off": 0.7,
"on": 0.9
}
}
},
"observability": {
"off": {
"roots": 10,
"threads": 10,
"metric_verdicts": 60,
"missing_outputs": 0,
"missing_threads": 0,
"llm_spans": 0,
"missing_costs": 0,
"status_cells": 60,
"billed_cost": 0
},
"on": {
"roots": 10,
"threads": 10,
"metric_verdicts": 60,
"missing_outputs": 0,
"missing_threads": 0,
"llm_spans": 19,
"missing_costs": 0,
"status_cells": 60,
"billed_cost": 0.0
},
"component": {
"roots": 2,
"threads": 2,
"metric_verdicts": 8,
"missing_outputs": 0,
"missing_threads": 0,
"llm_spans": 0,
"missing_costs": 0,
"status_cells": 12,
"billed_cost": 0
},
"workflow": {
"roots": 2,
"threads": 1,
"metric_verdicts": 8,
"missing_outputs": 0,
"missing_threads": 0,
"llm_spans": 0,
"missing_costs": 0,
"status_cells": 12,
"billed_cost": 0
}
},
"execution": {
"judge_cache_hits": 422,
"judge_cache_misses": 19,
"http_attempts": 19,
"embedding_cache": {
"query_cache_hits": 61,
"query_cache_misses": 7
},
"standard_route_value_usd_including_prior_audit": 0.39192151199999997,
"budget_usd": 0.5,
"unresolved_reservations": 1,
"free_route_billed_cost_usd": 0
},
"decision": "Keep reasoning disabled under the current output cap. Review answer scope and reference/judge alignment before another generation change."
}
}
5 changes: 3 additions & 2 deletions rag_app/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,8 @@ def run_worker():
'index': retrieve.index_identity() if hasattr(retrieve, 'index_identity') else 'injected_test_index',
'model': provider.model if provider else MODEL,
'prompt': PROMPT_VERSION, 'generation': {'provider': provider.provider if provider else 'injected',
'max_output_tokens': provider.max_tokens if provider else 1500}}
'max_output_tokens': provider.max_tokens if provider else 1500,
'thinking': getattr(provider, 'thinking', None)}}
cached = None if regen or result else answers.get(session.id, identity, session_expires_at=session.expires_at)
if cached:
result = dict(cached)
Expand Down Expand Up @@ -356,7 +357,7 @@ def run_worker():
emit('done', {})

def worker():
with trace_span('Pipeline / Question', inputs={'question': body.question, 'regenerate': body.regenerate}, run_id=uuid.UUID(rid), metadata={'model': os.getenv('TOKENHARBOR_MODEL', MODEL) if os.getenv('RAG_LLM_PROVIDER') == 'tokenharbor' else MODEL, 'prompt_version': PROMPT_VERSION, 'pipeline_sha256': pipeline_version()}) as run:
with trace_span('Pipeline / Question', inputs={'question': body.question, 'regenerate': body.regenerate}, run_id=uuid.UUID(rid), metadata={'model': os.getenv('TOKENHARBOR_MODEL', MODEL) if os.getenv('RAG_LLM_PROVIDER') == 'tokenharbor' else MODEL, 'prompt_version': PROMPT_VERSION, 'pipeline_sha256': pipeline_version(), 'thread_id': 'TechQA / session / ' + hashlib.sha256(session.id.encode()).hexdigest()[:24]}) as run:
run_worker()
if run and not run.outputs:
run.end(outputs={'status': 'cancelled_or_timed_out'})
Expand Down
Loading
Loading