AI Engineer World's Fair 2025

Scaling Enterprise-Grade RAG Systems: Lessons from the Legal Frontier

Read the talk

Scaling Enterprise-Grade RAG Systems: Lessons from the Legal Frontier

Legal retrieval combines semantic questions, exact identifiers, implicit filters, and confidential data. Building it at scale requires expert evaluation and infrastructure that supports repeated experimentation.

From a talk by Calvin Qi and Chang She

Before you start: Familiarity with retrieval-augmented generation, embeddings, and basic database concepts will help; no legal background is required.

One question, several retrieval requirements

Qi illustrates query complexity with a question about the applicable regime for covered bonds issued before 9 July 2022, under directive EU 2019/2062 and Article 129 of the CRR. These are the identifiers and date used in the presentation’s example, rather than a verified legal citation. He places the question near the middle of Harvey’s query-complexity range. Even this ordinary case contains several distinct retrieval requirements.

Query componentRetrieval requirement
Applicable regimeSemantic understanding of the requested legal relationship
Issued before a dateAn implicit temporal constraint
EU laws and directivesSelection of a specialized corpus
Directive identifier and Article 129Exact keyword or identifier matching
Directive plus regulation articleMultiple related parts to investigate
CRRInterpretation of domain terminology

The query must be decomposed before its retrieval needs can be matched to appropriate technologies. Semantic similarity alone does not express the date constraint or guarantee an exact identifier match. Conversely, matching identifiers does not establish how the provisions apply together. The example demonstrates a retrieval-planning problem; it does not provide the legal answer.

3:223:31
Suggest correction

This note stays in this page until you copy or download it. Nothing is submitted; reloading clears the draft.

3:22 · section reference included

Build an evaluation portfolio

Once a question requires several retrieval mechanisms, validating the combined system becomes substantial engineering work. Qi describes spending considerable effort on evaluation, beyond developing algorithms or agentic techniques. That investment matters especially when engineers and researchers lack the domain knowledge needed to judge an answer directly. There is no single evaluation that covers every task depth and complexity.

Evaluation methodStrengthCost or limitation
Expert reviews of outputs and written reportsHigh-fidelity judgmentExpensive expert time
Expert-curated criteria assessed automaticallyDomain guidance with repeatable assessmentCostly curation; some execution cost
Quantitative and deterministic checksFast iterationNarrower evidence of success

The fastest layer includes retrieval precision and recall, along with checks for the expected folder, section, or keywords. These tests provide quick signals while expert review addresses questions that a simple retrieval score cannot resolve.

A small Python evaluation can make that fastest layer explicit. Here, document relevance labels support precision and recall, while metadata checks test whether retrieval stayed inside the intended folder and found the expected section. The records are a teaching example of the evaluation pattern:

python

relevant_ids = {"doc-a", "doc-b"}
retrieved = [
    {
        "id": "doc-a",
        "folder": "eu-law",
        "section": "Article 129",
        "text": "covered bonds",
    },
    {
        "id": "doc-c",
        "folder": "eu-law",
        "section": "Overview",
        "text": "capital requirements",
    },
]

retrieved_ids = {row["id"] for row in retrieved}
hits = retrieved_ids & relevant_ids

metrics = {
    "precision": len(hits) / len(retrieved_ids) if retrieved_ids else 0.0,
    "recall": len(hits) / len(relevant_ids) if relevant_ids else None,
    "correct_folder": all(row["folder"] == "eu-law" for row in retrieved),
    "expected_section_found": any(
        row["section"] == "Article 129" for row in retrieved
    ),
    "keyword_found": any(
        "covered bonds" in row["text"].lower() for row in retrieved
    ),
}
print(metrics)

Finding the right section or keyword is useful evidence about retrieval behavior. It still does not establish that the final answer interprets the law correctly.

4:394:49
Suggest correction

This note stays in this page until you copy or download it. Nothing is submitted; reloading clears the draft.

4:39 · section reference included

Scale includes repeated processing

The data side introduces its own domain structure. Legal sources from different countries require different filtering, organization, and categorization. Harvey works with experts to understand those distinctions, then turns their guidance into heuristics or LLM processing where automation is practical. The expert contribution therefore affects the organization of the corpus, not just the evaluation of generated answers.

Performance has two separate meanings here. Online performance means acceptable latency when a user queries the corpus. Offline performance means ingesting and re-ingesting data, running ML experiments, and comparing variations without making each experiment prohibitively slow. Qi describes individual corpora reaching tens of millions of documents, many of them large. At that scale, repeated processing is a core workload rather than an occasional maintenance task.

“Scale” slide showing knowledge-source and tax-category menus beside bullets about large datasets, complex filtering, online and offline performance, and tens of millions of documents to index.Open full source frame
Organizing large datasets requires complex filtering and performance both online and offline.
6:116:21
Suggest correction

This note stays in this page until you copy or download it. Nothing is submitted; reloading clears the draft.

6:11 · section reference included

Turn application constraints into infrastructure requirements

Reliable service and smooth onboarding must accompany scale. ML and data teams need to spend their time improving quality and building customer applications, rather than repeatedly tuning databases or scaling them manually. Qi also qualifies that goal: automation does not remove the need for operational awareness.

The remaining requirements span governance, observability, and retrieval:

  • Storage segregation: isolate data according to the customer and use case.
  • Retention: respect legal limits on how long particular documents may remain stored.
  • Telemetry: expose database usage and behavior so teams can understand the service they operate.
  • Query flexibility: support exact matches, semantic matches, filters, and dynamic or agentic navigation over the data.

These requirements must hold together at scale. They establish the infrastructure problem that leads into LanceDB’s part of the architecture.

7:157:29
Suggest correction

This note stays in this page until you copy or download it. Nothing is submitted; reloading clears the draft.

7:15 · section reference included

One data foundation for offline work and online retrieval

LanceDB’s proposed foundation is a multimodal lakehouse: AI data stored together on object storage, with support for the work surrounding retrieval. Feature extraction, summaries, and text descriptions of images all create useful derived data. The same foundation should support search, analytical queries, training, and preprocessing, so teams can experiment with new features without rebuilding the data pipeline for each workload.

A lakehouse that handles large offline batches does not automatically provide good online serving. LanceDB addresses that distinction with a distributed architecture that separates compute, memory, and storage while serving data from cloud object storage. Its retrieval interface can combine multiple vector columns, vector search with full-text search, and reranking. Python and TypeScript APIs expose those operations in a dataframe-style interface familiar to pandas or Polars users.

She reports a GPU-indexing record of roughly 3–4 billion vectors in one table in under approximately 2–3 hours; hardware, vector dimensions, and index settings are not specified. That is an approximate reported record, not a general indexing-time guarantee. He also attributes lower costs to compute/storage separation and object storage, without supplying a quantified cost comparison.

9:029:26
Suggest correction

This note stays in this page until you copy or download it. Nothing is submitted; reloading clears the draft.

9:02 · section reference included

The storage format connects selective access and bulk scans

The shared-data design extends beyond storing vectors beside text. Images, videos, audio, embeddings, tabular values, and time series can share a table. That table becomes a common source for search, analytics, training, preprocessing, and feature engineering.

The open-source Lance format supplies the underlying storage capabilities. She emphasizes random access, large-blob support, and efficient schema evolution, contrasting these with limitations he encounters in workflows using WebDataset, Iceberg, and Parquet. This is his architectural comparison, rather than evidence of universal superiority over those systems. The practical problem is duplicated fragments of data across different stores: teams spend time keeping the copies connected and synchronized.

She’s shorthand for Lance is Parquet plus Iceberg plus secondary indexes, adapted for AI data. The important distinction is the access pattern each capability serves:

CapabilityWorkload it supports
Fast random accessSearch and shuffled data access
Fast scansAnalytics and training-data loading
Large blobs alongside small scalarsMultimodal records with their metadata

A useful shared format must support selective reads without giving up efficient bulk processing. It must also handle records whose payloads differ substantially in size.

Apache Arrow provides the main interface to the surrounding data ecosystem. Spark and Ray can write Lance data in distributed jobs; PyTorch can load it for training or fine-tuning; pandas and Polars can query it. This allows the storage layer to participate in existing data workflows rather than requiring every workload to move into a separate toolchain.

11:5712:12
Suggest correction

This note stays in this page until you copy or download it. Nothing is submitted; reloading clears the draft.

11:57 · section reference included

Make domain knowledge and evaluation drive iteration

The engineering choices begin with understanding the domain: the structure of the data, the user’s task, and the explicit and implicit patterns inside queries. Working closely with experts makes those requirements concrete enough to guide modeling and infrastructure choices. Flexibility then becomes essential because tools, retrieval paradigms, and model context windows keep changing.

Evaluation makes that flexibility usable. Good evaluation sets, expert procedures, and automated checks provide a faster signal about whether a change improves accuracy. Infrastructure must support the same pace of experimentation while accommodating multimodal data, vectors and embeddings, increasingly diverse workloads, and growing collections of public and private information. The capacity to revise a retrieval system depends on both trustworthy quality signals and a data foundation that can keep up with the revisions.

“Take Home Messages” slide with three bullets covering domain-specific data, modeling and infrastructure; iteration speed and flexibility grounded in evaluation; and multimodal data, diverse workloads, and massive scale.Open full source frame
Take-home messages: domain-specific solutions, evaluation-grounded iteration, and infrastructure for diverse workloads at massive scale.
14:5915:11
Suggest correction

This note stays in this page until you copy or download it. Nothing is submitted; reloading clears the draft.

14:59 · section reference included

Resources

From the talk

Updates since the talk

Transcript download
Read the transcript and explore slides

Loading transcript and slides…