Document Chunking
How LawForge breaks down large legal documents for efficient AI processing
Document Chunking
Legal documents can be extremely long—Supreme Court opinions often exceed 50 pages. Sending entire documents to an AI wastes context window space and can overwhelm the model with irrelevant information.
LawForge solves this with smart document chunking: breaking documents into meaningful sections and using semantic search to retrieve only the most relevant parts.
The Problem
When you ask Claude about a specific legal issue in a case, you typically don't need the entire opinion. You need:
- The relevant facts that relate to your question
- The specific holding on that issue
- The reasoning that supports the decision
Retrieving the full 50-page opinion wastes tokens and dilutes the AI's focus.
The Solution
LawForge automatically chunks documents into logical sections:
┌─────────────────────────────────────┐
│ Full Opinion (50 pages) │
└─────────────────────────────────────┘
↓
┌─────────┬─────────┬─────────┬───────┐
│ Summary │ Facts │ Holding │ Reason│
└─────────┴─────────┴─────────┴───────┘
↓
┌─────────────────────────────────────┐
│ Vector Embeddings (Vectorize) │
└─────────────────────────────────────┘How It Works
1. Section Extraction
When a document is first requested with chunking, LawForge identifies legal document sections:
| Section | What It Contains |
|---|---|
| Facts | Background facts of the case |
| Procedural History | Prior court proceedings |
| Issues | Legal questions presented |
| Holding | The court's decision |
| Reasoning | Legal analysis and rationale |
| Dissent | Dissenting opinions |
| Concurrence | Concurring opinions |
2. AI Summarization
For each document, an AI-generated summary captures:
- Key facts
- Legal issue(s)
- The holding
- Main reasoning
This summary becomes the first chunk, providing a quick overview without reading the full text.
3. Semantic Embeddings
Each chunk is converted to a vector embedding using the same model as semantic search. This enables finding chunks by meaning, not just keywords.
4. Relevance Ranking
When you use mode: "relevant" with a query, LawForge:
- Converts your query to a vector
- Finds chunks with similar vectors
- Returns them ranked by relevance score (0-1)
Retrieval Modes
| Mode | What You Get | Use Case |
|---|---|---|
full | Entire document | Reading the complete opinion |
summary | AI-generated summary | Quick case overview |
chunks | All document sections | Structured analysis |
relevant | Query-matched sections | Targeted research |
Example Workflow
Instead of:
"Get the full text of Brown v. Board of Education and tell me about equal protection"
→ Returns 50 pages of text
→ Uses most of your context windowUse:
"Get the sections of Brown v. Board relevant to 'separate but equal doctrine'"
→ Returns 3-5 targeted chunks
→ Preserves context for analysisLazy Chunking
Documents are chunked on first request, not in advance. This means:
- First request: Slightly slower (chunking happens)
- Subsequent requests: Fast (chunks are cached)
Chunks are stored permanently, so the chunking cost is only paid once per document.
Technical Details
- Storage: Chunks stored in Cloudflare D1 (SQLite)
- Vectors: Embeddings stored in Cloudflare Vectorize
- Model: BGE-base-en-v1.5 for embeddings
- Summarization: Llama 3.1 8B for AI summaries
See Also
- get_document - Using chunked retrieval
- Semantic Search - Finding cases by concept
- AI-Powered Legal Research - Overview of AI features