A hybrid retrieval system that links Dutch legal advice letters to relevant case law using ECLI (European Case Law Identifier) citations. Built with a multi-stage RAG (Retrieval-Augmented Generation) architecture combining dense semantic search, sparse lexical matching, neural reranking, and domain-specific enhancement mechanisms.
| Video | YouTube | Repository |
|---|---|---|
| Teaser | Watch | Teaser_CiteConnect.mp4 |
| Full Demo | Watch | Demo_CiteConnect.mp4 |
- Hybrid Retrieval: Combines dense semantic search (multilingual-e5-large) with sparse lexical search (BM25) using Reciprocal Rank Fusion
- Neural Reranking: Cross-encoder reranking with ms-marco-TinyBERT-L-2-v2 for fine-grained relevance scoring
- Subject-Based Filtering: Segments legal advice letters into thematic issues for targeted retrieval
- Citation-Context Boosting: Leverages historical citation patterns to improve retrieval accuracy
- Popularity-Based Fallback: Incorporates landmark case recognition based on citation frequency
- Dutch Language Support: Native Dutch language processing with multilingual models
- Interactive Interface: Gradio web interface (CiteConnect) for legal professionals
- Python 3.12 (required for ChromaDB compatibility)
- 16GB RAM minimum
- ~5GB storage for models and indices
- GPU optional (supports MPS on macOS, CUDA on NVIDIA)
# Clone the repository
git clone https://github.com/bchiusano/CiteConnect.git
cd CiteConnect
# Install dependencies
pip install pandas openpyxl langchain langchain-classic langchain-chroma \
langchain-text-splitters langchain-huggingface langchain-community \
chromadb openai sentence-transformers tiktoken huggingface_hub \
flashrank rank-bm25 nlp spacy transformers torch
# Requirements .txt
Dependencies can also be installed after creating a virtual environment with the provided requirements.txt
# Download Dutch language model
python -m spacy download nl_core_news_md
# Download embedding model (optional - auto-downloads on first run)
export HF_HUB_ENABLE_HF_TRANSFER=1
huggingface-cli download intfloat/multilingual-e5-large --local-dir ./models/intfloatpython app.pyfrom test_rag_infloat_multilingual import LegalRAGSystem
# Initialize system
rag = LegalRAGSystem(initialize_summarizer=False)
# Query with a single letter
results = rag.query_single_letter(letter_text, approach="split")
# Results contain ranked ECLIs with relevance scores
for ecli, score in results[:10]:
print(f"{ecli}: {score:.3f}")# Run evaluation on test set
rag = LegalRAGSystem(initialize_summarizer=False)
rag.run_evaluation(
mode="sample",
search_approach="split",
num_rows=30,
random_seed=40
)The system implements a multi-stage hybrid retrieval pipeline:
-
Input Processing: Legal advice letter undergoes subject-based filtering, splitting into 5 thematic issue chunks using SpaCy Dutch NLP
-
Parallel Retrieval:
- Semantic: multilingual-e5-large embeddings → ChromaDB (HNSW) → top 200 candidates
- Lexical: BM25Okapi with domain keyword anchoring → top 200 candidates
-
Fusion: Reciprocal Rank Fusion (RRF) combines results with 70/30 semantic/lexical weighting
-
Reranking: ms-marco-TinyBERT-L-2-v2 cross-encoder reranks top 50 candidates
-
Enhancement: Citation-context boosting, issue-aware boosting, and popularity-based fallback adjust final scores
-
Output: Top-k ranked ECLIs with relevance scores normalized to [0, 1]
For detailed documentation on enhancement mechanisms (citation-context boosting, issue-aware boosting, popularity-based fallback), see RAG_ENHANCEMENTS_README.md.
Key hyperparameters in test_rag_infloat_multilingual.py:
| Parameter | Value | Description |
|---|---|---|
SEARCH_K |
200 | Candidates from each retrieval method |
RERANK_TOP_N |
50 | Candidates passed to reranker |
MIN_SCORE |
0.3 | Minimum relevance threshold |
RERANK_WEIGHT |
0.8 | Reranker vs. hybrid score blend |
| Semantic weight | 0.7 | RRF fusion weight |
| Lexical weight | 0.3 | RRF fusion weight |
Domain keywords are configured in resources/domain_config.py.
- Recall@k: Proportion of ground truth ECLIs in top-k results
- MRR@k: Mean Reciprocal Rank of first relevant result
Evaluation uses an 80/20 train-test split with fixed random seed (40) for reproducibility.
| Dataset | Description | Size |
|---|---|---|
| Case law corpus | Dutch legal decisions with ECLI | 2447 cases |
| Advice letters | Annotated letters with ground truth citations | 567 letters |
- Built with LangChain, ChromaDB, and HuggingFace
- Embedding model: intfloat/multilingual-e5-large
- Reranker: ms-marco-TinyBERT-L-2-v2 via FlashRank
