TL;DR
NotebookRAG is a novel framework that automates Exploratory Data Analysis (EDA) by retrieving, enhancing, and reusing code and insights from existing data science notebooks. By treating notebooks as dynamic, executable components rather than static text documents, it allows Large Language Models (LLMs) to generate highly relevant, context-aware analysis plans and visualizations tailored to new or updated datasets.
What Problem Does This Paper Address?
Exploratory Data Analysis (EDA) is a crucial first step in any data science pipeline, helping analysts understand data distributions, anomalies, and patterns. However, high-quality EDA requires significant statistical expertise, visualization literacy, and coding proficiency.
While LLM-based tools (like the ChatGPT Data Analyst plugin) can automate parts of this process, they struggle when user intent is abstract (e.g., "perform EDA to prepare for time-series forecasting"). Consequently, they often produce generic, shallow insights and basic visualizations.
Meanwhile, platforms like Kaggle and enterprise repositories contain a vast wealth of "crowd-wisdom" in the form of existing computational notebooks. Standard Retrieval-Augmented Generation (RAG) methods fail to exploit this knowledge because they treat notebooks as static text. They ignore cell dependencies, break when data versions change, and fail to capture the executable nature of code.
Methods
NotebookRAG bridges this gap by introducing a two-stage pipeline: Notebook Retrieval and Notebook Generation.
1. Notebook Retrieval
- Component Extraction: Instead of indexing code cells independently, NotebookRAG uses static analysis to trace data-variable dependencies across the notebook. It merges dependent cells into self-contained, executable "Components" to ensure they can run standalone without missing variables.
- Metadata Annotation: LLMs annotate each component with the specific data columns it uses and its chart type, bypassing the semantic gap between natural language and raw code.
- Intent-Guided Retrieval: The system decomposes abstract user intent into multiple concrete EDA queries, matching them against markdown embeddings and component metadata.
- Component Enhancement: Retrieved components are re-executed on the new dataset in a sandbox environment. A Vision-Language Model (VLM) inspects the freshly generated charts to extract insights. To eliminate VLM hallucinations, an LLM writes statistical code to verify and refine these visual insights with precise data facts.
2. Notebook Generation
An intelligent agent architecture—consisting of a Planner, Progress Manager, Coder, and Summarizer—assembles the final product. The Planner ingests the retrieved insights as implicit guidance to prioritize analytical steps (e.g., moving anomaly detection earlier if past notebooks flagged major outliers). The Coder then selectively reuses or adapts the validated code components to output a coherent, executable .ipynb notebook.
Datasets
The authors evaluated NotebookRAG using three widely analyzed Kaggle datasets that reflect typical real-world enterprise scenarios (where data is continuously updated or exists in multiple versions):
- Avocado Prices
- Superstore Sales
- Netflix Movies and TV Shows
For each dataset, they collected the top 20 upvoted Python notebooks on Kaggle to serve as the reference corpus for retrieval.
Key Insights and Ideas
- Code as an Executable Artifact: The core shift is treating notebooks as dynamic code blocks rather than text. Tracking the lifecycle of data variables allows the system to "heal" broken code dependencies and successfully rerun old code on new data.
- The VLM + LLM Verification Loop: Relying solely on a VLM to read charts introduces factual errors. NotebookRAG pairs the VLM's visual pattern recognition with an LLM-generated statistical verification step, combining the best of visual intuition and exact computation.
- Implicit Planning Guidance: Simply providing past insights to the Planner naturally aligns the automated workflow with human analytical priorities without needing explicit user instructions.
Key Results
The authors conducted a within-subject user study with 24 experienced data analysts, comparing NotebookRAG against ChatGPT's Data Analyst plugin, a baseline notebook generator without retrieval, and a standard text-based RAG baseline.
- Superior Quality: NotebookRAG scored significantly higher across almost all evaluation dimensions, including Confidence, Helpfulness, Task Alignment, Visualization quality, and Analytical Insight.
- High Factual Accuracy: Objective checks revealed a remarkably low rate of factual inconsistencies—only 8 out of 319 generated insights contained errors—validating the effectiveness of the statistical refinement loop.
- Better Visualizations: Analysts praised NotebookRAG for generating diverse, human-like, and well-annotated visualizations (e.g., nested donut charts and faceted scatterplots) instead of generic plots.
Limitations and Future Work
- Over-reliance on Elaborate Designs: Because the system learns from highly upvoted Kaggle notebooks, it occasionally copies overly complex chart designs that can cause cognitive overload. Future work will incorporate user preferences for visualization complexity.
- Execution Overhead: The multi-step retrieval, sandboxed execution, and debugging loops take around 10 minutes to generate a complete notebook. While acceptable for an offline assistant, optimizing this efficiency remains a goal.
- Potential Confirmation Bias: The verification loop checks the VLM's initial hypothesis rather than actively trying to disprove it. The authors plan to explore introducing explicit falsification-oriented statistical tests.
Summary updated