What Is a Legal Corpus?
A legal corpus is the database of legal documents that feeds a RAG system. Its quality directly determines the quality of responses.
Sources of a Legal Corpus
- Legislation: BOE, regional official gazettes, EUR-Lex
- Case law: CENDOJ, constitutional court databases
- Administrative doctrine: DGT resolutions, DGRN, circulars
- Sectoral regulations: regulators (CNMC, Bank of Spain, CNMV)
Construction Process
- Ingestion: automated download from official sources
- Parsing: extraction of structured text (articles, grounds, ruling)
- Chunking: division into coherent semantic fragments
- Embedding: vectorization of each fragment
- Indexing: storage in vector database (pgvector)
Quality Problems
- Duplicates: the same regulation appears multiple times with slightly different wording
- Obsolete versions: repealed regulations still indexed
- Encoding: special characters poorly encoded (mojibake)
- Stubs: empty or incomplete records that contaminate results
Quality Metrics
| Metric | Description | Target |
|---|
| Coverage | % of key regulations indexed | >95% |
| Freshness | Average update time | <48h |
| Deduplication | Ratio of duplicates removed | >99% |
| Encoding | % of texts without encoding errors | 100% |
Continuous Maintenance
A legal corpus is not static. It requires:
- Daily monitoring of BOE and official gazettes
- Periodic deduplication
- Re-indexing after corrections
- Quality benchmarks against exam-type questions