Ollama + FastAPI: build a local RAG app

Build a PDF chat app with Ollama, FastAPI and Qdrant, then add BM25 hybrid search, cross-encoder reranking and session-based memory.

Player not loading? Watch on YouTube

This tutorial builds a PDF question-answering app with Ollama, a FastAPI backend and a Streamlit interface. The presenter describes the finished app as running entirely on the user's machine. It supports multiple documents, returns source information with answers, and lets users list and delete indexed documents.

The walkthrough starts with Python virtual environments and a PDF upload endpoint. Docling parses document structure and splits the text into chunks. Ollama generates embeddings with nomic-embed-text, while Qdrant stores the vectors and text metadata. Qdrant runs through Docker, which viewers need to install. The local LLM used for answers is llama3.1; the presenter says another model in the Ollama installation can replace it.

Retrieval begins with semantic search, then adds BM25 keyword matching through rank-bm25. The hybrid pipeline requests extra candidates from both searches, removes duplicates using document IDs and chunk indexes, and passes the merged results to a cross-encoder for reranking. The speaker explains that this slower step runs only on the shortlist.

Conversation history uses a Python dictionary keyed by session ID. It supports follow-up exchanges, but a server restart erases the history. Persistent storage and rewriting follow-up questions for retrieval remain future work. The final section connects the backend to a chat interface with PDF uploads and expandable source details.