Large Language Models (LLMs) have demonstrated strong capabilities in natural language understanding and reasoning, yet they remain unreliable in mathematical problem solving due to hallucinations, arithmetic inconsistencies, and limited transparency in intermediate reasoning steps. This thesis proposes a structured Retrieval-Augmented Generation framework, termed \textit{MathRAG}, designed to improve reliability and precision in mathematical question answering by integrating knowledge graph retrieval with deterministic tool execution. The proposed system extracts formulas from domain-specific documents, converts them into structured entities enriched with semantic metadata, and stores them in a knowledge graph. Upon receiving a user query, the framework performs semantic retrieval over embedded formula representations, selects the most relevant formula, and dynamically synthesizes a computational tool from a validated Python template. Numerical computation is then executed deterministically, separating symbolic reasoning from language generation and thereby reducing hallucination risks. This whole process of question answering is encapsulated inside a ReAct-style reasoning loop, in order to take advantage of the CoT-reasoning ability of the language model as much as possible. The system is evaluated on a dataset of 600 mathematical questions spanning Physics and Chemistry domains. Results show that the primary bottleneck lies in tool recognition and retrieval rather than in numerical execution. While overall accuracy across the full dataset reaches 28\%, conditional accuracy rises above 58\% when the correct tool is instantiated, demonstrating the robustness of deterministic computation once the appropriate formula is selected. A domain-level analysis reveals a significant performance gap between the two questions' domains, highlighting the impact of formula structure, metadata consistency, and semantic alignment on retrieval effectiveness. The findings confirm that combining structured knowledge representation with executable tools substantially improves computational reliability and interpretability compared to purely generative approaches. However, system performance remains strongly dependent on retrieval precision, metadata quality, and ingestion robustness. The thesis concludes that hybrid knowledge-grounded architectures such as MathRAG constitute a promising direction for trustworthy mathematical reasoning systems, provided that future work further enhances semantic matching, document standardization, and knowledge graph consistency.
I Large Language Models (LLM) hanno dimostrato notevoli capacità nella comprensione e nel ragionamento in linguaggio naturale; tuttavia, rimangono inaffidabili nella risoluzione di problemi matematici a causa di fenomeni come allucinazioni, incoerenze aritmetiche e scarsa trasparenza nei passaggi intermedi del ragionamento. Questa tesi propone un framework strutturato di Retrieval-Augmented Generation, denominato \textit{MathRAG}, progettato per migliorare affidabilità e precisione nel rispondere a domande di carattere matematico attraverso l’integrazione tra recupero di conoscenza da un knowledge graph ed esecuzione deterministica di strumenti computazionali. Il sistema proposto estrae formule da documenti contenenti formule e/o leggi matematiche, le converte in entità strutturate arricchite con metadati semantici e le memorizza in un knowledge graph. Alla ricezione di una query, il framework esegue una ricerca semantica sulle rappresentazioni vettoriali delle formule, seleziona quella più pertinente e sintetizza dinamicamente uno strumento computazionale a partire da un template Python validato. Il calcolo numerico viene quindi eseguito in modo deterministico, separando il ragionamento simbolico dalla generazione linguistica e riducendo il rischio di allucinazioni. L’intero processo di risposta è incapsulato in un ciclo di ragionamento in stile ReAct, così da sfruttare al massimo le capacità di Chain-of-Thought dell'LLM. Il sistema è stato valutato su un dataset di 600 domande matematiche appartenenti ai domini della Fisica e della Chimica. I risultati mostrano che il principale collo di bottiglia risiede nella fase di riconoscimento e selezione dello strumento, piuttosto che nell’esecuzione numerica. Sebbene l’accuratezza complessiva sull’intero dataset sia pari al 28\%, l’accuratezza condizionata supera il 58\% nei casi in cui viene istanziato lo strumento corretto, dimostrando la robustezza dell’esecuzione deterministica se la giusta formula é stata selezionata. L’analisi a livello di dominio evidenzia inoltre un significativo divario prestazionale tra Fisica e Chimica, sottolineando l’impatto della struttura delle formule, della coerenza dei metadati e dell’allineamento semantico sull’efficacia del recupero. I risultati confermano che la combinazione tra rappresentazione strutturata della conoscenza ed esecuzione di strumenti computazionali migliora significativamente l’affidabilità e l’interpretabilità rispetto ad approcci puramente generativi. Tuttavia, le prestazioni del sistema rimangono fortemente dipendenti dalla precisione del recupero, dalla qualità dei metadati e dalla robustezza del processo di ingestione. La tesi conclude che architetture ibride knowledge-grounded come MathRAG rappresentano una direzione promettente per lo sviluppo di sistemi di ragionamento matematico affidabili, a condizione che lavori futuri si concentrino sul miglioramento dell’allineamento semantico, della standardizzazione dei documenti e della coerenza del knowledge graph.
MathRAG: an agentic question answering architecture for mathematical problems based on structured knowledge graphs
MORELLI, DAVIDE
2025/2026
Abstract
Large Language Models (LLMs) have demonstrated strong capabilities in natural language understanding and reasoning, yet they remain unreliable in mathematical problem solving due to hallucinations, arithmetic inconsistencies, and limited transparency in intermediate reasoning steps. This thesis proposes a structured Retrieval-Augmented Generation framework, termed \textit{MathRAG}, designed to improve reliability and precision in mathematical question answering by integrating knowledge graph retrieval with deterministic tool execution. The proposed system extracts formulas from domain-specific documents, converts them into structured entities enriched with semantic metadata, and stores them in a knowledge graph. Upon receiving a user query, the framework performs semantic retrieval over embedded formula representations, selects the most relevant formula, and dynamically synthesizes a computational tool from a validated Python template. Numerical computation is then executed deterministically, separating symbolic reasoning from language generation and thereby reducing hallucination risks. This whole process of question answering is encapsulated inside a ReAct-style reasoning loop, in order to take advantage of the CoT-reasoning ability of the language model as much as possible. The system is evaluated on a dataset of 600 mathematical questions spanning Physics and Chemistry domains. Results show that the primary bottleneck lies in tool recognition and retrieval rather than in numerical execution. While overall accuracy across the full dataset reaches 28\%, conditional accuracy rises above 58\% when the correct tool is instantiated, demonstrating the robustness of deterministic computation once the appropriate formula is selected. A domain-level analysis reveals a significant performance gap between the two questions' domains, highlighting the impact of formula structure, metadata consistency, and semantic alignment on retrieval effectiveness. The findings confirm that combining structured knowledge representation with executable tools substantially improves computational reliability and interpretability compared to purely generative approaches. However, system performance remains strongly dependent on retrieval precision, metadata quality, and ingestion robustness. The thesis concludes that hybrid knowledge-grounded architectures such as MathRAG constitute a promising direction for trustworthy mathematical reasoning systems, provided that future work further enhances semantic matching, document standardization, and knowledge graph consistency.| File | Dimensione | Formato | |
|---|---|---|---|
|
Morelli_Thesis__MathRAG____2026.pdf
accessibile in internet per tutti
Dimensione
1.62 MB
Formato
Adobe PDF
|
1.62 MB | Adobe PDF | Visualizza/Apri |
I documenti in POLITesi sono protetti da copyright e tutti i diritti sono riservati, salvo diversa indicazione.
https://hdl.handle.net/10589/252303