← cd ../projects

Legal AI Assistant — KG-Enhanced LLM for Italian Law

RAGKnowledge GraphPyTorchQdrantStreamlitGAT

Development of a conversational assistant for the Italian legal domain based on an original architecture that combines RAG with Hybrid Search and a Knowledge Graph-enhanced LLM. The system draws on two knowledge sources: the Italian Civil Code indexed on Qdrant through a three-level Hybrid Search (dense with multilingual-e5-large, sparse with BM25, re-ranking with ColBERTv2.0), and Italian case law modeled as a Knowledge Graph (~4,700 nodes, ~19,600 edges) with NetworkX.

To integrate the graph into the LLM (frozen Qwen3-1.7B), a GAT (Graph Attention Network) pre-trained with link prediction, a GraphProjector (MLP, GNN dim 128 → LLM dim 2048) and a Cross-Attention module with gating mechanism were implemented natively in PyTorch, trained with a combined cross-entropy + InfoNCE loss.

The Streamlit interface supports a classic RAG mode (Mistral Large via API with function calling / local models via Ollama) and a KG-Enhanced mode with the full graph-LLM pipeline.