Ontology-Grounded RAG with SPARQL and Local Language Models for Technical Documentation
Abstract
This paper presents LIDI-AI, a Retrieval-Augmented Generation (RAG) system whose knowledge base consists of technical documentation for the LIDI-AI Research Assistant, a web-based data analysis application developed at Universidad del Azuay. The runtime architecture integrates two complementary knowledge sources: an OWL 2 ontology (artifact version 2.0) with six classes and twenty-five properties (nine object and sixteen datatype properties) that models the five-stage pipeline, the accepted file formats, the statistical analysis types, and the system errors, and a SPARQL 1.1 query layer for structured intent resolution. A Prolog knowledge base built on an Object-Attribute-Value (OAV) representation, comprising 172 facts, 17 inference rules, and three diagnostic engines, is formally specified and validated as a symbolic reasoning layer, although it is not yet callable from the Python orchestrator at runtime. A lexical retrieval module selects ontology fragments as grounded context for a locally hosted language model, specifically Llama-3.2-3B deployed via the Ollama framework with Q4_K_M quantization. Evaluation on ten queries from real users shows that seven were resolved with high precision via SPARQL-grounded retrieval, two were resolved via lexical fallback with ontology traceability, and one out-of-domain query received an explicit knowledge-limit acknowledgment, yielding an appropriate response rate with zero hallucinations.