Shoply is an AI-powered customer support assistant for an e-commerce store. It uses Retrieval-Augmented Generation (RAG) to answer customer questions based on the store's actual policy documents.
Instead of relying only on the language model's general knowledge, Shoply retrieves relevant information from the store's policy documents and provides that information to the AI model to generate the final answer.
๐ Live Demo: https://shoply-ly6s.onrender.com/
๐ GitHub Repository: https://github.com/dilliram-code/shoply
Customer support systems often need to answer questions such as:
- What is the return policy?
- How long does shipping take?
- Can I get a refund?
- What is covered by the warranty?
- How can I return a product?
- How long do I have to request a refund?
Shoply provides an AI chatbot that can answer these questions using information stored in the company's policy documents.
The project demonstrates the basic architecture of a Retrieval-Augmented Generation (RAG) application using:
- PDF documents as the knowledge source
- OpenAI embeddings
- Pinecone vector database
- OpenAI language model
- FastAPI backend
- HTML/CSS/JavaScript frontend
The system follows this general pipeline:
โโโโโโโโโโโโโโโโโโโโโโโ
โ Customer Question โ
โโโโโโโโโโโโฌโโโโโโโโโโโ
โ
โผ
โโโโโโโโโโโโโโโโโโโโโโโ
โ Generate Embedding โ
โ OpenAI Embedding โ
โโโโโโโโโโโโฌโโโโโโโโโโโ
โ
โผ
โโโโโโโโโโโโโโโโโโโโโโโ
โ Search Pinecone โ
โ Vector Database โ
โโโโโโโโโโโโฌโโโโโโโโโโโ
โ
โผ
โโโโโโโโโโโโโโโโโโโโโโโ
โ Relevant Policy โ
โ Chunks โ
โโโโโโโโโโโโฌโโโโโโโโโโโ
โ
โผ
โโโโโโโโโโโโโโโโโโโโโโโ
โ OpenAI LLM โ
โ Context + Question โ
โโโโโโโโโโโโฌโโโโโโโโโโโ
โ
โผ
โโโโโโโโโโโโโโโโโโโโโโโ
โ Final Answer โ
โโโโโโโโโโโโโโโโโโโโโโโ
Suppose a customer asks:
"Can I return a product after 20 days?"
Shoply does not simply ask the LLM to answer from its general knowledge.
Instead:
- The question is converted into an embedding.
- Pinecone searches for semantically similar policy information.
- Relevant sections from the return-policy document are retrieved.
- The retrieved information is provided to the LLM as context.
- The LLM generates the final response using the retrieved company information.
This helps keep the answer grounded in the store's actual policies.
The current knowledge base contains policy documents related to the store:
knowledge/
โ
โโโ return-policy.pdf
โโโ shipping-policy.pdf
โโโ refund-policy.pdf
โโโ warranty-policy.pdf
These documents are converted into smaller text chunks before being embedded and stored in Pinecone.
shoply/
โ
โโโ knowledge/
โ โโโ return-policy.pdf
โ โโโ shipping-policy.pdf
โ โโโ refund-policy.pdf
โ โโโ warranty-policy.pdf
โ
โโโ static/
โ โโโ index.html
โ
โโโ main.py
โโโ server.py
โโโ requirements.txt
โโโ .gitignore
โโโ README.md
Contains the core RAG logic:
- Loading PDF documents
- Splitting documents into chunks
- Creating embeddings
- Uploading vectors to Pinecone
- Performing similarity search
- Sending retrieved context to the LLM
- Generating the final answer
Contains the FastAPI application.
It provides API endpoints for:
- Health checking
- Chat requests
- Knowledge-base ingestion
- Serving the frontend
Contains the PDF documents used as the knowledge base.
Contains the frontend interface for interacting with the chatbot.
| Technology | Purpose |
|---|---|
| Python | Main programming language |
| FastAPI | Backend API |
| OpenAI | Embeddings and LLM |
| Pinecone | Vector database |
| PyPDF | Reading PDF documents |
| tiktoken | Token-based text chunking |
| HTML | Frontend structure |
| CSS | Frontend styling |
| JavaScript | Frontend interaction |
| Render | Deployment |
The project requires API keys for OpenAI and Pinecone.
Create a .env file locally:
OPENAI_API_KEY=your_openai_api_key
PINECONE_API_KEY=your_pinecone_api_key
PINECONE_INDEX_NAME=shop-support
PINECONE_NAMESPACE=policiesYour OpenAI API key used for:
- Generating embeddings
- Generating chatbot responses
Your Pinecone API key used to access the vector database.
The name of the Pinecone index.
For this project:
PINECONE_INDEX_NAME=shop-supportThis is not an API key.
The namespace used to store the policy vectors:
PINECONE_NAMESPACE=policiesgit clone https://github.com/dilliram-code/shoply.gitMove into the project:
cd shoplypython -m venv .venvActivate it on macOS/Linux:
source .venv/bin/activateOn Windows:
.venv\Scripts\activatepip install -r requirements.txtCreate a .env file:
OPENAI_API_KEY=your_openai_api_key
PINECONE_API_KEY=your_pinecone_api_key
PINECONE_INDEX_NAME=shop-support
PINECONE_NAMESPACE=policiesDo not commit .env to GitHub.
Run:
python -m uvicorn server:app --reloadThe application should be available at:
http://127.0.0.1:8000
Before asking questions, the PDF documents need to be processed and uploaded to Pinecone.
The project provides an ingestion endpoint:
POST /api/ingestFor example:
curl -X POST http://127.0.0.1:8000/api/ingestThis will:
- Read the PDF files.
- Extract their text.
- Split the text into chunks.
- Generate embeddings.
- Store the vectors in Pinecone.
The ingestion process should be run when the knowledge documents are added or changed.
The chatbot provides the following endpoint:
POST /api/chatExample request:
{
"question": "What is your return policy?"
}Example response:
{
"answer": "..."
}The application also provides a health-check endpoint:
GET /api/healthExample response:
{
"status": "ok"
}The application reads the policy PDFs from the knowledge/ directory.
PDF
โ
Text Extraction
Large documents are divided into smaller token-based chunks.
Large PDF
โ
Extracted Text
โ
Text Chunks
โ
Chunk 1
Chunk 2
Chunk 3
...
This makes semantic retrieval more effective.
Each chunk is converted into a numerical vector using:
text-embedding-3-small
The vectors represent the semantic meaning of the text.
Policy Text
โ
OpenAI Embedding Model
โ
Vector Representation
The embeddings are stored in Pinecone.
Document Chunk
โ
Embedding
โ
Pinecone
Each stored vector also contains metadata such as the original document and chunk information.
When a customer asks a question, the question is also converted into an embedding.
Customer Question
โ
Embedding Model
โ
Query Vector
The query vector is sent to Pinecone.
Pinecone searches for the most semantically similar policy chunks.
Query Vector
โ
Pinecone
โ
Top Relevant Chunks
The retrieved chunks are combined into a context that is sent to the language model.
Retrieved Chunk 1
Retrieved Chunk 2
Retrieved Chunk 3
Retrieved Chunk 4
โ
Context
The LLM receives:
System Instructions
+
Retrieved Company Information
+
Customer Question
and generates the final response.
The assistant is instructed to use the company information rather than inventing policy information.
One of the important concepts demonstrated by this project is grounding an LLM using external knowledge.
The assistant is instructed to answer using the retrieved company information.
If the required information is not available, it can respond:
I don't have that information in the company documents.
This is preferable to allowing the model to invent a company policy.
However, RAG does not completely eliminate hallucinations. Production systems should also consider:
- Better retrieval strategies
- Reranking
- Metadata filtering
- Citation/source display
- Evaluation datasets
- Retrieval quality monitoring
- Guardrails
- Human escalation
The application is deployed using Render.
๐ https://shoply-ly6s.onrender.com/
The backend runs using:
python -m uvicorn server:app --host 0.0.0.0 --port $PORTEnvironment variables are configured through the Render dashboard rather than committing API keys to the repository.
You can try questions such as:
What is the return policy?
How many days do I have to return a product?
How long does shipping take?
Can I get a refund?
What products are covered by the warranty?
How can I request a return?
What happens if my product arrives damaged?
You can also ask questions that are unrelated to the available documents and observe how the system handles information that is not present in its knowledge base.
This project was built to understand the fundamental concepts behind modern RAG applications.
Through this project, the following concepts are demonstrated:
- Large Language Models
- Embeddings
- Vector databases
- Semantic search
- Document chunking
- PDF processing
- Retrieval-Augmented Generation
- Prompt grounding
- FastAPI
- REST APIs
- Environment variables
- Backend/frontend integration
- Cloud deployment
The current project demonstrates a basic RAG architecture. It can be extended into a more production-oriented customer support system.
Possible improvements include:
Store previous user and assistant messages so that the chatbot can understand follow-up questions.
Show the customer which policy document was used to generate the answer.
Example:
Source: return-policy.pdf
Introduce:
- Hybrid search
- Sparse + dense retrieval
- Reranking
- Metadata filtering
Add an admin interface for uploading and updating policy documents without modifying the source code.
Connect the assistant with a customer account system.
This could allow questions such as:
Where is my order?
Can I cancel my order?
What is the status of my refund?
Connect the chatbot to an actual e-commerce database containing:
- Customers
- Orders
- Products
- Payments
- Returns
- Refunds
The RAG chatbot could eventually become an AI agent capable of deciding when to:
Search policies
โ
Check order database
โ
Check refund status
โ
Create support ticket
โ
Respond to customer
This would move the system beyond a simple RAG chatbot toward an agentic customer-support system.
This project is primarily a learning and demonstration project.
The current implementation is not intended to be used as a complete production e-commerce customer-support platform without additional security, monitoring, authentication, evaluation, error handling, and infrastructure improvements.
API keys and other secrets should always be stored securely using environment variables or a dedicated secret-management system.
Dilli Ram Chaudhary
B.Sc. Physics | AI/ML Student | Python & AI Enthusiast
GitHub: https://github.com/dilliram-code
If you find this project useful for learning RAG, feel free to explore the repository and experiment with the implementation.
Live Demo: https://shoply-ly6s.onrender.com/
Source Code: https://github.com/dilliram-code/shoply