How amgad-abdelkhaleq/pdf-rag works
Main Components
a. Frontend – a Streamlit application (located under src/ui/streamlit_app.py) that provides the user interface.
b. Backend – a FastAPI-based API handling routes for chat and document management (see src/api/routes and main.py).
c. Document Processing Pipeline – components responsible for PDF upload, text extraction, chunking, and indexing. In the README, these are represented by nodes like “PDF Processor”, “Chunking Service” and “Indexing Service.”
d. Embedding and Vector Storage – services for generating embeddings (using all-MiniLM-L6-v2) and storing them in a vector store (Qdrant), supported by the src/repositories/vector_store.py.
e. Query Processing & LLM Integration – processes that receive a user query, generate an embedding, retrieve context from the vector store, and then use a LLM (TinyLlama) for generating responses. This involves services like the rag_service and chat_history_service.
f. Supporting Modules – configuration (src/core/config.py), dependency management (src/core/dependencies.py), and data models (src/models).
Relationships and Interactions
a. The Frontend (Streamlit UI) sends user interactions to the Backend (FastAPI API).
b. The API routes handle document uploads and chat interactions, interacting with the services.
c. For documents: the API triggers PDF processing, which passes through text extraction and chunking, then to the embedding service before storing data in the Vector Store.
d. For queries: the API receives the user query, processes it through the embedding service to match against stored embeddings, retrieves context, and forwards the request to the LLM service with RAG logic.
Architectural Patterns and Design Principles
a. Separation of Concerns: The project clearly separates UI, API routes, core logic, services, and data models.
b. Modularity: Services such as document service, embedding service, chat history service, and RAG service are split into different modules (each in src/services).
c. Pipeline Processing: The document processing (from PDF upload to vector storage) and query processing (user query to LLM response) represent sequential workflows.
d. API-Driven Architecture: FastAPI orchestrates interactions between different internal components and external dependencies (like the vector store or LLM).
Final Assembly and Detailing
• Detail out the API endpoints supported, noting that one handles document uploads while another handles chat interactions.
• Optionally, annotate with technologies (e.g., “Built with FastAPI”, “Powered by LangChain”, “Using Qdrant for vector storage”) to provide clarity on the tech stack used.