explaingit

pchengli/ai_chatbot_rag

21PythonAudience · developerComplexity · 4/5Setup · hard

TLDR

A self-hosted chatbot that answers questions about documents you upload, using both semantic vector search and keyword matching together to find the most relevant passages before replying.

Mindmap

mindmap
  root((ai_chatbot_rag))
    What it does
      Answer questions on docs
      RAG retrieval pipeline
      Multiple knowledge bases
    Tech Stack
      FastAPI and Python
      Milvus vector database
      PostgreSQL
      LangChain
      JavaScript frontend
    Retrieval Methods
      Vector search
      BM25 keyword search
      BGE reranker
      Reciprocal Rank Fusion
    Features
      Document upload UI
      Conversation history
      ChatGPT-style interface
Click or tap to explore — scroll the page freely

Code map

Detail Auto

An interactive map of this repo's files and how they connect — its source is parsed live in your browser. Click Visualize to build it.

filefunction / class

Things people build with this

USE CASE 1

Upload internal company documents and ask the chatbot detailed questions about them without sending any data to an external service.

USE CASE 2

Build a support chatbot that finds answers from a product manual using both exact keyword matching and semantic similarity for better accuracy.

USE CASE 3

Maintain separate knowledge bases so different teams can each chat with their own document collections independently.

USE CASE 4

Add conversation history so the chatbot remembers earlier messages in a session and can answer follow-up questions in context.

Tech stack

PythonFastAPIMilvusPostgreSQLLangChainJavaScriptBM25BGE

Getting it running

Difficulty · hard Time to first run · 1h+

Requires running Milvus and PostgreSQL alongside the FastAPI backend, plus a separate npm step for the JavaScript frontend.

In plain English

This is a chatbot system built for answering questions about documents you upload. Instead of relying on a language model's general training alone, it pulls relevant passages from a private document collection and feeds them into the model as context before generating a reply. This approach is called Retrieval-Augmented Generation, or RAG. The result is a chatbot that can answer detailed questions about your own files rather than recalling generic knowledge. The retrieval side uses two methods running together. The first is vector search, which finds documents by meaning and similarity using a database called Milvus. The second is BM25 search, an older text-matching technique that locates exact keyword matches. Results from both methods are combined using a ranking algorithm called Reciprocal Rank Fusion, then passed through a BGE reranker that reorders the final candidates by relevance before they reach the language model. Documents are uploaded through a web interface that handles chunking (splitting long documents into smaller pieces), generating embeddings (numerical representations of meaning), and storing everything in PostgreSQL and Milvus. The system supports multiple separate knowledge bases so you can keep different document collections distinct. Conversation history is preserved across turns so follow-up questions are answered with context from earlier in the chat. The backend is built with FastAPI and Python, using LangChain for some integration work. The frontend is a separate JavaScript application with a chat interface styled after ChatGPT, complete with message bubbles and a document upload sidebar. Starting it requires standard Python and npm setup commands run in sequence.

Copy-paste prompts

Prompt 1
I have the ai_chatbot_rag project running with Milvus and FastAPI. How do I upload a PDF through the web interface and then ask it a question in the chat?
Prompt 2
Explain how Reciprocal Rank Fusion combines the BM25 and vector search results in ai_chatbot_rag to decide which document passages go to the language model.
Prompt 3
I want to replace the language model in ai_chatbot_rag with a locally running Ollama model instead. Which file in the FastAPI backend do I need to change?
Prompt 4
How do I create a second knowledge base in ai_chatbot_rag and assign specific uploaded documents to it so users can switch between bases in the chat?
Open on GitHub → Explain another repo

← pchengli on gitmyhub — every repo by this author, as a profile.

Verify against the repo before relying on details.