How faridghr/simple-rag-chatbot works
Project Type and Purpose
• This is a domain-specific full-stack Python application: a Retrieval-Augmented Generation (RAG) chat-bot.
• Frontend: Streamlit UI.
• Backend: LangChain RAG pipeline in Python.
• Data store: Pinecone vector database for embeddings.
• External service: OpenAI LLM for response generation.
• Purpose: Accept user chat input, retrieve relevant domain documents, and generate informed, context-aware responses.
File-Structure Analysis
• Top-level:
• .env (API keys)
• requirements.txt (dependencies)
• src/ (application code)
• report/, video/ (deliverables)
• src/:
• streamlitMain.py (entry point for UI)
• RAG_ChatBot.py (encapsulates RAG pipeline: ingestion, embedding, retrieval, generation)
• materials/ (domain documents loaded into vector store)
Key Architectural Components
a. Streamlit Frontend
• Serves HTML widgets, text-input, display of bot responses.
• Communicates over in-process API to RAG pipeline code.
b. RAG Pipeline (LangChain)
• Document Loader: reads materials from src/materials.
• Embedder: converts docs/text and user query to vector embeddings.
• Vector Store Interface: upserts/retrieves embeddings in Pinecone.
• RAG Chain: crafts prompt combining retrieved contexts and forwards to LLM.
c. Vector Database (Pinecone)
• Stores and indexes embeddings.
• Supports efficient similarity search on user queries.
d. LLM Service (OpenAI)
• Receives concatenated prompt + context.
• Returns generated answer.
Data Flow & Interactions
1. User types query → Streamlit UI
2. UI calls RAG_ChatBot.query(query)
3. RAG_ChatBot:
a. Query embedding → Pinecone.retrieve(top_k docs)
b. Build prompt with retrieved docs + query
c. Send prompt → OpenAI API → Receive response
4. Streamlit displays response
Architectural Patterns & Design Principles
• RAG pattern: explicit separation of retrieval (vector DB) and generation (LLM).
• Single-page app: UI & backend code packaged together via Streamlit.
• Configuration via .env for secrets (OpenAI & Pinecone keys).
• Modular code: RAG_ChatBot.py encapsulates all backend logic.