Technology Review
There were two possible solutions that we came across in our research: firstly a RAG based approach[4] and an AI SQL Agent Approach[2]. The SQL Agent approach is the one we implemented in our final project.
RAG Based Approach
This approach intended to use a standard RAG approach, similar to the other use cases. However, it would replace fixed-size chunking with a structured chunking strategy:
- Row-based chunking: For insights into individual records within the Excel sheet.
- Column-based chunking: For general insights across the entire dataset.
Additionally, this approach would pre-calculate and store statistics (e.g., average, minimum, maximum, standard deviation) for general insights into the data.
SQL Agent Approach (implemented)
This approach is quite different from RAG. Instead of a vector store, retriever, and chunking operations, it uses an SQLite in-memory database.
The Excel file is first converted to a pandas dataframe. The sheet names and column headers are made SQL friendly, and data is formatted with the correct data types. These features allow data to be easily queried.
An agent is created using the LLama model and the agentic API through Ollama. The agent is provided with a tool (a Python function) and a schema of the database, which it uses to query the database.
The data returned from the Agent's query is given again to the LLM so that it can generate a response. In short, the SQLite database replaces the vector store, the Agent replaces the retriever, and there is no chunking, only preprocessing.
Technical Choices
The SQL agent approach was selected for this use case due to several factors:
- Speed: It delivered faster responses than the RAG-based approach, given the nature of the data.
- Scalability: It is more sustainable in the long run, as telemetry data can grow quite large, which a RAG-based approach might not handle well, leading to inaccurate results.
- Accuracy: The SQL approach is inherently more accurate because it eliminates the possibility of the LLM hallucinating or imagining data.