How Lexiel's Legal RAG Works: Legal Research With Checked Citations
The biggest fear lawyers have when using AI is legitimate: what if it invents a judgment? Lexiel reduces that risk with a legal RAG architecture and, on top of that, checks the citations after generating the answer. Here is how it works and where its limits are.
The Problem: LLMs Don't Know Case Law
Large language models were trained on internet text up to a cutoff date. When you ask a general chatbot for Supreme Court judgments, it may respond with judgment numbers that look real but don't exist. This is called hallucination and is the greatest risk of using generalist AI in legal contexts.
The Solution: RAG (Retrieval-Augmented Generation)
RAG separates two functions:
- Retrieval: searching a database of real documents for the most relevant fragments
- Generation: using those fragments as context for the LLM to generate an answer based on them
The LLM does not have to rely on memory: we give it the text of the statute or judgment that supports the answer.
How a query flows through Lexiel
Lawyer's query
↓
[Hybrid search over the legal corpus]
· semantic search (embeddings)
· keyword search (full text)
↓
[Rank fusion (RRF) and reranking]
↓
[One fragment per source and article]
↓
[Context → LLM]
↓
[Verification of the answer's citations]
↓
Answer with each citation marked verified or not
The Corpus: 130,000+ Official Sources
- Spain: BOE legislation and case law from CENDOJ (Supreme Court, National High Court, regional High Courts and other bodies) and the Constitutional Court
- European Union and Latin America: EU law and legislation from several Latin American countries
- Total: 130,000+ official sources
Article-Level Chunking
Statutes are split into fragments that follow their structure: each article is one fragment. If an article is too long, it is split by its numbered paragraphs, not mid-sentence. From BOE consolidated texts the "previous wording" is discarded so only the version in force remains. Texts without article structure, such as judgments, are split into fixed-size overlapping fragments.
This gives:
- Coherence: each statutory fragment makes sense on its own
- Citations with the article: the fragment carries its article number, so the answer can cite "art. 1964 CC" with its source
- Less noise: articles on different subjects are not mixed in one fragment
Hybrid Search, Threshold and Deduplication
- Two searches in parallel: a semantic one (by meaning) and a keyword one, which is better at finding an article number or a technical term. Their results are combined with Reciprocal Rank Fusion.
- Minimum relevance threshold: fragments below it are left out. The threshold adapts to the query: it is stricter when you cite a specific article or a quoted phrase.
- Reranking: when there are more candidates than fit, a lightweight model reorders them by actual relevance to the question.
- Deduplication: at most one fragment per source and article, so the context covers more distinct provisions.
- Bounded context: the chat uses up to 12 fragments split between the legal corpus, your documents and the firm library; more fragments add more noise.
Citation Verification
After generating the answer, Lexiel extracts the citations (articles, statutes, judgments, DGT rulings) and checks them: articles against the BOE, judgments against CENDOJ and the corpus itself. Each citation is marked verified or unverified, and unverified ones are flagged so you review them before use. Verification reduces the risk, it does not remove it: the final review is always the lawyer's.
The Result: 98.0% on the Official Exam
| System | Score |
|---|
| Lexiel with RAG | 98.0% |
A strong general model does well on a test. What the legal corpus and hybrid search add is that each citation carries its source and can be checked.
Illustrative Example: Mortgage Floor Clauses
An illustrative example to explain the difference, not a recorded answer.
Without RAG (general chatbot):
"A 2015 Supreme Court judgment declared floor clauses void."
Problem: you don't know which judgment it means or whether the number it gives exists. Manual verification required.
With RAG (Lexiel):
The answer cites STS 241/2013 of 9 May, by the Plenary of the First Chamber, on the transparency test for floor clauses, together with the retrieved fragment, the link to its source and its verification status.
The lawyer sees where each statement comes from and can check it in one click before citing it in a brief.
Frequently Asked Questions
Does Lexiel update its corpus regularly?
Yes. The BOE corpus is updated with new provisions, and case law from CENDOJ and the Constitutional Court is added periodically.
Can I add my own documents to the RAG?
Yes. The "Firm library" lets you upload your own documents, which are indexed and included in RAG searches for your organization.
Which LLM does Lexiel use?
Lexiel uses state-of-the-art AI models chosen for their legal reasoning. We evaluate models with the same exam and switch engines when one performs better on Spanish law.
What Lexiel Cannot Do
- If a judgment is very recent and not yet in the corpus, the citation will not show as verified
- Verification can mark a correct citation as "unverified" when it cannot confirm it; in that case, check it at the source
Try Lexiel's legal RAG free for 14 days →