How spanionsharma/rag works
Project Type and Purpose
• This is a Python-based, Retrieval-Augmented Generation (RAG) chatbot tool.
• Purpose: Ingest user-provided documents into a vector store (Pinecone), retrieve relevant context at query time, and dispatch prompts to an LLM (ChatOpenAI or Gemini) to generate answers.
a. User Interface (CLI or script runner)
b. Ingestion Module (ingestion.py)
c. Retrieval Module (retrieval.py)
d. Chat Orchestration Module (chatbot_rag.py)
e. Local Documents Folder (“documents/”)
f. Vector Database Service (Pinecone)
g. LLM API Service (ChatOpenAI or Gemini)
h. Configuration Store (API keys, environment variables, requirements.txt)
Data Flows & Interactions
• Ingestion Flow:
• User places files in documents/ → ingestion.py reads docs → splits and embeds text → sends embeddings to Pinecone
• Query Flow:
• User issues query via chatbot_rag.py → chatbot_rag invokes retrieval.py → retrieval.py queries Pinecone → Pinecone returns top-k relevant chunks → retrieval.py returns context → chatbot_rag.py formats prompt and calls LLM API → LLM returns generated response → chatbot_rag.py prints to user
• Config/Environment:
Architectural Patterns & Design Principles
• Pipeline Pattern: clear separation of ingest → store → retrieve → generate
• Single Responsibility: each script handles one phase (ingestion, retrieval, orchestration)
Essential Elements
• Clear labels for all modules and services
[ User (CLI) ]
|
| “/start chat”
↓
[ Chat Orchestration Module ]
| ↘── Config (API_KEYS)
| “get_relevant_context” ───┐
↓ ↓
[ Retrieval Module ] ──vector_search──▶ [ Pinecone Vector DB ]
|
“return top-k chunks”
↓
Chat Orchestration Module
|
“format prompt + context”
↓
[ LLM API Service ]
|
“generated answer”
↓
Chat Orchestration Module → prints to User
With a parallel branch for:
[ Documents Folder ] ──read & embed──▶ [ Ingestion Module ] ──upload──▶ [ Pinecone Vector DB ]