LawForge
Concepts

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:

SectionWhat It Contains
FactsBackground facts of the case
Procedural HistoryPrior court proceedings
IssuesLegal questions presented
HoldingThe court's decision
ReasoningLegal analysis and rationale
DissentDissenting opinions
ConcurrenceConcurring 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:

  1. Converts your query to a vector
  2. Finds chunks with similar vectors
  3. Returns them ranked by relevance score (0-1)

Retrieval Modes

ModeWhat You GetUse Case
fullEntire documentReading the complete opinion
summaryAI-generated summaryQuick case overview
chunksAll document sectionsStructured analysis
relevantQuery-matched sectionsTargeted 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 window

Use:

"Get the sections of Brown v. Board relevant to 'separate but equal doctrine'"
→ Returns 3-5 targeted chunks
→ Preserves context for analysis

Lazy 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

On this page