Skip to content

Latest commit

 

History

History

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

README.md

English | 简体中文

CaseAnchor — 类案检索工作台

CaseAnchor

Turn a folder of Chinese court judgments into a ranked similar-case analysis and a court-ready retrieval report draft — on your own machine, with your own AI key.

License: MIT Python 3.8+ Zero dependencies Tests Visual QA BYOK

Quick Start · Screenshots · How It Works · 中文文档


Table of Contents

The Problem

Since the Supreme People's Court's 2020 guiding opinion on unified application of law (法发〔2020〕24号), Chinese litigators are required to run similar-case retrieval (类案检索) — and often to submit a written 类案检索报告 — for whole categories of cases. In practice that means:

  • keyword search on public judgment sites misses cases whose facts match but whose wording differs;
  • reading dozens of judgments to pull out 裁判要点 (adjudication points) and 争议焦点 (dispute focuses) takes hours per matter;
  • assembling the report — method statement, ranked case table, divergence analysis — is manual, repetitive, and error-prone;
  • conflicting outcomes on similar facts (同案不同判) are exactly what you must address, and exactly what keyword search never surfaces side by side.

Why Existing Approaches Are Not Enough

  • Public judgment websites give you keyword search over one case at a time — no similarity ranking, no extraction, no report.
  • Commercial legal databases (北大法宝, 威科先行, Alpha…) are powerful but subscription-priced, cloud-bound, and closed: your query strategy and your matter's facts leave your machine.
  • Pasting judgments into a chatbot produces fluent but ungrounded summaries — no verbatim citations, no confidence labels, no way to audit which sentence of the judgment a "holding" came from.

What CaseAnchor Does

CaseAnchor is a local web workbench that runs the whole retrieval chain on your machine:

  1. Import judgments (.txt one per file, .json batches) — a structural parser segments each into 案号/法院/案由/诉讼请求/事实认定/本院认为/判决结果, extracts cited statutes, and classifies procedure, court level and outcome, with provenance warnings for anything it could not parse.
  2. Retrieve with hard filters (案由 / court level / year / statute) plus BM25 lexical recall over fact-bearing text.
  3. Rank by a five-dimension similarity model (fact-pattern cosine, 案由 alignment, statute overlap, court authority, recency) with user-adjustable weights — and a built-in counterfactual sensitivity check that tells you which dimension your ranking depends on.
  4. Extract 裁判要点 from 本院认为 using your own AI key, grounded to verbatim source quotes and cross-checked against a deterministic rule-based extractor; every point carries a HIGH/MEDIUM/LOW confidence label. No key? A rule-based mock mode runs fully offline.
  5. Report: one click produces a downloadable 类案检索报告 draft (Markdown) — method statement, ranked case table, per-case points with quotes and confidence, 同案不同判 divergence flags, an action plan of which cases to cite and which to distinguish, and an honest limitations section.

Your API key stays in your browser's localStorage, travels only through your local backend to the provider you chose, and is never stored or logged server-side.

Key Features

  • Judgment structure parser — sections, 案号, statutes (《民法典》第676条-style normalization, Chinese-numeral aware), outcome classes (支持/部分支持/驳回/改判/维持/发回重审/调解/撤诉), provenance warnings.
  • Hybrid retrieval — structured filters narrow, char-bigram BM25 ranks; a visible funnel (corpus → filtered → matched) shows coverage.
  • Explainable similarity — every match shows its per-dimension breakdown and the decisive dimension; weights are sliders, not magic.
  • Sensitivity analysis — drop-one-dimension counterfactuals mark the ranking STABLE or UNSTABLE, so you know what to double-check before relying on it.
  • Grounded AI extraction — the model must quote a verbatim span from 本院认为; fabricated quotes are demoted to LOW and flagged for human review; rule/AI agreement promotes to HIGH.
  • 同案不同判 divergence detection — highly similar cases with conflicting outcomes are paired and annotated with the distinctions you must argue.
  • BYOK, six providers + relays — OpenAI, Anthropic, Gemini, DeepSeek, Kimi, GLM presets plus any OpenAI-compatible base URL (中转站/self-hosted); key test button; offline mock mode.
  • Long-task resilience — batch extraction runs server-side with progress, cancel, resume after page refresh, task history and per-task token usage.
  • Zero dependencies — Python 3.8+ standard library only; one command to run; nothing leaves your machine except the AI call you explicitly configure.

Demo / Screenshots

Workbench (retrieval + ranked matches) AI settings (BYOK)
Workbench AI settings
Mobile layout (390px) Mobile layout

Quick Start

git clone <this-repo>
cd caseanchor
python server.py            # Python 3.8+, no pip install needed
# open http://127.0.0.1:8056

Then, in the browser:

  1. Click 加载示例判例库 — 7 bundled sample judgments (民间借贷/租赁/买卖/劳动) import through the real parsing pipeline.
  2. The query box is one paste away: describe your case facts, set 案由, hit 检索类案.
  3. Tick the matches you care about → 提取要点 (works offline in mock mode) → 生成检索报告 → download the .md draft.

Run the test suite:

python -m unittest discover -s tests    # 63 tests

AI Setup (BYOK)

Open AI 设置 in the masthead:

Field Notes
Provider mock (offline, default) / DeepSeek / Kimi / GLM / OpenAI / Anthropic / Gemini / custom
API Key stored in your browser only; masked; one-click clear; never logged
Base URL custom mode only — any OpenAI-compatible endpoint (relay/中转站, LM Studio, vLLM); HTTPS enforced except localhost
Model optional; sensible default per provider

测试密钥 fires a one-token ping and reports the exact failure class if something is wrong (invalid key / rate limit / model missing / network / timeout), with a fix hint.

Example Input / Output

Input (any judgment text, e.g. the bundled fixtures/sample_corpus/j01_….txt):

北京市朝阳区人民法院
民事判决书
(2023)京0105民初12345号
…
本院认为,合法的借贷关系受法律保护。原告提交的借条、微信转账记录及聊天记录
能够相互印证,足以认定双方之间借贷关系成立且款项已实际交付。…

Output (excerpt of the generated report draft):

# 类案检索报告(草稿)
## 二、类案匹配结果(按相似度排序)
| # | 案号 | 法院 | 案由 | 程序 | 结果 | 相似度 | 决定性维度 |
| 1 | (2023)京0105民初12345号 | 北京市朝阳区人民法院 | 民间借贷纠纷 | 一审 | 支持 | 48% | 事实相似 |## 三、同案不同判风险提示
- (2023)京0105民初12345号(支持) vs (2023)粤0304民初23456号(驳回):
  两案均与本案高度相关但结论相反——检索报告中必须说明区分点…
## 五、行动建议(action plan)
- 可优先援引 (2023)京0105民初12345号(基层院,支持),论证本案与其事实要件的一致性。

Use Cases

  • Litigators producing a mandated 类案检索报告 with a defensible method statement.
  • In-house counsel triaging dispute risk against their own archive of past judgments.
  • Paralegals / interns turning a partner's "find me similar cases" into a ranked, quoted, checkable draft.
  • Law students & researchers studying 同案不同判 patterns across a corpus they assemble.

How It Works

flowchart LR
  A[Judgment files\n.txt / .json] --> B[M1 Parser\nsections · statutes · outcome\nprovenance warnings]
  B --> C[(Corpus store\nshared data model)]
  C --> D[M2 Retrieval\nfilters + BM25]
  D --> E[M3 Similarity\n5 dimensions · weights\nsensitivity counterfactuals]
  E --> F[M4 Extraction\nrule path + BYOK AI\ngrounding cross-check]
  E --> G[M5 Report\nranked table · divergence\naction plan · limitations]
  F --> G
  G --> H[[类案检索报告\ndraft .md]]
  I[Browser UI\nkey in localStorage] -. request-scoped key .-> J[Local server\nBYOK gateway]
  J --> D
  J --> F
Loading

Six cooperating subsystems (parser, corpus store/index, similarity engine, extraction with cross-check, task registry, report engine) exchange state through one shared data model — remove any single one and the others still function.

Project Structure

caseanchor/
├── server.py           # local HTTP server (127.0.0.1), API + static
├── provider.py         # BYOK gateway: 6 presets + custom + mock, error taxonomy
├── domain/
│   ├── model.py        # shared data model (Case, Query, MatchScore, Extraction)
│   ├── parse.py        # M1 judgment structure parser
│   ├── tokenize.py     # char-bigram Chinese tokenizer (no deps)
│   ├── index.py        # M2 BM25 inverted index + structured filters
│   ├── similarity.py   # M3 five-dimension similarity + sensitivity
│   ├── extract.py      # M4a rule-based extraction + AI cross-check
│   ├── ai.py           # M4b grounded AI extraction (BYOK)
│   ├── report.py       # M5 report draft + 同案不同判 divergence
│   ├── store.py        # corpus persistence + import pipeline
│   └── tasks.py        # background tasks: progress/cancel/resume/history
├── web/                # 檀卷 design system UI (no framework)
├── fixtures/           # 7 sample judgments + 4 edge cases
├── tests/              # 63 tests across 7 files
└── qa/                 # machine visual-integrity report (24/24 states)

Comparison

Public judgment sites Commercial databases Generic chatbot CaseAnchor
Similar-case ranking keyword only yes (closed) no yes, explainable + sensitivity
裁判要点 extraction no partial ungrounded grounded, confidence-labeled
检索报告 draft no template export prose only structured draft w/ divergence + action plan
Runs locally / data stays private no no yes
Bring your own AI key no n/a yes (6 providers + relays + offline mock)
Price free subscription varies free, MIT

Roadmap

  • PDF / DOCX judgment import (currently .txt / .json)
  • Optional embedding-based recall behind the same interface (kept out of v1 to stay dependency-free)
  • Report export to DOCX with firm letterhead
  • Corpus statistics view (outcome rates by court level / year for the retrieved set)

Limitations

  • Retrieval is lexical + structural (BM25 over character bigrams plus engineered dimensions), not neural semantic search — cases phrased very differently may be missed; the report's coverage statement says exactly what corpus was searched.
  • The bundled corpus is a 7-judgment starter sample for trying the pipeline — it is not a mirror of any judgment database; bring your own corpus for real work.
  • AI extraction can be wrong. Every AI point is grounded to a quoted span and cross-checked, but LOW-confidence items must be human-verified; the report labels extraction method per point.
  • The generated report is a draft (决策简报-style decision record), not a filing: review, edit and take responsibility for anything you submit. CaseAnchor does not provide legal advice.

License

MIT