A project that builds an Import/Export Business chatbot using a Retrieval-Augmented Generation (RAG) pipeline. The system combines procedural guidance from a trade business knowledge base with Indian export data, and returns answers with source citations. Users can also upload their own business data to receive personalised, data-driven suggestions for growing their export business.
Entrepreneurs and businesses involved in import and export need both procedural guidance and reliable trade statistics. This project creates a chatbot that answers questions from a curated knowledge base: a standard import/export business reference and Indian export data from TRADESTAT-style sources. The system uses RAG so answers are grounded in sources and can be cited, rather than relying only on the language modelβs training.
International trade connects countries, firms, and consumers. Imports bring goods and inputs that may be cheaper, higher quality, or unavailable domestically. Exports open new markets, earn foreign exchange, and support jobs and growth. For India, trade activity is central to economic development and global integration. For entrepreneurs, importβexport offers the chance to scale beyond local markets but requires understanding regulations, logistics, finance, and demand.
RAG combines search with language generation. The user question is used to retrieve relevant passages from a stored collection of documents or data, then those passages are passed to a language model as context. The model generates an answer grounded in the retrieved context, which reduces hallucinations and allows source citations.
RAG helps by:
- answering "how-to" questions from trusted guides and manuals,
- answering "what are the numbers?" questions from official trade statistics,
- showing where the answer came from,
- staying aligned with your selected knowledge base.
- Provide a single conversational interface for procedural guidance and trade-data questions.
- Ground answers in designated documents and datasets.
- Use Indian export statistics so trade-data answers are authoritative.
- Allow users to upload their own business data (CSV, Excel, PDF) for personalised recommendations.
- Cross-reference user data with the knowledge base to identify growth opportunities and risks.
- Design the pipeline to support future data updates and new source types.
The chatbot uses a knowledge base composed of:
- a trade business reference book,
- Indian export data in a merged CSV,
- trade law and regulation knowledge.
The system operates in two modes:
- Standard mode β answers questions using the RAG knowledge base.
- Personalised mode β when a user uploads their business data, the system combines the uploaded data with RAG-retrieved knowledge to give tailored suggestions.
The system supports entrepreneur-style questions, trade-data queries, personalised business analysis, and general import/export questions.
This README is organised into: introduction, system flow, data preparation, ingestion, query pipeline, web application, implementation status, advantages, applications, future scope, and sample conversations.
The system is organised into four stages:
| Stage | Name | Mode | Description |
|---|---|---|---|
| 0 | Data Preparation | Offline / Admin | Acquire and prepare source documents and export data. |
| 1 | Data & Ingestion | Offline / Admin | Parse, chunk, embed, and store content in a vector database. |
| 2 | Query β Answer | Online | Retrieve relevant chunks and generate answers with citations. |
| 3 | Web Application | Online | Chat UI and backend API that invoke the RAG pipeline. |
End-to-end flow (standard mode):
User β Web UI β Backend API β RAG (Retrieve + LLM) β Answer + Citations β User
End-to-end flow (personalised mode with file upload):
User uploads file β Backend parses β Summary stored in session
User asks question β RAG retrieves trade KB chunks
β LLM gets: RAG context + user's business data
β Personalised answer with citations β User
Offline pipeline:
Data Preparation β Parse β Chunk β Enrich β Embed β Store (Vector DB)
Online pipeline:
User Question β Embed Query β Retrieve Top-k β Build Context β LLM β Answer + Sources
Collect, structure, and organise source materials before ingestion. This stage ensures the book and export data are in a consistent form.
| Step | Description |
|---|---|
| Source acquisition | Obtain the book text and Indian export data. |
| Schema / structure | Ensure export data has country_from, country_to, HSCode, Commodity, year value columns, and growth. |
| Data cleaning | Normalise text and validate numeric export values. |
| Organisation | Keep book text under data/book/, export CSV under data/export/, and law KB under data/. |
- Book reference content ready for chunking.
- Merged Indian export CSV ready for ingestion.
New export data or book sections can be added and re-ingested without retraining the model.
Convert raw sources into searchable chunks and store them with embeddings in a vector database.
| Step | Description |
|---|---|
| Parse | Extract text from book sources and load export CSV rows. |
| Chunk | Split book text into digestible passages; create data chunks for export rows or grouped country/commodity segments. |
| Enrich | Attach metadata for source type, chapter, country, HS code, and commodity. |
| Embed | Generate embeddings for each chunk using a shared model. |
| Store | Save chunks and embeddings in a vector database such as Pinecone. |
- A vector database comprised of book chunks and export data chunks.
- Metadata to distinguish book content from export data.
Additional export years, new countries, or future dispute data can be added to the same pipeline.
For each user query, retrieve relevant context from the knowledge base and generate an answer with citations.
| Step | Description |
|---|---|
| Query embedding | Convert the user question into an embedding. |
| Retrieval | Search the vector database for top-k relevant chunks. |
| Context building | Format retrieved chunks with source labels. |
| Generation | Send the user question plus retrieved context to the LLM. |
| Response | Return structured output with answer and sources. |
- Answer text grounded in the knowledge base.
- Source citations for verification.
Expose the RAG pipeline through a user-facing chat interface, including file upload for personalised analysis.
| Step | Description |
|---|---|
| User opens app | The chat UI loads in the browser. |
| User uploads file (optional) | User clicks π to upload business data (CSV, Excel, PDF, TXT). Backend parses and stores a summary. |
| User submits question | The frontend sends the message to the backend. |
| Backend processing | The backend runs retrieval and LLM generation. If a file was uploaded, the user's data is injected into the prompt alongside RAG context. |
| Frontend display | The answer and colour-coded source tags appear in the chat. |
| Follow-up | Multi-turn dialogue is supported; uploaded data persists for the session. |
| Remove file | User can click β on the file badge to return to standard mode. |
- Frontend:
templates/chat.htmlandstatic/style.css - Backend:
app.pywith RAG logic, file upload routes, and API endpoints - Retrieval engine: Pinecone vector store
- LLM: HuggingFace endpoint via
langchain-huggingface
Allow export business owners to upload their own business data so the chatbot can analyse it and provide personalised, data-backed recommendations by cross-referencing with the trade knowledge base.
| Format | Extension | Parsing method |
|---|---|---|
| CSV | .csv |
pandas.read_csv() β auto-detects columns, builds summary with stats |
| Excel | .xlsx, .xls |
pandas.read_excel() β same as CSV |
.pdf |
PyPDFLoader β extracts text from all pages |
|
| Plain text | .txt |
Direct text read |
- Upload: User clicks the π button and selects a file (max 5 MB).
- Parse: The backend (
src/helper.py β parse_uploaded_file()) reads the file and produces a structured text summary (~2000 chars max). - Store: The summary is kept in server memory for the session duration.
- Query: When the user asks a question, the backend builds a personalised prompt that includes:
- The user's business data summary (from the uploaded file)
- RAG-retrieved context (from book, export data, and trade laws in Pinecone)
- Answer: The LLM cross-references both sources to give specific, actionable recommendations.
- Clear: User can remove the file at any time to switch back to standard mode.
The personalised prompt instructs the LLM to:
- Analyse the user's current export products, markets, and revenue.
- Compare with Indian export trends from the knowledge base.
- Identify growth opportunities β new markets, high-growth commodities, untapped regions.
- Flag potential risks β declining markets, over-concentration.
- Give specific, data-backed recommendations with numbers.
- Cite both the user's data and the trade knowledge base.
| Endpoint | Method | Description |
|---|---|---|
/ |
GET | Serve the chat UI |
/get |
POST | Handle chat messages (standard or personalised mode) |
/upload |
POST | Upload and parse a business data file |
/clear-upload |
POST | Remove uploaded data and return to standard mode |
- Uploaded files are parsed and immediately deleted from disk.
- Only the text summary is kept in server memory for the session.
- No uploaded data is stored permanently.
| Stage | Main output |
|---|---|
| 0 | Prepared book and export data sources |
| 1 | Vector DB with embeddings |
| 2 | Retrieved answer with citations |
| 3 | User-facing chat app |
This system combines trusted documentation and official trade data into one conversational assistant.
- Book knowledge:
data/book/(book text or extracted content) - Indian export data:
data/export/merged_country_wise.csv - Trade laws KB:
data/import_export_laws_knowledge_base.txt
The merged Indian export dataset has also been published on Kaggle under a CC0 license. Anyone can download and reuse it from:
This makes the dataset available publicly for research and reuse.
The repository includes the chat application and the data sources needed for the RAG pipeline. The app loads embeddings, connects to Pinecone, and serves the chat UI.
The export dataset is prepared as a merged CSV with columns such as:
country_fromcountry_toS.No.HSCodeCommodity2023-20242024-2025%Growth
The data is normalised for missing values, dropped summary rows, and standardised for ingestion.
- finish ingestion of book and export data
- complete retrieval and LLM integration
- improve the web UI and deploy the app
- Grounded answers from curated sources
- Colour-coded source citations (π export data, π book, π trade laws) for transparency
- Official-style Indian export statistics
- One interface for both procedural guidance and trade data
- Personalised suggestions based on user-uploaded business data
- Cross-referencing of user data with national trade statistics for actionable insights
- Easy to extend with new datasets
- Privacy-conscious: uploaded files are parsed and not stored permanently
- Entrepreneur guidance on export/import business setup
- Trade market research with country and commodity figures
- Personalised business analysis β upload sales data to get market expansion recommendations
- Risk assessment β identify over-concentrated markets or declining product categories
- Growth opportunity identification β find high-growth commodities and untapped export destinations
- Educational support for trade and customs topics
- Future extension to dispute guidance and case-based support
- Parse and chunk book + export data.
- Embed chunks and store in Pinecone.
- Build the query pipeline with retrieval, prompt assembly, and LLM generation.
- Finalise the chat UI and deploy.
- Add dispute data and case references
- Add multilingual support
- Add voice and chatbot analytics
- Integrate with real trade portals or customs APIs
- Support multi-sheet Excel workbooks with sheet selection
- Add persistent file storage with user accounts
- Generate downloadable PDF reports from personalised analysis
- Auto-generate an initial business health analysis upon file upload
User: How do I start an export business?
Chatbot:
- Research product-market fit.
- Register your business and obtain IEC.
- Source quality suppliers and arrange logistics.
- Comply with customs, certificates, and export regulations.
- Find buyers and negotiate contracts.
π Sources:
- π Import/Export Business Book β Page 12
- π Trade Laws & Regulations KB β FTDR Act
- Domain expertise
User: What does India export to Australia?
Chatbot: India exports commodities such as cereals and processed food products to Australia. The system can cite export data by HS code and value for FY 2023β2024 and 2024β2025.
π Sources:
- π Indian Export Data β Australia (CEREALS, HS 10)
User: Uploads my_sales_data.csv containing their export products, revenue, and destinations.
Chatbot: π File "my_sales_data.csv" loaded successfully! I can now give you personalised suggestions based on your business data.
User: Which new markets should I target?
Chatbot: Based on your current exports of organic spices to the USA ($120K) and UAE ($95K), I recommend:
- United Kingdom β India's spice exports to the UK grew 18% in 2024β2025. Your product line aligns well.
- Germany β HS 0910 (spices) saw 12% growth to Germany; currently underserved by your portfolio.
- Diversification risk: 65% of your revenue comes from USA β consider spreading to 3β4 markets.
π Sources:
- π Uploaded Business Data β revenue breakdown by country
- π Indian Export Data β UK (SPICES, HS 0910)
- π Indian Export Data β Germany (SPICES, HS 0910)
- π Import/Export Business Book β Page 87
- Domain expertise
cd /Users/udaydhakar12/Documents/project_impexp
python3 -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt
python app.pyOpen http://localhost:8080.
Create .env with:
PINECONE_API_KEY=your_pinecone_api_key
HUGGINGFACEHUB_ACCESS_TOKEN=your_huggingface_api_tokenapp.pyβ Flask backend, RAG pipeline, file upload routes (/upload,/clear-upload)src/prompt.pyβ system prompt (standard mode) and upload prompt (personalised mode)src/helper.pyβ embedding setup, file parsing (parse_uploaded_file)templates/chat.htmlβ chat interface with π upload button and file badgestatic/style.cssβ UI styling with colour-coded source tagsstore_index.pyβ offline ingestion pipeline for Pineconedata/export/merged_country_wise.csvβ Indian export datasetdata/book/β import/export business reference book (PDF)data/import_export_laws_knowledge_base.txtβ trade laws and regulatory knowledgerequirements.txtβ Python dependencies (includesopenpyxlfor Excel upload support)docs/β screenshot assets
This README is inspired by the project report structure and shows how the system flow maps to the current repository. The screenshots are included to visualise the app experience and results.




