gitmyhub

AI_chatbot_Rag

Python ★ 41 updated 15d ago

Enterprise-grade RAG chatbot with Hybrid Retrieval and BGE Reranking

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.

PythonFastAPIMilvusPostgreSQLLangChainJavaScriptBM25BGEsetup: hardcomplexity 4/5

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.

Where it fits