ashe0042 commited on
Commit
9629346
·
0 Parent(s):

Initial scaffold: gitignore, env, CLAUDE.md

Browse files
Files changed (2) hide show
  1. .gitignore +3 -0
  2. CLAUDE.md +171 -0
.gitignore ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ .env
2
+ __pycache__/
3
+ .venv/
CLAUDE.md ADDED
@@ -0,0 +1,171 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # CLAUDE.md — AusRegBench
2
+
3
+ > This file is read by Claude Code at the start of every session.
4
+ > It is the source of truth for scope and rules. If a request conflicts with
5
+ > this file, **stop and ask the human** before proceeding.
6
+
7
+ ## What this project is
8
+
9
+ **AusRegBench** is an open, reproducible **benchmark + diagnostic tool** that measures
10
+ where RAG systems get **Australian financial-services and prudential law** wrong —
11
+ specifically how often they (a) cite provisions that don't exist, and (b) cite real
12
+ provisions but misstate the obligation — and pinpoints **which pipeline stage**
13
+ (retrieve / augment / generate) caused each failure.
14
+
15
+ It is a **measurement instrument**, not a product. Its entire value is that its
16
+ ground truth is trustworthy. Treat it that way in every decision.
17
+
18
+ ## Frozen scope — DO NOT EXPAND
19
+
20
+ - **One domain:** Australian financial-services & prudential regulation. No other verticals.
21
+ - **Five configs** (the only configs — no sixth): naive, hybrid, rerank, KG-augmented, grounded/citation-forced.
22
+ - **One finding:** a faithfulness/stage-attribution result, e.g. "the provision was retrieved but the obligation was misstated, so the failure lives in generation, not retrieval."
23
+
24
+ The temptation to add a vertical, a sixth config, MCP, multi-agent orchestration, or
25
+ cloud deployment **mid-build** is the single biggest risk to this project shipping.
26
+ All of those are **post-ship extensions only**, added one at a time, and only if they
27
+ sharpen the finding. **If a session would add any of them, STOP and ask the human.**
28
+
29
+ ## The two human-verification non-negotiables
30
+
31
+ 1. **The gold set is human-verified.** The LLM may do the heavy lifting — surface the
32
+ relevant provision, summarise it, draft a candidate obligation, propose the citation.
33
+ But a human verifies every gold item against the actual provision text. The LLM is
34
+ never the source of truth for what the law says. (This is the whole point: we are
35
+ testing LLMs, so an LLM cannot define the correct answers — that's circular.)
36
+ 2. **The headline numbers are human-verified.** Fabrication rate, misstatement rate,
37
+ Cohen's κ, stage-attribution — the human reads the code that produces these and
38
+ spot-checks the outputs. These numbers are the findings; they cannot be vibe-checked.
39
+
40
+ ## The 90/10 coding rule
41
+
42
+ - **Vibe-code the ~90% where a bug looks wrong** (Streamlit dashboard, config plumbing,
43
+ DeepEval wiring, run scripts). Go fast, hands-off.
44
+ - **Human-verify the ~10% where a bug looks correct.** Specifically:
45
+ - **Clause-aware chunking that preserves paragraph IDs.** A misaligned ID silently
46
+ corrupts every downstream citation check. Spot-check chunks against the source by eye.
47
+ - **The deterministic citation-checker (regex).** A parsing edge-case bug prints a
48
+ clean, wrong number.
49
+ - **The κ computation.** Verify label arrays are aligned before trusting the value.
50
+
51
+ ## Locked stack
52
+
53
+ - **Language:** Python 3.11. Pin dependencies (lockfile). Set seeds for reproducibility.
54
+ - **Orchestration:** LangChain (pipelines) + LangGraph (the agentic / KG-augmented config).
55
+ - **Vector DB:** **Neon** (managed serverless Postgres) + **pgvector**. No local Docker.
56
+ - **Embeddings:** default `text-embedding-3-large` (OpenAI); plus **BGE-large** (open) for
57
+ the "embedding choice changes results" comparison.
58
+ - **Retrieval:** BM25 (Postgres FTS or `rank_bm25`) + dense; combine with Reciprocal Rank Fusion.
59
+ - **Reranker:** a cross-encoder (e.g. `bge-reranker`) or Cohere Rerank.
60
+ - **Generation models (systems under test) — pick current versions at build time:**
61
+ - Frontier closed: GPT-5.x (OpenAI API)
62
+ - Strong open-weight, via API (not local): DeepSeek V4 (DeepSeek API or OpenRouter)
63
+ - Cheap/small tier: a budget model, to establish the cost floor
64
+ - **Judge:** **Claude (Anthropic API)** — a different family from every generator, to avoid
65
+ self-preference bias. Never use the same model to generate and to judge.
66
+ - **Eval metrics:** DeepEval (faithfulness, answer relevancy, contextual recall).
67
+ - **Tracing:** LangSmith — span-level retrieve→augment→generate, for stage-attribution.
68
+ - **Dashboard:** Streamlit, deployed on Streamlit Community Cloud or Hugging Face Spaces
69
+ (NOT AWS — over-engineering for a static benchmark; cloud/MLOps skills live in coursework).
70
+
71
+ > Note: Claude Pro funds Claude Code + chat only. All pipeline model calls (OpenAI,
72
+ > Anthropic judge, DeepSeek) bill separately on API credits. Use prompt caching and
73
+ > batch endpoints to control cost and rate limits.
74
+
75
+ ## The five configs
76
+
77
+ 1. **Naive** — embed → top-k → generate. Baseline.
78
+ 2. **Hybrid** — BM25 + dense + RRF. Hypothesis: lexical matching helps on exact citation tokens.
79
+ 3. **Rerank** — retrieve 20 → cross-encoder → top 5. Hypothesis: higher precision cuts wrong-provision errors.
80
+ 4. **KG-augmented** — entity/relationship graph over provisions (the differentiator).
81
+ Hypothesis: helps where obligations cross-reference each other.
82
+ 5. **Grounded / citation-forced** — model must quote the provision verbatim + cite the
83
+ paragraph ID, and refuse if unsupported. Hypothesis: cuts fabrication/misstatement most.
84
+
85
+ ## Failure taxonomy (exactly one bucket per (query, config))
86
+
87
+ 1. **Fabricated citation** — provision doesn't exist. (Caught deterministically by regex.)
88
+ 2. **Real-but-irrelevant** — provision exists but doesn't support the claim.
89
+ 3. **Correct citation / misstated obligation** — exists and relevant, but the obligation is
90
+ wrong or distorted. ← the wedge.
91
+ 4. **Missing citation** — answer needed authority and gave none.
92
+ 5. **Correct & faithful** — the pass bucket.
93
+
94
+ ## Ground-truth pipeline (two layers)
95
+
96
+ - **Layer 1 — deterministic.** Regex-parse every citation; check against the corpus citation
97
+ index. Catches bucket 1 with zero judgment. Fabrication rate is publishable on its own.
98
+ - **Layer 2 — entailment, validated.** LLM judge sees the *actual retrieved provision text*
99
+ + the model's claim; decides entailment (buckets 2 & 3). **Validate the judge:** hand-label
100
+ ≥100 items, run the judge on the same 100, report **Cohen's κ** + accuracy. Judge model
101
+ must differ from the generator. This validation is the biggest credibility differentiator.
102
+
103
+ ## Gold set design (quality over count — aim 80–120)
104
+
105
+ - Stratify by the failure mode each query targets: retrievability stress, distractor stress,
106
+ obligation-fidelity stress (the largest stratum), cross-reference stress.
107
+ - Per query, record: question, gold answer, gold citation(s) with paragraph IDs, the supported
108
+ proposition, the stratum, and a one-line rationale.
109
+ - **Anti-leakage:** NEVER put the gold answer or gold citation text into any prompt.
110
+ - Favour concrete obligations ("an APRA-regulated entity must…") over vague principles.
111
+
112
+ ## Data
113
+
114
+ - **Statutory:** Open Australian Legal Corpus (`isaacus/open-australian-legal-corpus`, HF).
115
+ Pull subset: Corporations Act 2001 (Cth), Banking Act 1959 (Cth), relevant regulations.
116
+ - **Regulator instruments:** APRA Prudential Standards (start CPS 220, CPS 230, CPS 234);
117
+ a coherent handful of ASIC Regulatory Guides.
118
+ - **Keep clause/paragraph IDs as metadata on every chunk.** Most important ingestion decision.
119
+ - Attribute OALC (CC BY 4.0). Note provenance/licensing — it's on-theme for a compliance project.
120
+
121
+ ## Repo structure
122
+
123
+ ```
124
+ ausregbench/
125
+ data/ # ingested corpus + provenance notes
126
+ src/
127
+ ingest.py # clause-aware chunking, keeps paragraph IDs
128
+ retrieval.py # bm25, dense, hybrid (RRF), rerank
129
+ configs/ # the 5 RAG configs
130
+ eval.py # taxonomy scoring + DeepEval metrics
131
+ judge.py # LLM-judge + kappa validation
132
+ queries/ # gold set as versioned .jsonl
133
+ results/ # raw runs + summary tables
134
+ dashboard/ # Streamlit app
135
+ README.md # what/why/how + headline result + how to reproduce
136
+ methodology.md # taxonomy, judge protocol, kappa, limitations
137
+ LICENSE
138
+ ```
139
+
140
+ ## Build phases
141
+
142
+ 1. **Skeleton:** Neon + pgvector, OALC ingest + clause-aware chunking (IDs preserved),
143
+ naive config end-to-end on ~10 queries.
144
+ 2. **Breadth:** the other 4 configs + eval harness + LangSmith tracing.
145
+ 3. **Ground truth:** full 80–120 gold set + two-layer judge + **validate the judge (κ)**.
146
+ 4. **Ship:** run everything, build the Streamlit dashboard, write the report.
147
+ 5. **(Optional, post-ship):** MCP wrapper, additional model, etc. — one at a time, only if it sharpens the finding.
148
+
149
+ ## Prior art to engage (cite correctly)
150
+
151
+ - **Monash AusLaw Citation Benchmark** (Han, Burgess & Shareghi) — case-law/legislation
152
+ **citation prediction**; found standalone generative models fail almost entirely and BM25
153
+ beats dense retrieval. Cite as corroboration for the hybrid config AND as the "how is this
154
+ different" contrast (they predict citations; we measure obligation faithfulness + stage).
155
+ - **Deakin "Seven Failure Points"** (Barnett et al., 2024, arXiv 2401.05856) — an engineering
156
+ **experience report** of RAG failure points across research/education/biomedical. NOT
157
+ case-law citation prediction. Contrast: they catalogued failures qualitatively; we built a
158
+ reproducible quantitative benchmark for one high-stakes domain.
159
+
160
+ ## When to STOP and ask the human
161
+
162
+ - Any request to add a vertical, a 6th config, MCP, multi-agent orchestration, or AWS/cloud deploy.
163
+ - Any change to chunking logic or how paragraph IDs are tracked.
164
+ - Anything that touches the gold set's correctness.
165
+ - Using the same model as both generator and judge.
166
+ - Putting gold answers/citations into a prompt (leakage).
167
+
168
+ ## Done means done
169
+
170
+ When the report is written, the repo is clean, the dashboard runs, and the LinkedIn post is
171
+ drafted — **stop.** Resist infinite polishing. Shipped at 90% beats perfect-and-abandoned.