How kalikousik-14/simple-rag-pipeline works
Project type and purpose
• This is a Python‐based Retrieval-Augmented Generation (RAG) pipeline exposed as a Flask web API.
• Purpose: accept user-uploaded documents (PDF/TXT), chunk and embed them into a FAISS vector store, then answer user queries using either a local LLM or the OpenAI API.
File structure
Top-level files and directories:
• app.py – Flask application defining three endpoints
• ingest.py – Document ingestion and chunking logic
• embed.py – Embedding logic (sentence-transformers)
• index/ – Serialized vector store (faiss.index) and chunk metadata (chunks.pkl)
• model_loader.py – Loads local quantized LLM (Mistral)
• query_local.py – Query pipeline invoking the local LLM
• query_openai.py – Query pipeline invoking OpenAI’s GPT-3.5-turbo
• data/ – Storage for raw uploaded files (e.g., data/resume.pdf)
• .env, requirements.txt, README.md
Key architecture points from the README
• Upload API (/upload) performs parsing (PyPDF2/fopen), chunking (~300–500 tokens), embedding, FAISS indexing.
• Query APIs (/ask_local, /ask_openai) perform:
a. Vector similarity search against FAISS
b. Prompt assembly with relevant chunks
c. LLM invocation (local vs. OpenAI) → answer
Main components and their interactions
a. Clients
• Users or API clients (curl, Postman, frontend)
• Send POST /upload, /ask_local, /ask_openai
b. Flask API layer (app.py)
• Routes requests to the ingestion or query submodules
c. Ingestion pipeline
• ingest.py → parse → chunk
• embed.py → sentence-transformers embedding
• FAISS vector store in index/
d. Retrieval pipeline
• FAISS similarity search
• Returns top-k chunk embeddings + text
e. LLM inference
• model_loader.py loads local Mistral with transformers
• query_local.py builds prompt & runs local LLM
• query_openai.py builds prompt & calls OpenAI API
f. Persistence
• data/ for original documents
• index/ for vector index and chunk metadata
g. External services
• OpenAI API (gpt-3.5-turbo)
• (Optionally) any hosted local LLM dependencies
Architectural patterns
• Modular pipeline: ingestion, vector store, retrieval, inference
• Separation of concerns: parsing/chunking vs. embedding vs. indexing vs. querying
• Simple service façade (Flask) exposing HTTP endpoints