weiwill88/Local_Pdf_Chat_RAG

🧠 纯原生 Python 实现的 RAG 框架 | FAISS + BM25 混合检索 | 支持 Ollama / SiliconFlow | 适合新手入门学习

What it solves

This project provides a localized intelligent Q&A system designed to help developers understand and implement Retrieval-Augmented Generation (RAG). It solves the problem of "black box" RAG implementations by providing a transparent, modular pipeline for chatting with local documents while supporting various LLM backends.

How it works

The system follows a structured RAG pipeline:

  1. Document Processing: Extracts text from multiple formats (.pdf, .txt, .docx, .md, .html, .csv, .xls, .xlsx), splits them into chunks, and converts them into vectors.
  2. Hybrid Retrieval: Combines FAISS semantic search with BM25 keyword search to improve recall and accuracy.
  3. Reranking: Uses a CrossEncoder or an LLM to refine the retrieved results.
  4. Generation: Constructs a prompt with the retrieved context and sends it to a configured LLM (Ollama, SiliconFlow, or Magick API) to generate the final answer.
  5. Optional Enhancements: Can integrate SerpAPI for real-time web search and supports Chain-of-Thought processing via DeepSeek-R1.

Who it’s for

It is primarily for developers and RAG beginners who want a hands-on learning platform to practice document loading, vectorization, hybrid retrieval, and LLM integration.

Highlights

  • Hybrid Search Strategy: Integrates both FAISS (semantic) and BM25 (keyword) retrieval.
  • Flexible LLM Backends: Supports local inference via Ollama and cloud APIs like SiliconFlow and Magick API with automatic backend detection.
  • Advanced RAG Techniques: Implements result reranking via CrossEncoders and recursive retrieval.
  • Interactive UI: Features a Gradio-based web interface that includes visualization of document chunks.