← Writing & notes

FROM THE NOTEBOOK

Building a High-Quality RAG Application

Introduction

InfoWiz, a Retrieval-Augmented Generation (RAG) application built to unlock the knowledge hidden within a vast collection of corporate documents. As an AI engineer on this project, I want to walk you through the journey of how we brought InfoWiz to life, from the initial stages of data processing to the final, sophisticated application you see today. This is a tale of challenges, innovative solutions, and a relentless focus on quality.

Chapter 1: The Foundation - A Deep Dive into Data Ingestion and Processing

Every RAG application begins with the data. Our challenge was to take a diverse set of documents—PDFs, DOCX files, and more—and transform them into a format that a language model could understand and use effectively. This is where our data ingestion pipeline came in, and it's far more than a simple script.

The heart of this process lies in the utilities/chunking directory. We knew that simply splitting the documents into fixed-size chunks wouldn't be enough. We needed to preserve the context and structure of the original documents. To achieve this, we developed a sophisticated, multi-stage chunking strategy:

This meticulous and multi-faceted approach to data processing laid a solid foundation for the next stage: building our knowledge base.

Chapter 2: Building the Knowledge Base - Sophisticated Indexing

With our documents processed into high-quality, metadata-rich chunks, the next step was to create a searchable index. For this, we turned to two powerful tools: LlamaIndex and ChromaDB.

The utilities/Indexes_creation/produce_index_from_chunks.py script is where the magic happens. Here's how it works:

  1. Iterating Through Chunks: The script processes the JSON files from our chunking pipeline.
  2. Creating Nodes with Relationships: For each chunk, it creates a TextNode in LlamaIndex. Crucially, we preserved the relationships between chunks. Each node is linked to its PREVIOUS and NEXT nodes, and back to its SOURCE document. This allows us to retrieve not just a single chunk, but a window of surrounding context, which dramatically improves the quality of the generated responses.
  3. Storing in ChromaDB: The nodes are then indexed and stored in a ChromaDB collection, creating a highly searchable and contextually aware knowledge base.

Chapter 3: The Heart of the Application - An Advanced RAG Engine

With our knowledge base in place, it was time to build the application itself. The core logic resides in infowiz/app.py, and it's built on the Viktor framework, which allowed us to create a sophisticated, multi-page web application.

But the true innovation of InfoWiz lies in its advanced RAG engine:

Chapter 4: Ensuring Quality - A Multi-Faceted Approach to Testing and Evaluation

A high-quality RAG application requires a rigorous approach to quality assurance. We implemented a multi-faceted strategy that combines traditional testing with cutting-edge, metric-driven evaluation.

Chapter 5: The Technology Stack

InfoWiz is built on a modern and powerful technology stack:

Conclusion

The journey of building InfoWiz has been a challenging but rewarding one. From the meticulous processing of our source documents to the development of a sophisticated, multi-page application and a rigorous evaluation framework, we've built a powerful tool for unlocking the knowledge hidden in our corporate data.

The dynamic query engine selection, the use of a ReAct agent, the federated search with automated citations, and the metric-driven approach to quality all demonstrate a commitment to engineering excellence. InfoWiz is more than just a RAG application; it's a testament to what can be achieved with a clear vision, a powerful technology stack, and a relentless focus on quality.

All writing