October 19, 2026
AI Assistant with RAG and local LLMs via Ollama for natural language data exploration.
AI Assistant with Local RAG and LLMs Via Ollama for Natural Language Data Exploration.
Tales Henrique Branquinho; Igor Pinheiro de Araújo Costa
DOI: 10.22167/2675-6528-202603476
Article derived from a Course Conclusion Work (TCC), with content based on the student’s original work and adapted to the editorial format of the E&S Magazine with the support of the ResumeAI tool, an artificial intelligence solution developed by Instituto Pecege for textual synthesis and organization.
Summary
The implementation of an Artificial Intelligence assistant based on the Retrieval-Augmented Generation (RAG) technique was investigated, using large language models (LLMs) executed locally through the Ollama platform. The objective was to enable natural language data exploration, eliminating the need for technical knowledge in programming languages or SQL queries. A functional prototype was developed that retrieved relevant information from a vectorized data dictionary in ChromaDB and generated SQL instructions coherent with the context of the queries. For this, the Qwen 3:8B model was used for response generation, the nomic-embed-text model for semantic vectorization, and the LangChain framework for integration between retrieval and response. The execution took place in a Google Colab environment with GPU usage. During validation, the assistant produced technically valid SQL instructions aligned with the provided queries, demonstrating technical feasibility, contextual accuracy, and potential application in scenarios requiring privacy and autonomy in data processing. The results showed that the quality of the responses depended directly on the accuracy of the data dictionary used and the instructions given to the model, confirming that the proposed solution reduced the need for advanced knowledge in data analysis and presented significant potential for corporate and academic applications demanding privacy, autonomy, and data governance.
Keywords: Vector Database; Retrieval Augmented Generation; SQL Query Generation from Natural Language; Generative Artificial Intelligence; Large Language Models.
1. Introduction
The field of data science has witnessed a significant increase in demand for intelligent and autonomous solutions, driving the advancement of artificial intelligence (AI)-based technologies. Within this landscape, natural language processing (NLP) emerges as a crucial area, with large language models (LLMs) standing out as powerful tools. These models are capable of generating text, performing semantic analysis, and interacting in natural language, demonstrating high coherence and contextualization after being trained with vast textual datasets (IBM, 2025; SAP, 2024).
However, LLMs present inherent limitations, such as dependence on static training data, lack of updated knowledge, and difficulty in accessing specific information from restricted domains. To mitigate these barriers, the Retrieval-Augmented Generation (RAG) technique, proposed by Meta AI researchers in 2020, emerges as an effective solution. RAG integrates the generative capability of LLMs with external information retrieval systems, enabling models to access updated and specific databases in real-time. This results in more accurate, reliable, and contextualized responses.
The application of the RAG technique in data analysis agents represents an evolution in professionals’ interaction with large volumes of information. By combining search mechanisms with natural language generation, these agents can explore complex datasets, respond to natural language queries, and provide analyses based on verifiable sources. This approach is particularly relevant in corporate and academic contexts, where the precision and timeliness of information are essential for decision-making (Red Hat, 2024; Oracle Brasil, 2023).
In parallel, the growing concern with privacy, autonomy, and operational cost has fostered the adoption of offline solutions for executing AI models. In this scenario, the Ollama platform stands out, as it allows LLMs to be executed locally, eliminating the dependence on external cloud services. Ollama provides a simplified and secure environment for running models such as Llama 3, Mistral, Qwen 3, and DeepSeek, enabling applications on personal devices and local servers with full control over the processed data (Ollama, 2025).
Exploratory data analysis, a fundamental step in the data science lifecycle, often requires advanced knowledge in programming languages, such as Python or R, or in query languages, such as SQL. This technical requirement can constitute a barrier for many professionals, limiting access to relevant information and hindering data analysis.
The central problem of this research lies in the growing demand for intelligent systems that integrate textual generation with access to updated data, operating autonomously and securely in local environments. Therefore, we seek to demonstrate the technical viability of the proposed approach, as well as its benefits in terms of privacy, efficiency, and applicability in real-world scenarios, reducing the need for specialized technical knowledge and optimizing the analysis process. Thus, the objective of this work is to implement an AI assistant based on RAG and language models executed locally via Ollama, capable of allowing queries to databases in natural language, without the need for direct code writing or SQL commands.
2. Material and Methods
The present research adopted an applied methodological approach, complemented by a theoretical basis, with the purpose of demonstrating the technical feasibility and benefits of implementing an artificial intelligence assistant. This assistant was designed based on the Retrieval-Augmented Generation (RAG) technique and utilized large language models (LLMs) executed locally via the Ollama platform, focusing on applicability in real-world scenarios, privacy, and efficiency.
The research strategy consisted of the development of a functional AI assistant prototype, focusing on its construction, configuration, and technical evaluation. Data collection was carried out through a documentary survey of techniques, tools, and procedures. As an external knowledge base, a simulated data dictionary from a relational database of service orders in a generic industrial context was used. To standardize and structure this information, a JSON file (“DicionarioTabelas.json”) was created. A Python script organized the textual content into documents for each table, its columns, and relationships.
The assistant’s architecture was based on the Retrieval Augmented Generation (RAG) technique, which combines pre-trained LLMs with document retrieval mechanisms to access explicit external knowledge (NeurIPS, 2020). The LLMs were executed locally, using the Ollama platform, allowing the models to operate without dependence on external cloud services, ensuring greater privacy and autonomy over the processed data.
For the generation of responses, the Qwen 3:8B language model was employed, selected for its balance between performance, computational cost, and speed, in addition to its multilingual and advanced reasoning capabilities (Qwen3 Technical Report, 2025). For the semantic vectorization of texts, the nomic-embed-text model was used, responsible for transforming textual documents into numerical vectors (embeddings), essential for the semantic retrieval of relevant information in the RAG architecture.
The integration between the retrieval and generation components was orchestrated by the LangChain framework (LANGCHAIN DOCS, 2025). This framework facilitated the implementation of the RAG technique, including chaining calls to LLMs and managing the flow of retrieval and response generation. The efficient storage and retrieval of semantic text representations were carried out in a local vector database, ChromaDB, which supports vector similarity-based searches.
The computational environment used for the development, execution, and validation of the prototype was Google Colab. The choice was justified by the ease of configuration, availability of computational resources, and support for iterative experimentation, especially access to T4 type Graphics Processing Units (GPUs). The use of GPU was necessary to optimize performance and accelerate the execution of language models.
The environment preparation involved the installation and initialization of the Ollama platform, providing a local service on port 11434. The Qwen 3:8B and nomic-embed-text models were installed via Ollama, along with ChromaDB and LangChain. A Python script instantiated nomic-embed-text to convert textual documents from the data dictionary into numerical vectors, which were persisted in ChromaDB in a specific collection for semantic searches.
The final stage consisted of the execution and validation of the assistant. The prepared tools and information were integrated using a Python script, which defined the LLM model, the prompt template with security rules, and the retrieval mechanism. For validation, natural language questions were formulated to the assistant, relevant to the documented data dictionary, focusing on information about service orders. The validity of the SQL instructions generated in response to these requests was evaluated.
3. Results and Discussion
The results obtained in this work demonstrate the technical viability and practical potential of implementing an artificial intelligence (AI) assistant based on the Retrieval Augmented Generation (RAG) technique, using large language models (LLMs) executed locally through the Ollama platform. The proposed solution allows the exploration of structured data in natural language, overcoming the need for technical knowledge in programming languages or SQL queries. The analysis of the findings goes beyond the simple presentation of performance metrics, interpreting the solution’s contribution in technical, comparative, managerial, and academic dimensions, according to the research problem and established objectives.
Assistant performance and technical contribution of the architecture
The assistant validation process was conducted by formulating fifteen natural language questions, all related to the data dictionary used as a knowledge base, focusing on information about service orders in a generic industrial context. The assistant succeeded in ten out of the fifteen queries made, representing an average accuracy rate of approximately 67%. This performance is considered satisfactory within the exploratory scope of the study, indicating the effectiveness of the RAG approach in translating natural language into SQL queries.
It was observed that the assistant demonstrated greater precision in queries involving direct filters on attributes clearly defined in the data dictionary. Examples include the service order closure status, the associated plant, the priority, the existence of a scheduled downtime, or the indication of a stopped equipment. In these cases, the generated SQL queries correctly used the tables and columns described in the schema, respecting the restrictions imposed by the prompt, such as the prohibition of data modification commands and the need for exclusive use of SELECT-type statements. Questions 1, 3, 4, 6, 7, 8, 9, 12, 13, and 14 illustrate this precise behavior.
These results corroborate the literature that points to greater adherence to the context of RAG-based architectures, especially when compared to the isolated use of language models in tasks that require strict alignment to external structured knowledge sources. The retrieval of relevant snippets from the vectorized data dictionary at the time of response generation was crucial, as it allowed the model to reduce the occurrence of fabricated information and produce semantically more precise SQL instructions, as expected for RAG systems (Lewis et al., 2020).
On the other hand, the failures observed in approximately 33% of the questions reveal important points about the adopted approach. In some cases, the model generated semantically incorrect queries, as in Question 2, where it used the closing date field instead of the issue date for period filtering. In another case, represented by Question 10, the model generated a query containing the NUM_OS column, which was not defined in the data dictionary, characterizing the invention of a non-existent attribute in the relational schema.
These results indicate that, although the retrieval mechanism provides additional context to the model, there is still a significant dependence on the conceptual clarity and semantic standardization of the data dictionary used as a knowledge base. The quality of the response is directly related to the accuracy of the data dictionary and the instructions provided to the model, underscoring the importance of a well-structured and detailed knowledge repository for the success of the RAG application.
A recurring and positive behavior was the explicit response of absence of sufficient information to generate the query, observed in Questions 5, 11, and 15. Although these responses were counted as errors in the accuracy rate, they represent a favorable aspect from the perspective of information governance and security. The prompt was designed to prevent the invention of non-existent tables, columns, or relationships, and the model behaved correctly by recognizing the insufficiency of context, thus avoiding the generation of speculative or incorrect information.
Regarding computational performance, the average response time observed was approximately 31.9 seconds per query. This value partly reflects the inherent limitations of locally executing a language model with 8 billion parameters, especially considering that the Google Colab environment used did not have a subscription, which implied intermittent availability and resource constraints, even with GPU usage. Therefore, the response time should not be interpreted as a structural limitation of the proposed architecture.
The use of dedicated and adequately sized hardware tends to significantly reduce system latency, according to the literature on LLM optimization (Yang et al., 2025). In the adopted experimental context, the observed times are acceptable and reinforce the main differential of the approach, which is local execution with greater control, privacy, and autonomy over the analyzed data, a fundamental requirement for many corporate and academic applications (Ollama, 2025).
Comparative analysis
To understand the contribution of the proposed architecture, it is relevant to compare it to alternative scenarios. In a scenario where an LLM is used in isolation, without the RAG technique, the model relies exclusively on its internal knowledge, acquired during training. In this situation, the generated queries tend to be incompatible with the actual database schema, frequently resulting in the invention of non-existent columns, incorrect joins, and inadequate filters.
The incorporation of the RAG-based semantic retrieval mechanism proved essential for correcting these issues, by providing the model, at the time of generation, with explicit information about tables, columns, and relationships effectively defined in the data dictionary. This approach ensures that the responses are based on verifiable information and aligned with the specific context of the database, increasing the reliability and accuracy of the generated SQL queries (Red Hat, 2024).
When compared to the traditional process of manual consultation in SQL, the proposed solution presents clear advantages from the information access point of view. Manual writing of SQL queries requires prior technical knowledge, familiarity with the database schema, and time dedicated to exploring and validating queries. The developed assistant acts as an intermediate layer between the user and the database, translating informational needs expressed in natural language into structured queries.
This translation significantly reduces the technical barrier for non-specialist users and streamlines the information retrieval process. In organizational contexts where non-technical users rely on specialized analysts for queries, the assistant can reduce operational bottlenecks by allowing recurring questions to be answered autonomously, securely, and in a controlled manner. The proposal does not aim to replace the data analyst, but rather to act as a support tool for analysis, especially in the initial stages of exploration or for frequent operational queries (Oracle Brasil, 2023).
Managerial impacts
From a managerial perspective, the proposed assistant shows significant potential as a decision-support tool. By allowing managers and analysts to directly express their informational needs in natural language, the solution reduces the gap between identifying a demand and obtaining the corresponding structured information. This reduction in time and technical effort can lead to more agile decision-making processes based on up-to-date data, contributing to greater operational efficiency.
In organizational environments, especially industrial ones, where operational decisions depend on accurate and timely information, ease of access to this data can bring relevant efficiency gains. The assistant enables users to focus on interpreting results and defining actions, instead of dedicating time to the technical construction of queries, contributing to a more data-driven organizational culture and driving innovation (IBM, 2025).
Additionally, the fact that the solution operates entirely in a local environment reinforces critical aspects of privacy and governance, making it particularly suitable for organizations that handle sensitive data or have restrictions on the use of cloud services. This autonomy and control over data are important differentiators in a growing scenario of concerns about information security and regulatory compliance.
Academic and social contributions
From an academic perspective, this work contributes by demonstrating, in an applied manner, the use of the RAG technique integrated with locally executed language models for structured data exploration. Although the literature on RAG is predominantly focused on the retrieval of unstructured textual documents, this study highlights its applicability also in relational database scenarios, broadening the scope of use of this architecture and opening new research fronts for the integration of LLMs with structured knowledge bases.
From a social and organizational point of view, the proposed solution points to the democratization of access to information, by expanding the autonomy of non-technical users and reducing barriers associated with SQL language and dependence on specialists. By enabling the local execution of modern language models, the approach also favors environments with greater control over data, contributing to the reduction of dependence on external services and technical knowledge in query and programming languages, without renouncing fundamental requirements such as security, privacy, and control over information (SAP, 2024).
In summary, the results obtained confirm the technical viability of implementing an AI assistant based on RAG and LLMs executed locally for natural language data exploration. The developed prototype demonstrated the ability to generate coherent SQL queries in the context of the questions, provided that the data dictionary is consistent and well-documented. Although the observed computational performance limitations were associated with the experimental environment, the solution presents significant practical potential for scenarios that demand greater control, privacy, and autonomy in data access and analysis, while reducing the dependence on specialized technical knowledge in query languages.
4. Conclusion
This study aimed to implement an artificial intelligence assistant based on the Retrieval-Augmented Generation (RAG) technique and large language models (LLMs) executed locally via Ollama, with the goal of enabling natural language queries to databases, eliminating the need for knowledge in programming languages or SQL. The technical feasibility of the proposed solution was verified, which demonstrated the ability to retrieve relevant information from a vectorized data dictionary and generate SQL instructions consistent with the provided queries. It was observed that the prototype succeeded in ten out of fifteen queries performed, showing precision in direct filters on well-defined attributes. However, it was identified that the quality of the responses depended directly on the conceptual clarity and semantic standardization of the data dictionary, as well as the instructions given to the model, resulting in failures when the context was insufficient or ambiguous, or in the invention of non-existent attributes. A positive aspect was the assistant’s ability to recognize the absence of information and respond explicitly, avoiding the generation of speculative data.
The main contribution of this work lies in demonstrating the applicability of the RAG architecture in structured data exploration scenarios, expanding its scope beyond unstructured textual documents. From a managerial and practical standpoint, the solution offers significant support for decision-making by lowering the technical barrier for non-specialist users and streamlining access to information, promoting greater autonomy and operational efficiency. Additionally, the local execution of models via Ollama reinforces data privacy and governance, crucial aspects for corporate and academic environments with sensitive information. The observed computational performance limitations, with an average response time of thirty-one point nine seconds, were attributed to the experimental Google Colab environment, which had intermittent resources, and not to the architecture itself, indicating that latency can be significantly reduced with dedicated hardware. The research, therefore, points towards the democratization of information access and the reduction of dependence on specialized technical knowledge, without compromising data security and control.
Bibliographic References
IBM, 2025. O que é LLM (large language models)? IBM Think. Disponível em: https://www.ibm.com/br-pt/think/topics/large-language-models. Acesso em: 28/10/2025.
LANGCHAIN DOCS, 2025. Build a RAG agent with LangChain. Disponível em: https://docs.langchain.com/oss/python/langchain/rag#build-a-rag-agent-with-langchain. Acesso em: 12/01/2026.
LEWIS, Patrick; PEREZ, Ethan; PIKTUS, Aleksandra; PETRONI, Fabio; KARPUKHIN, Vladimir; GOYAL, Naman; KÜTTLER, Heinrich; LEWIS, Mike; YIH, Wen-tau; ROCKTÄSCHEL, Tim; RIEDEL, Sebastian; KIELA, Douwe. Retrieval-Augmented Generation for Knowledge-Intensive NLP Tasks. In: ADVANCES in Neural Information Processing Systems 33 (NeurIPS 2020). Disponível em: https://proceedings.neurips.cc/paper_files/paper/2020/file/6b493230205f780e1bc26945df7481e5-Paper.pdf. Acesso em: 12/01/2026.
NeurIPS, 2020 [Referência completa não encontrada no documento original]
Ollama, 2025. Documentação oficial do Ollama. Disponível em: https://docs.Ollama.com/. Acesso em: 28/10/2025.
ORACLE, 2023. Retrieval-Augmented Generation (RAG). Disponível em: https://www.oracle.com/br/artificial-intelligence/generative-ai/retrieval-augmented-generation-rag/. Acesso em: 28/10/2025.
Qwen3 Technical Report, 2025 [Referência completa não encontrada no documento original]
RED HAT, 2024. O que é geração aumentada por recuperação (RAG)? Disponível em: https://www.redhat.com/pt-br/topics/ai/what-is-retrieval-augmented-generation. Acesso em: 28/10/2025.
SAP, 2024. O que são modelos de linguagem de grande escala? Disponível em: https://www.sap.com/brazil/resources/what-is-large-language-model. Acesso em: 28/10/2025.
YANG, An et al. Qwen3 Technical Report. 2025. Disponível em: <https://arxiv.org/abs/2505.09388>. Acesso em: 12/01/2026.
Article originating from the Final Course Project of the Specialization in Data Science and Analytics of the MBA USP/Esalq
To learn more about the course, click here and access the MBX Academy platform