Generative artificial intelligence has transformed our approach to information, but its integration into the professional environment raises certain questions regarding the reliability and confidentiality of data.
To address these issues, Trilab (Trialog experimentation laboratory), as part of an internship, led a research and development project to design, develop, and evaluate a fully localized RAG (Retrieval-Augmented Generation) solution.
The goal of this initiative was to answer the following questions: How can a language model interact with Trialog’s internal data without that data leaving our infrastructure? What technologies are necessary to build such an ingestion and retrieval pipeline?
Traditional language models (LLMs) generate responses based on the data they were trained on. However, they lack knowledge of a company’s internal documents and can be prone to “hallucinations,” which occur when the LLM, lacking knowledge, starts inventing new, plausible-looking data.
The RAG technology solves this problem by adding an initial retrieval step. Concretely, when a user asks a question, the system first searches for relevant information in an internal database, then provides this context to the language model so it can generate an accurate, sourced, and up-to-date response (Augmented Generation).
For the needs of this project, we restricted the scope to a strictly localized system. This means that the entire process, from document ingestion to response generation, including the storage of vector data, runs on controlled infrastructure. This approach guarantees data security, a crucial point for industrial or confidential use cases.
The creation of this RAG system required the implementation of a robust and iterative data pipeline. Our project architecture relies on several key steps.

The Ingestion Pipeline (First step in figure 1)
The processing of our data sources, mainly consisting of internal documents in PDF format (deliverables, technical documentation, grant agreements, etc.), required the creation of a robust and automated ingestion pipeline in Python. This process is articulated in three critical phases:
- Intelligent Extraction: To extract text from PDFs, we use Optical Character Recognition (OCR), a lightweight AI model that treats PDFs as images and converts them to Markdown format.
- Custom Cleaning and Formatting: The initial conversion generates Markdown containing noise (orphaned tags related to non-preserved images, excessive line breaks, tables unreadable by a machine). We therefore developed a specific “cleaner” that scrubs this text, removes visual artifacts, and reformats complex elements to ensure the content is perfectly interpretable afterward.
- Chunking and Indexing: Once the text is cleaned, it is cut into segments (chunks). These segments are vectorized and then inserted into a vector database using the BGE-M3 model developed by BAAI (Beijing Academy of Artificial Intelligence).
Retrieval and Generation (Second step in figure 1)
Once our vector database was established, the main challenge was to isolate the right information before providing it to the language model. To avoid off-topic answers and guarantee reliability, we designed a three-step restitution process:
- Query Rewriting: User questions often contain conversational noise (“Thank you,” “I don’t understand,” etc.). Initially, an LLM analyzes the raw input and the conversation history to rewrite a clean, condensed, and purely factual search query.
- Two-Level Search (Retrieval & Reranking): This new query is vectorized to query the vector database, initially using Cosine Similarity, which calculates the angle (dot product) between the question vector and the different segment vectors present in the database. This first broad search allows us to quickly isolate the 100 most semantically close fragments (chunks). To ensure maximum precision, these 100 results are then scrutinized by a specific reranking model (bge-reranker-v2-m3), which re-evaluates the relevance of each fragment compared to the question to keep only the 5 most relevant.
- Constrained Generation: The final step consists of assembling the context. A dedicated function compiles the reformulated question, conversation history, the 5 final fragments, and above all, a very strict System Prompt. This set of instructions imposes an absolute framework of reliability on the local LLM: it is forbidden from inventing information (zero hallucination) and must explicitly admit its inability to answer if the provided context is insufficient.
Generation Model (Third step in figure 1)
For the generation phase, the challenge was to reconcile high reasoning capabilities with the constraints of strictly local execution. We chose the open-source gpt-oss-20b model [1].
The major asset of this model lies in its “Mixture of Experts” (MoE) architecture, which allows for reducing the number of parameters activated to generate a token. This reduces it from 20 billion activated parameters in a classic architecture to only 3.6 billion with this technology. This specificity allows for high performance while reducing inference time during generation.
Evaluation and Validation
To ensure the reliability of our solution, a rigorous testing campaign was automated using the DeepEval framework [2]. We created a dataset of 300 questions divided into 3 levels of difficulty (simple, multi-context, and with reasoning).
The evaluation focused on metrics specific to RAG architectures: faithfulness (the response contains no fabricated elements), answer relevance (the response is directly aligned with the question asked), as well as contextual precision and recall (the retrieved sources are properly ranked from most to least relevant and are exhaustive). After optimizations, the system achieved a user success rate of 84.04% (combining faithfulness and relevance above a threshold of 0.7).
Conclusion and Perspective
The project resulted in a fully functional proof of concept, encapsulated in a microservices architecture and equipped with a streamlined web interface for fluid use. Our system thus offers a secure and high-performance knowledge capitalization solution.
The next steps to deploy this system will include the implementation of a hybrid document search (semantic and lexical) to reduce the limitations of a unique semantic search. Furthermore, an evolution towards an agentic RAG would allow the model to reason about the retrieval strategy itself. This would allow it to choose whether it should refine its retrieval or consult more sources before generating its response.



