Building a legal RAG system: the data sources you actually need
Case law, legislation and regulatory filings for legal RAG across the UK, US and EU, with notes on licensing and how to structure legal text for retrieval.
Legal work is one of the clearest fits for retrieval-augmented generation (RAG): the source material is authoritative, heavily cited, and updated on a schedule, and the cost of a confident but wrong answer is high enough that grounding every response in a citable document is non-negotiable. The hard part is rarely the model. It is assembling a corpus that is complete for your jurisdiction, correctly licensed, and structured so that a retriever can find the right section rather than the right document. This post walks through the primary sources worth building on, organised by document type and jurisdiction, and then covers the practical work of preparing legal text for retrieval. It is written as a deep-dive into one vertical, but the shape of it (organise by document type, pick the authoritative source per jurisdiction, check the licence per subset) transfers to almost any other domain.
Start with the document types, not the datasets
Before choosing sources, decide which document types your assistant needs to reason over. Most legal RAG systems draw on three:
- Legislation and regulation: the statutes and rules that state the law as written.
- Case law: the judgments and opinions that interpret and apply it.
- Corporate and regulatory filings: the disclosures, registrations and returns that show how the law is complied with in practice.
These behave differently. Legislation is versioned and amended in place, so a point-in-time view matters. Case law is append-only and citation-dense. Filings are structured, high-volume and often the actual thing a commercial user cares about. Mixing them into one undifferentiated index tends to hurt retrieval, so it helps to keep the document type as metadata from the start. The legal category in the directory groups these sources together, and the adjacent government category is worth a look for the official portals that publish much of this material.
Legislation: the law as written
For the UK, Legislation.gov.uk is the primary source, published by The National Archives. Its most useful property for RAG is that it exposes legislation at the section level as structured XML, with point-in-time versions, so you can retrieve the specific provision as it stood on a given date rather than a whole Act as a single blob. That granularity maps almost directly onto how you will want to chunk.
For US federal regulation, the Electronic Code of Federal Regulations (eCFR) provides a continuously updated, structured version of the CFR. It is organised into titles, parts and sections, which again gives you a natural retrieval unit and a stable citation to carry through.
For EU law, EUR-Lex is the official gateway to treaties, regulations, directives and case law of the Court of Justice, published in the official languages. It is large and its structure varies across document families, so expect to spend time normalising before indexing. If your assistant needs to reason across languages, it is worth reading our note on the licensing trap before you assume every subset is equally reusable.
Case law: how the law is interpreted
Case law is where coverage decisions bite hardest, because completeness and recency both matter and no single source gives you everything.
- United States: CourtListener, maintained by the Free Law Project, aggregates opinions from federal and state courts with an API and bulk access. For historical depth, the Caselaw Access Project digitised a very large span of published US case law and is the better choice when you need older reported decisions.
- United Kingdom and Commonwealth: Find Case Law, also from The National Archives, is the official source for recent judgments of the senior courts, published as structured documents. BAILII has long-standing, broad coverage across UK and Irish jurisdictions and is often where older or tribunal-level material lives.
- Australia: AustLII covers legislation and case law across Australian jurisdictions.
- Canada: CanLII plays the equivalent role for Canadian federal and provincial law.
A common pattern is to combine an official source for recent, authoritative text (Find Case Law, CourtListener) with a broader aggregator for historical reach (BAILII, Caselaw Access Project), then deduplicate on citation. The value of pairing them is that the official sources give you clean, structured, recent judgments you can trust for current advice, while the aggregators fill in the older and lower-court decisions that a serious legal question often turns on. Deciding how far back to reach is a coverage question specific to your users: a litigation team may need decades of precedent, whereas a compliance tool may only care about the current position. Browse the full directory if you need to check coverage for a jurisdiction not listed here.
Corporate and regulatory filings
If your users are lawyers doing transactional or compliance work, filings are frequently the highest-value corpus you can offer.
EDGAR, the US Securities and Exchange Commission’s filing system, holds registration statements, periodic reports and disclosures from public companies, available in bulk and via API. The documents are long and semi-structured, which rewards careful sectioning: a single annual report may run to hundreds of pages, and the useful answer usually lives in one identifiable item or note rather than the document as a whole.
For the UK, Companies House publishes the register of companies along with filings such as accounts and confirmation statements, much of it available as bulk data and through an API. Both sources reward treating each filing as a set of addressable sections rather than a single document.
Ready-made corpora for prototyping
Assembling primary sources takes time. To get a retriever working before you commit to the ingestion engineering, two pre-built corpora are useful.
Pile of Law is a large collection of legal and administrative text drawn from many sources, assembled for training and research. It is a fast way to stand up a broad English-language legal index. Cambridge Law Corpus is a research corpus of court cases with annotations, useful when you want a cleaner, well-described set to experiment with.
Treat both as prototyping and evaluation aids rather than the foundation of a production system. Their licence terms and coverage vary by subset, and for anything you ship you will usually want to trace back to the authoritative primary source and ingest it directly. Our guide to choosing your first RAG dataset covers how to make that call.
Preparing legal text for retrieval
Once you have the documents, the difference between a mediocre and a genuinely useful legal assistant is mostly in how you chunk and annotate. Legal text has structure that plain-prose splitting throws away, and preserving it is the single highest-leverage thing you can do.
Chunk at the section and clause level. Legislation, regulation and contracts are already divided into sections, subsections and clauses. Use those boundaries as your primary chunk unit rather than a fixed token window that cuts across them. A retriever that returns “section 3(1)(b)” is far more useful than one that returns the middle 400 tokens of a page. Our lesson on chunking your documents goes into the mechanics; the legal-specific point is to let the document’s own hierarchy drive the split.
Carry citations and dates as metadata. Every chunk should know where it came from: the citation, the section number, the court or issuing body, the decision or enactment date, and the jurisdiction. This metadata does double duty. It lets you filter retrieval (only current EU regulations, only England and Wales judgments after a certain date), and it lets the model cite precisely, which is what makes a legal answer verifiable. The get your data lesson covers extracting this cleanly.
Handle point-in-time versions explicitly. Legislation is amended in place, so “what does section 12 say” has different answers depending on the date. Sources like Legislation.gov.uk expose historical versions precisely for this reason. Store the version’s effective date range as metadata and, where your users need it, retrieve the version that was in force on a particular date rather than only the current text. Getting this wrong is one of the more dangerous failure modes in a legal assistant.
Keep the document type separate. As noted above, indexing legislation, case law and filings together tends to blur retrieval. Either keep separate indexes or tag every chunk with its document type so you can route and filter queries appropriately.
A word on licensing
Primary law occupies an unusual position. In many jurisdictions the text of statutes, regulations and court judgments is not protected by copyright, or is published under an open government licence, precisely because the law must be freely knowable. That does not mean every source is equally reusable. Official portals often attach their own terms to the presentation, structure or metadata even where the underlying text is free, and aggregated corpora almost always mix subsets under different licences, so a corpus that is broadly open may still contain material you cannot redistribute.
The practical rule is to check the licence per source and, for compiled corpora, per subset, and to record what you found alongside the data. Each source page in our directory states the licence where it is known, and the glossary explains the common terms. Getting this right early is far cheaper than discovering a redistribution problem after you have shipped, and it is the same discipline that makes every other part of a legal RAG system trustworthy: know exactly where each answer came from, and be able to prove it.