Spec: Resolve Citations to Case Nodes (Graph Densification)¶
- ID: 002-resolve-citations-to-cases
- Status: shipped
- Owner: @copilot
- Created: 2026-04-29
- Roadmap Epic: BL-20260429-05 (graph densification)
- Constitution Compliance: confirmed against docs/constitution.md §§1–11.
1. Problem & Motivation¶
Spec 001 ships citations as (:Citation {normalized}) nodes connected to a single source (:Case) via HAS_CITATION. The cited case itself is rarely linked, so the graph is a star, not a network — defeating the GraphRAG advantage over plain vector search. We need to resolve Citation.normalized strings to existing Case nodes whenever possible and create (:Case)-[:CITES]->(:Case) edges.
Mirrors backlog item BL-20260429-05 (feature, high).
2. Goals¶
- G1: Given a freshly extracted
ExtractionResult, populateCitation.target_case_idfor every citation that matches an existingCasealias. - G2: Densify the graph by reusing the existing
MERGE_CITES_CYPHER(no schema change beyond a newCase.aliases: list[str]property). - G3: Make the resolver pure-async, idempotent, and safe to run on backfills.
3. Non-Goals¶
- NG1: Fuzzy matching across reporters (e.g. parallel cites). Phase 2.
- NG2: Cross-jurisdiction harmonization. Phase 2.
- NG3: New API endpoints — this is an internal ingestion enhancement.
4. User Stories¶
- As a Precedent Hunter agent, I want incoming opinions to be auto-linked to the cases they cite so that Cypher traversals (
(:Case)-[:CITES*1..3]->(:Case)) return real precedent chains instead of empty results. - As a researcher, I want the graph viewer to show citation networks the day after ingestion, not after a separate manual densification pass.
5. Functional Requirements¶
- FR-1: Add
Case.aliases: list[str]populated fromExtractionResult.aliases(new optional field). Backward compatible — existing nodes without aliases are unaffected. - FR-2: Add
app.db.citation_resolver.resolve_citations(session, normalized: list[str]) -> dict[str, str | None]returning a{normalized: case_id_or_None}map. - FR-3: Add
app.db.citation_resolver.densify_extraction(session, result: ExtractionResult) -> ExtractionResultthat mutatesresult.citations[*].target_case_idin place using FR-2. - FR-4:
IngestionScout.run_and_commitcallsdensify_extractionafterextractand beforecommit_extraction(FR-3 reuse).
6. Non-Functional Requirements¶
- NFR-IDEMPOTENT-1: Re-running densification on the same
ExtractionResultproduces the sametarget_case_idvalues and creates zero new edges in Neo4j. - NFR-PERF-1: Resolver issues exactly one Cypher round-trip per
ExtractionResult, regardless of citation count (usesUNWIND $normalized AS n). - NFR-AUDIT-1: Every resolved citation is logged via
app.core.provenancewith fields{normalized, target_case_id, confidence, agent_version}. - NFR-HITL-1: No HITL change — densification only touches edges between already-approved nodes.
7. Data Model Impact¶
- New property:
Case.aliases: list[str](defaults to[]). - No new node labels.
- Existing edge reused:
(:Case)-[:CITES]->(:Case)from spec 001'sMERGE_CITES_CYPHER.
Provenance fields (source, confidence, ingest_timestamp) remain on the :CITES edge per constitution §4.
8. API Surface¶
No public route changes. Internal contract:
async def resolve_citations(
session: AsyncSession, normalized: list[str]
) -> dict[str, str | None]: ...
async def densify_extraction(
session: AsyncSession, result: ExtractionResult
) -> ExtractionResult: ...
9. Agent / Crew Impact¶
IngestionScout(existing) gains one extra step:densify_extractionbetweenextractandcommit_extraction. No new tools.PrecedentHunter(existing) automatically benefits — its Cypher traversals start returning real:CITESchains.
10. Acceptance Criteria¶
- AC-1: Given a
Case {id:"a", aliases:["410 us 113"]}exists, when anExtractionResultfrom casebcites"410 us 113", thenresolve_citationsreturns{"410 us 113": "a"}anddensify_extractionsetstarget_case_id="a"on that citation. - AC-2: Given the same input as AC-1 run twice in a row, when
commit_extractionis called both times, then exactly one(:Case {id:"b"})-[:CITES]->(:Case {id:"a"})edge exists (idempotency). - AC-3: Given an
ExtractionResultwith N citations where none match anyCase.aliases, whendensify_extractionruns, then everytarget_case_idstaysNone, exactly one Cypher query is issued, and zero:CITESedges are created. - AC-4:
mypy app/db/citation_resolver.py --strictis clean and the module has ≥85% line coverage.
11. LegalBench Impact¶
- Tasks affected:
precedent_retrieval,case_relevance. - Expected delta: ≥ 0 pp (densification can only help). Actual delta recorded in PR after a real ingestion run; not part of acceptance for this spec because the hermetic test suite doesn't load LegalBench.
12. Risks & Open Questions¶
- R-1: Aliases are author-supplied; bad aliases pollute the graph. Mitigation:
confidenceon:CITESedge inherits from the sourceExtractionResult.confidence, so HITL gate still applies upstream. - R-2: Backfill cost — re-densifying historical cases needs a one-shot script. Captured as a follow-up rather than blocking this spec.
13. Out of Scope / Follow-ups¶
- Fuzzy / parallel-cite matching.
- Backfill script for historical opinions.
aliasesextraction from opinion headers (currently caller-supplied).