How sergiocipher/pdf_peter works
1. High-level shape
- This is a two-tier RAG application: a FastAPI backend does document ingestion and question answering, while a React/Vite frontend provides the upload-and-chat UI.
- The core architectural boundary is between document processing + retrieval in Python and user interaction in the browser.
2. Backend entrypoint and API surface
- app/main.py is the FastAPI application assembly point.
- The HTTP surface is split into two route modules:
- app/api/upload.py for PDF ingestion and indexing
- app/api/chat.py for user questions and grounded answers
- run.py is the local startup wrapper.
3. Ingestion pipeline
- The upload path is a staged pipeline implemented in services:
- app/services/pdf_loader.py extracts text from PDFs
- app/services/chunking.py splits text into overlapping chunks
- app/services/embeddings.py turns chunks into vectors
- app/services/vector_store.py persists vectors and metadata in Qdrant
- This is the write side of the system: PDF in, searchable document index out.
4. Query / RAG pipeline
- The chat path is the read side:
- app/services/retriever.py embeds the user query and fetches relevant chunks from Qdrant
- app/services/llm.py sends retrieved context plus the question to the model
- The response is grounded in retrieved document context, with citations/page references coming from stored chunk metadata.
5. Model and external service boundaries
- The architecture relies on three external AI services:
- Gemini embeddings for vectorization
- Qdrant for vector search and storage
- Groq for LLM inference
- These are important boundaries because the backend orchestrates them rather than hosting models locally.
6. Prompt and configuration layer
- app/core/prompts.py defines the system prompting used to constrain answers to document context.
- app/core/config.py centralizes runtime configuration such as API keys, Qdrant connection details, and other environment-driven settings.
- This layer separates policy/configuration from the pipeline logic.
7. Frontend architecture
- The frontend lives under frontend/src and is organized as a small component-based UI:
- components/UploadBox.jsx for PDF upload
- components/ChatBox.jsx and components/MessageBubble.jsx for conversation display
- services/api.js for HTTP calls to the backend
- App.jsx stitches the upload and chat experiences together.
8. Client-server interaction
- The browser does not talk directly to Qdrant or the model providers.
- It only calls the backend API, which acts as an orchestration layer and hides the retrieval/model details.
- This keeps secrets, vector search, and prompt logic server-side.
9. Operational and debug utilities
- debug_pipeline.py is likely for testing or tracing the ingestion/retrieval flow end-to-end.
- reset_qdrant.py is an administrative utility to clear the vector store state.
- These scripts indicate the repo has a separate operational boundary for pipeline maintenance.
10. Deployment and environment
- The README describes deployment split across Render for the backend, Vercel for the frontend, and Qdrant Cloud for the vector database.
- requirements.txt and frontend/package.json define the Python and Node runtimes respectively.
- The system is environment-driven rather than monolithic: the app depends on configured external services at runtime.
11. Data flow summary
- Upload path: PDF → text extraction → chunking → embeddings → Qdrant
- Query path: question → query embedding → retrieval from Qdrant → prompt assembly → Groq response
- The architecture is a classic RAG loop with a clear separation between indexing and answering.
12. Diagramming takeaway
- When drawing this repo, show three major boxes:
- React UI
- FastAPI orchestration backend
- External AI/data services (Qdrant, Gemini embeddings, Groq)
- Then represent two internal backend pipelines: ingestion/indexing and question answering/retrieval.
Main entry points: upload.py Upload API · main.py FastAPI app · api.js API client · chat.py Chat API
Components 22
Frontend
Browser UI and client-side API calls.
- React app · Top-level browser application composition.
frontend/src/App.jsx - Upload box · User interface for selecting and sending PDFs.
frontend/src/components/UploadBox.jsx - Chat box · Conversation panel for asking questions and viewing replies.
frontend/src/components/ChatBox.jsx - Message bubble · Renders individual chat messages.
frontend/src/components/MessageBubble.jsx - API client · Browser-side wrapper for backend API requests.
frontend/src/services/api.js
Backend
FastAPI orchestration, ingestion, retrieval, and answer generation.
- run.py · Local backend startup wrapper.
run.py - FastAPI app · Assembles the FastAPI application and mounts routes.
app/main.py - Upload API · HTTP endpoint for PDF ingestion and indexing.
app/api/upload.py - Chat API · HTTP endpoint for questions and grounded answers.
app/api/chat.py - Config · Central runtime configuration and environment settings.
app/core/config.py - Prompts · System prompt templates and answer constraints.
app/core/prompts.py - PDF loader · Extracts text from uploaded PDFs.
app/services/pdf_loader.py - Chunking · Splits extracted text into overlapping chunks.
app/services/chunking.py - Embeddings · Turns text chunks and queries into vectors.
app/services/embeddings.py - Vector store · Persists vectors and metadata into Qdrant.
app/services/vector_store.py - Retriever · Finds relevant chunks from Qdrant for a question.
app/services/retriever.py - LLM client · Calls the model with retrieved context to produce an answer.
app/services/llm.py
External services
Managed AI and storage dependencies used at runtime.
- Gemini embeddings · Hosted embedding service used for vectorization.
- Qdrant · External vector database for storage and retrieval.
- Groq · Hosted inference service for answer generation.
Ops
Local utilities for debugging and maintenance.
- Debug pipeline · End-to-end ingestion and retrieval tracing helper.
debug_pipeline.py - Reset Qdrant · Utility for clearing vector store state.
reset_qdrant.py
Connections 28
- run.py → FastAPI app: starts · Launches the FastAPI application.
- FastAPI app → Upload API: mounts · Registers the upload route module.
- FastAPI app → Chat API: mounts · Registers the chat route module.
- FastAPI app → Config: loads · Reads runtime configuration.
- Upload API → PDF loader: extracts · Converts uploaded PDFs into text.
- Upload API → Chunking: splits · Breaks extracted text into chunks.
- Upload API → Embeddings: vectorizes · Creates embeddings for chunks.
- Upload API → Vector store: indexes · Writes vectors and metadata to the index.
- PDF loader → Chunking: feeds · Text extraction feeds chunking.
- Chunking → Embeddings: feeds · Chunks are embedded for retrieval.
- Embeddings → Gemini embeddings: uses · Delegates vector generation to Gemini.
- Vector store → Qdrant: stores · Persists indexed content in Qdrant.
- Chat API → Retriever: retrieves · Finds relevant context for the user question.
- Chat API → LLM client: answers · Generates a grounded answer from context.
- Retriever → Embeddings: embeds · Embeds the user query before search.
- Retriever → Qdrant: queries · Searches the vector database for matches.
- LLM client → Prompts: applies · Uses prompt templates to constrain answers.
- LLM client → Groq: calls · Sends the prompt to the hosted LLM.
- React app → Upload box: contains · Composes upload UI.
- React app → Chat box: contains · Composes chat UI.
- Chat box → Message bubble: renders · Displays individual messages.
- Upload box → API client: uploads · Sends PDFs to the backend.
- Chat box → API client: asks · Sends questions to the backend.
- API client → Upload API: calls · Browser requests the upload endpoint.
- API client → Chat API: calls · Browser requests the chat endpoint.
- Debug pipeline → PDF loader: traces · Exercises the extraction stage.
- Debug pipeline → Retriever: traces · Exercises the retrieval stage.
- Reset Qdrant → Qdrant: clears · Administrative reset of vector storage.