How kalyanm45/docgenius-revolutionizing-pdfs-with-ai works
1. Project shape
- This repository is a small Python, single-user PDF question-answering app.
- The runtime entrypoint is app.py, which is launched with Streamlit.
- Most of the document-QA logic appears to live in DocGenius/PDFChat.py, with app.py acting as the UI and orchestration layer.
2. User interface boundary
- The visible application is the Streamlit interface.
- Its job is to accept a PDF upload, collect a natural-language question, and display the answer.
- The UI does not appear to own the document intelligence itself; it likely delegates that to the PDF chat module.
3. Document ingestion subsystem
- PDF content is read from the uploaded file using PyPDF2.
- The README describes a flow where the PDF text is extracted and then split into smaller chunks.
- This ingestion stage is the first boundary between raw user input and searchable text data.
4. Text preparation and chunking
- The application breaks the PDF text into chunks before sending anything to the model.
- tiktoken is listed, which strongly suggests token-aware chunk sizing to stay within model limits.
- This is an important architecture step because it shapes both retrieval quality and LLM prompt size.
5. Embedding and vector indexing
- The repo uses OpenAI embeddings to convert text chunks into vector representations.
- faiss-cpu is used as the local vector index for semantic search over those embeddings.
- This creates a clear retrieval layer: raw PDF text is transformed into searchable vectors, separate from the UI and the final answer generation.
6. Question answering flow
- When a user asks a question, the app embeds that question and searches the vector index for the most semantically similar chunks.
- Only those retrieved chunks are forwarded to the LLM as context.
- The README explicitly says the model is constrained to answer from the document, so retrieval is a gating mechanism, not just a convenience.
7. LLM orchestration
- The LLM generates the final answer from the retrieved PDF chunks plus the user question.
- The architecture is retrieval-augmented generation rather than direct free-form chat.
- This means the system is dependent on both the vector search quality and the prompt/context assembly in the PDF chat logic.
8. Main internal module boundary
- DocGenius/PDFChat.py is likely the core service module that encapsulates PDF loading, chunking, embedding, retrieval, and response generation.
- app.py likely imports and calls into that module rather than implementing the full pipeline inline.
- That separation matters for the diagram: UI at the top, document-processing engine below it.
9. Configuration and secrets
- OpenAI access is configured through a .env file via python-dotenv.
- The API key is an external dependency boundary, not hardcoded into the app.
- This is the main runtime configuration hook and should be shown outside the core code path.
10. Runtime dependencies that affect architecture
- streamlit defines the interaction model and makes the app a local interactive tool rather than a backend service.
- langchain likely provides helper abstractions for chaining, prompting, or document handling, even if the core pattern is still RAG.
- faiss-cpu means the vector search runs locally in-process or on the local machine, not via a managed vector database.
11. Data flow summary
- The end-to-end flow is: user uploads PDF → text extraction → chunking → embeddings → FAISS index → question embedding → similarity search → selected chunks + question → LLM → answer displayed in Streamlit.
- The data path is one-way from document ingestion into retrieval, then into generation.
- There is no sign of persistent knowledge storage or long-term conversation memory in the repository structure.
12. Artifacts and non-runtime assets
- The Artifacts/ directory appears to store screenshots and image resources used for documentation or proof-of-concept presentation.
- These assets are not part of the core execution path.
- They are useful for understanding the intended UI/UX but should be excluded from the runtime architecture diagram.
13. Overall architecture pattern
- This is a lightweight retrieval-augmented PDF chat application with three main layers: Streamlit UI, document processing/retrieval engine, and OpenAI-backed generation.
- The system is local-first and single-process, with external dependence only on OpenAI services for embeddings and answer generation.
- The key architectural boundary is between user-facing interaction and the internal semantic search/LLM pipeline.
Main entry points: PDFChat.py PDF chat · app.py Streamlit app
Components 19
UI
Streamlit entrypoint and user interaction layer
- Streamlit app · Launches the interactive PDF Q&A UI and orchestrates user flow
app.py - PDF upload · Uploaded document enters the application through the UI
- User question · Natural-language query provided by the user
- Rendered answer · Final response shown back in the Streamlit interface
PDF engine
Document ingestion, retrieval, and answer generation
- PDF chat · Central document-QA pipeline for loading, indexing, retrieving, and answering
DocGenius/PDFChat.py - Text extraction · Reads PDF content from the uploaded file
- Chunking · Splits extracted text into token-aware chunks
- Doc embeddings · Converts text chunks into vector representations
- FAISS index · Local semantic index over embedded chunks
- Query embedding · Embeds the user question for retrieval
- Similarity search · Finds the most relevant document chunks for the question
- Context assembly · Combines retrieved chunks with the question for the model
- LLM answer · Produces the final answer using document-grounded context
Dependencies
External libraries and runtime services
- Streamlit · Interactive local web UI runtime
- PyPDF2 · Library used to read and extract text from PDFs
- tiktoken · Token-aware sizing for chunking and prompt limits
- LangChain · Helper abstractions for chaining and document orchestration
- OpenAI API · External embeddings and answer generation backend
- .env config · Loads API credentials and local configuration
Connections 24
- Streamlit app → PDF upload: accepts · The UI receives the uploaded PDF from the user
- Streamlit app → User question: collects · The UI captures the user's question
- Streamlit app → PDF chat: delegates · The Streamlit layer calls into the PDF chat engine
- PDF upload → Text extraction: ingests · Uploaded PDF becomes extracted text
- Text extraction → PyPDF2: uses · PDF parsing is handled by PyPDF2
- Text extraction → Chunking: feeds · Extracted text is prepared for chunking
- Chunking → tiktoken: sizes · Chunking is guided by token limits
- Chunking → Doc embeddings: prepares · Text chunks are converted into vectors
- Doc embeddings → OpenAI API: embeds · OpenAI embeddings create document vectors
- Doc embeddings → FAISS index: stores · Chunk vectors are added to the local index
- FAISS index → Similarity search: queries · Similarity search runs against the FAISS index
- User question → Query embedding: embeds · The user question is vectorized for retrieval
- Query embedding → OpenAI API: embeds · OpenAI embeddings create the query vector
- Query embedding → Similarity search: searches · Query vector drives semantic retrieval
- Similarity search → Context assembly: selects · Relevant chunks are assembled into model context
- Context assembly → LLM answer: feeds · Context plus question are passed to the LLM
- LLM answer → OpenAI API: calls · OpenAI produces the grounded final answer
- LLM answer → Rendered answer: returns · Answer is sent back to the UI for display
- PDF chat → Text extraction: orchestrates · Core module coordinates document ingestion
- PDF chat → Similarity search: orchestrates · Core module coordinates retrieval
- PDF chat → LLM answer: orchestrates · Core module coordinates response generation
- Streamlit app → Streamlit: runs on · The application is launched under Streamlit
- PDF chat → LangChain: leverages · Document and chain helpers support the RAG flow
- .env config → Streamlit app: configures · Environment variables supply runtime credentials