How vivekdeshmukhrepos/document-intelligence works
This is a single-service Flask web application that implements a RAG (Retrieval-Augmented Generation) document Q&A system:
• Users upload documents (PDF/TXT) via a browser UI (or /upload).
• The server extracts text, chunks it, embeds chunks using OpenAI embeddings, and stores vectors in ChromaDB (persistent).
• The original file is stored in AWS S3.
• Users ask questions via UI (or /query); the server embeds the query, performs top-k similarity search in ChromaDB, builds a prompt, and calls GPT-4 to answer.
Runtime entrypoint / composition root
• app/main.py: Flask app, routes, orchestration of upload + query flows
Configuration
• app/config.py: env-driven settings (model name, chunk sizes, k, vector db path, keys)
“Models” (in this repo, means “data layer”)
• app/models/vector_store.py: VectorStore wrapper around ChromaDB + OpenAI Embeddings
“Services” (integration / business logic)
• app/services/llm_service.py: LLMService that:
• calls VectorStore similarity search
• builds context/prompt
• calls GPT-4
• tracks conversation memory/history (in-process)
• app/services/storage_service.py: S3Storage wrapper (boto3) for upload/download
Data
• data/RAG-White-Paper.pdf: sample/local document (not required at runtime, but indicates expected inputs)
This strongly implies a modular monolith: one Flask server process, structured as routes → services → integrations.
What the README adds (must be reflected explicitly)
• Ingestion chunking: 1000 chars with 200 overlap
• Embedding model: text-embedding-3-small, 1536 dims
• Retrieval: cosine similarity, k=4
• LLM: GPT-4-0613, temperature 0.7
• Persistence:
• ChromaDB persistent storage path (VECTOR_DB_PATH)
• S3 bucket for original docs
• Endpoints:
• GET / serves UI
• POST /upload ingestion pipeline
• POST /query RAG pipeline
Flask → Browser: “answer JSON”
Critically: show retrieval before generation, and show that chat history is internal state (memory) that affects prompts.
Small callouts/annotations:
• RAG Pattern: Retrieval (ChromaDB) → Augment (context in prompt) → Generation (GPT-4)
• Modular Monolith: one Flask service, internal modules
• Externalized config: .env → config.py
• Persistence split:
• Vector persistence: ChromaDB on disk
• Original document storage: S3
• Flask 2.3.3
• LangChain components (text splitter, OpenAI wrappers)
• ChromaDB (vector DB)
• OpenAI Embeddings model (text-embedding-3-small, 1536 dims)
• OpenAI GPT-4-0613 (temp 0.7)
• boto3 / AWS S3
• pypdf + unstructured
Browser ↔ Flask App ↔ (OpenAI API, S3, ChromaDB on disk).
This is the executive view.
Includes extraction → chunk → embed → store → S3 upload.
Includes query embed → similarity search → prompt build (history+context) → GPT-4.
• “Flask Server / Routes” → app/main.py
• “Config” → app/config.py
• “VectorStore (ChromaDB + embeddings)” → app/models/vector_store.py
• “LLMService (GPT-4 + history)” → app/services/llm_service.py
• “S3Storage” → app/services/storage_service.py
• “UI” → app/templates/index.html, app/static/style.css