DEV Community

Elyass
Elyass

Posted on

How I Built a PDF Chat API in One Day with FastAPI, Gemini, and Qdrant

Have you ever wanted to just talk to a PDF instead of reading through 50 pages?

I built a full PDF Chat API in one day — upload any PDF, ask questions in natural language, and get AI-powered answers. Here's how I did it.

What it does

  • Upload any PDF document
  • Ask questions about its content in natural language
  • Get accurate answers powered by RAG (Retrieval Augmented Generation)
  • Clean web UI included — no frontend framework needed
  • REST API with authentication for easy integration

Tech Stack

  • FastAPI — REST API backend
  • Google Gemini — embeddings (gemini-embedding-001) + chat (gemini-2.5-flash)
  • Qdrant — vector database for semantic search
  • LangChain — RAG pipeline orchestration
  • Pure HTML/CSS — no React, no framework

How it works

The architecture is classic RAG in two phases:

Ingestion (upload):

  1. Extract text from PDF
  2. Split into chunks (1000 chars, 200 overlap)
  3. Generate embeddings with Gemini
  4. Store in Qdrant

Query (chat):

  1. Embed the user's question
  2. Search Qdrant for the 4 most relevant chunks
  3. Send chunks + question to Gemini
  4. Return the answer

The code

The core is surprisingly simple:

chain = (
    {"context": vector_store.as_retriever(search_kwargs={"k": 4}), 
     "question": RunnablePassthrough()}
    | prompt
    | llm
    | StrOutputParser()
)
Enter fullscreen mode Exit fullscreen mode

That's the entire RAG chain — retrieve relevant context, inject into prompt, generate answer.

What I learned

  • Gemini embeddings produce 3072-dimensional vectors (not 768 like older models)
  • grpcio on Windows can be a pain — pin to version 1.62.2
  • Qdrant Cloud free tier is genuinely useful for side projects
  • Building a clean UI in pure HTML/CSS takes less time than setting up React

Try it yourself

 get the packaged version ready to deploy:
👉 https://elyassdigital.gumroad.com/l/zcgjmmz

What's next

  • Multi-user support with separate collections per user
  • Docker deployment guide
  • Support for other document types (Word, Excel)

Built this as a side project — happy to answer questions in the comments!

Top comments (0)