RAG Superstore Sales Analyst is a Python-based Retrieval-Augmented Generation system designed to answer business questions about the Sample Superstore sales dataset.
The system converts structured sales data into natural-language business documents, stores them in a vector database, retrieves the most relevant context for a user question, and uses a local LLM to generate clear analytical answers.
This project demonstrates how RAG can be applied to business intelligence and data analysis tasks, allowing users to ask questions about sales, profit, regions, product categories, discounts, seasonality, and trends in natural language.
The main goal of this project is to build a local AI-powered sales analyst that can answer questions such as:
- What is the sales trend over the 4-year period?
- Which months show the highest sales?
- Which product category generates the most revenue?
- Which region has the best sales performance?
- Which cities are the top performers?
- What products are frequently sold at a discount?
- How does the West region compare to the East in terms of profit?
Instead of manually querying the dataset, the user can ask questions directly and receive interpreted answers supported by retrieved data context.
Retrieval-Augmented Generation, or RAG, combines information retrieval with text generation.
In this project, the system works as follows:
- The Superstore dataset is converted into text documents.
- Each document is embedded using a sentence-transformer model.
- The embeddings are stored in ChromaDB.
- When the user asks a question, the system retrieves the most relevant documents.
- The retrieved context is passed to a local LLM.
- The LLM generates a business-style answer based on the retrieved data.
The project uses the Sample Superstore dataset.
The dataset contains sales transaction records with information such as:
- Order date
- Ship date
- Customer name
- Segment
- Product name
- Category
- Sub-category
- Ship mode
- City
- State
- Region
- Sales
- Quantity
- Discount
- Profit
The dataset is stored in:
data/Sample_Superstore.csv
The raw CSV data is transformed into multiple types of text documents to make retrieval more effective.
The generated documents include:
- Transaction-level records
- Monthly sales summaries
- Category and sub-category summaries
- Region and state performance summaries
- Yearly sales trend summaries
- Seasonality summaries
- Product discount summaries
- City performance summaries
- Category yearly trend summaries
The processed text documents are saved as:
data/sales_documents.csv
Sample_Superstore.csv
|
v
prepare_data.py
|
v
sales_documents.csv
|
v
build_vector_db.py
|
v
ChromaDB Vector Store
|
v
rag_app.py
|
v
User Question β Retrieved Context β LLM Answer
RAG_Superstore/
β
βββ data/
β βββ Sample_Superstore.csv # Original Superstore dataset
β βββ sales_documents.csv # Generated text documents
β
βββ chroma_db/ # Persistent ChromaDB vector database
β
βββ src/
β βββ prepare_data.py # Converts CSV rows and summaries into text documents
β βββ build_vector_db.py # Creates embeddings and stores them in ChromaDB
β βββ rag_app.py # Main RAG application for question answering
β βββ test_queries.py # Runs predefined evaluation questions
β
βββ test_results_20260428_184354.json # Saved test output
βββ test_results_20260428_191402.json # Saved test output
βββ requierments.txt # Project dependencies
βββ README.md
Note: The dependency file is currently named
requierments.txt. A recommended improvement is to rename it torequirements.txt.
- Python
- Pandas
- NumPy
- ChromaDB
- Sentence Transformers
- LangChain
- LangChain Community
- LangChain Ollama
- Ollama
- Llama 3.2 3B
- tqdm
all-MiniLM-L6-v2
This model is used to convert the generated sales documents and user questions into vector embeddings.
llama3.2:3b
The project uses Ollama to run the local language model.
git clone https://github.com/MonirCSauc/RAG_Superstore.git
cd RAG_Superstorepython -m venv venvActivate it:
venv\Scripts\activatesource venv/bin/activateThe repo currently contains a file named requierments.txt.
pip install -r requierments.txtIf you rename it to the standard spelling, use:
pip install -r requirements.txtMake sure Ollama is installed on your machine.
Then pull the required model:
ollama pull llama3.2:3bConvert the structured Superstore CSV into natural-language documents:
python src/prepare_data.pyThis creates:
data/sales_documents.csv
Generate embeddings and store the document chunks in ChromaDB:
python src/build_vector_db.pyThis creates or updates the persistent vector database in:
chroma_db/
Start the interactive question-answering system:
python src/rag_app.pyYou can then ask questions such as:
Which region has the best sales performance?
Compare Technology vs Furniture sales trends.
Which cities are the top performers?
To stop the app, type:
exit
To clear conversation history, type:
reset
The project includes a testing script with predefined business questions.
Run:
python src/test_queries.pyThe script asks several questions, generates answers, and saves the results in a timestamped JSON file.
Example tested questions include:
- What is the sales trend over the 4-year period?
- Which months show the highest sales?
- Which product category generates the most revenue?
- What sub-categories have the highest profit margins?
- Which products are frequently sold at a discount?
- Which region has the best sales performance?
- Compare sales performance across different states.
- Which cities are the top performers?
- Compare Technology vs Furniture sales trends.
- How does the West region compare to the East in terms of profit?
The system includes basic query routing and filtering.
It can detect keywords related to:
- Years from 2014 to 2017
- Regions such as West, East, Central, and South
- Categories such as Furniture, Technology, and Office Supplies
- Document types such as city summaries, state summaries, monthly summaries, yearly trends, discount summaries, and category summaries
This improves retrieval by selecting more relevant documents from the vector database before generating the final answer.
What is the sales trend over the 4-year period?
Which months show the highest sales? Is there seasonality?
Which product category generates the most revenue?
What sub-categories have the highest profit margins?
Which products are frequently sold at a discount?
Which region has the best sales performance?
Compare sales performance across different states.
Which cities are the top performers?
Compare Technology vs Furniture sales trends.
How does the West region compare to the East in terms of profit?
- Converts structured CSV data into natural-language documents
- Generates transaction-level and summary-level documents
- Uses ChromaDB for persistent vector storage
- Uses sentence-transformer embeddings for semantic search
- Uses Ollama with Llama 3.2 3B for local response generation
- Supports interactive question answering
- Maintains short conversation history
- Includes query filtering for years, categories, regions, and document types
- Includes a test script for evaluating multiple business questions
- Runs locally using Ollama
- Does not require a paid API key
- Combines structured data analysis with natural-language querying
- Uses multiple document types to improve retrieval quality
- Demonstrates a practical business intelligence use case for RAG
- Stores the vector database persistently using ChromaDB
- Some answers may depend heavily on retrieval quality.
- The system may occasionally retrieve incomplete context for broad comparison questions.
- The LLM may need stronger prompting or post-processing for precise numerical analysis.
- The current system does not directly run SQL or Pandas calculations at query time.
- The dependency file name is misspelled as
requierments.txt. - The project currently runs through the command line and does not include a web interface.
- Ahmed M. Monir