Skip to main content
Try Lexiel for freeTry now →
15 minAdrián

Legal RAG Explained

What is RAG (Retrieval-Augmented Generation) and how it ensures responses grounded in real sources.

What is RAG?

RAG (Retrieval-Augmented Generation) is an AI architecture that combines two capabilities:

  1. Retrieval: searches for relevant documents in a verified source database
  2. Generation: uses an LLM to synthesize a response based on those documents

Why Is It Crucial for Law?

A "pure" LLM (without RAG) can:

  • Invent non-existent articles ("hallucinations")
  • Cite non-existent rulings
  • Mix legislation from different countries
  • Give outdated information

With RAG, the response is always grounded in real, verifiable documents.

How It Works Step by Step

  1. User question: "What is the statute of limitations for non-contractual damages?"
  2. Embedding: the question is converted into a numerical vector
  3. Semantic search: the most similar fragments are found in the database (pgvector)
  4. Context: relevant fragments are passed to the LLM along with the question
  5. Generation: the LLM responds based only on the provided fragments
  6. Citation: the response includes exact sources (article, ruling, BOE)

RAG Quality Metrics

  • Precision: are the cited sources correct?
  • Recall: were all relevant sources found?
  • Faithfulness: is the response faithful to what the sources say?
  • Relevance: are the sources pertinent to the question?

Have your own legal questions?

The Individual Plan gives you 50 queries/month with answers verified against official legal sources.

Try free for 14 days