Architecture
How AskDocuMind is put together: where a request goes, how a document becomes searchable, and how an answer is built. Each diagram covers one part of the system.
System overview
The Next.js client on Vercel reaches the FastAPI API on Railway through Cloudflare. The API uses Postgres with pgvector on Neon, an S3-compatible bucket, OpenAI and Brave Search, and runs ingestion, the upload sweeper and user cleanup as background tasks in the same process.
RAG pipeline
The question is rewritten by gpt-4o-mini, embedded, and matched against this chat’s chunks in pgvector. If fewer than 3 match and web search is on, Brave Search adds up to 5 pages. A cross-encoder reranks the results, and the top 15 go to gpt-4o-mini to write the answer.
Upload handling
Uploads are validated, saved to object storage and acknowledged with a 202. A background task, up to 5 at once, extracts, chunks and embeds the text, while a sweeper retries or fails stuck uploads every 60 seconds.
Data models
Five tables: users, chat sessions, chat messages, documents and chunk embeddings, all with cascading deletes. Each chunk stores a 1536-dimension vector and its chat ID, so searches stay within one chat.