blackinkkkxi/RAG_langchain
一个基于langchain实现RAG的简单示例
What it is
RAG_langchain is a study and implementation project that walks you from basic to advanced Retrieval-Augmented Generation (RAG) techniques. RAG is a pattern that lets a large language model (LLM) answer questions by first retrieving relevant pieces of information from your own documents, then generating a response grounded in that retrieved context. The project shows how to build such systems using the LangChain framework.
The project is a collection of Jupyter notebooks (files ending in .ipynb) and code modules that you can run and learn from. It is not a single library — it is an educational repo with practical examples.
What it covers
The README lists eight main areas:
- Document loading — loading and parsing various file formats (e.g., PDFs, including complex layouts like tables and multi-column pages).
- Text splitting — strategies for breaking documents into manageable chunks before embedding.
- Embeddings — how to choose and use embedding models (including OpenAI and Google's Gemini Embedding 2 for multimodal retrieval).
- Vector databases — using and comparing vector stores like Chroma, FAISS, and Milvus, including metadata filtering.
- LLM integration — support for OpenAI, DeepSeek, and others.
- Reranking — improving retrieval precision by re-scoring results after initial search.
- Evaluation — measuring RAG system quality using metrics like accuracy, recall, and response quality, and frameworks like RAGAS.
- Agent systems — building tool-calling agents and multi-agent collaborations (e.g., with AutoGen and LangGraph).
Each of these has dedicated code files and notebooks in the repository's learn/ folder, which is organized by topic.
How to get started
The README suggests a quick start path:
- Run
rag_chat.ipynbto build a basic RAG system with OpenAI. The flow is: load documents → split into chunks → embed → retrieve relevant chunks → generate an answer. - For a DeepSeek-based RAG, see
rag_deepseekR1.ipynb.
There is also a recommended learning route for beginners and advanced users (detailed under "Learning path" below).
Learning path
The README proposes a two-stage trajectory:
Beginner route:
- Run the basic RAG notebook to see the full flow.
- Study document loaders (
learn/doc_loader/). - Study text splitters (
learn/text_splitter/). - Study embedding models (
learn/embedding_model/).
Advanced route:
5. Dive into different vector databases (vectorDB/).
6. Learn reranking (learn/reranker/) to improve retrieval quality.
7. Build an evaluation system (learn/evaluation/).
8. Explore advanced retrieval methods (learn/advanced_method/).
9. Look into RLM (recursive LLM) in the RLM/ folder.
Additional content
Beyond the core RAG pipeline, the repo includes:
- Graph RAG (
graph_rag/) — a graph-based RAG implementation. - Chunk size optimization (
chunsize/) — exploring the best chunk sizes. - Hybrid retrieval — combining dense (vector) and sparse (keyword-based) search.
- A mini Claude Code — a simplified version of an AI coding agent, with a complete flow in
mini_claude_code/mini_claude_code.py(marked as a work-in-progress with a TODO). - Star History — the README asks for stars on GitHub, so this is a community project.
Project structure (high-level)
RAG_langchain/
├── agent/ # Agent frameworks (multi-agent, tool calling)
├── vectorDB/ # Vector database examples
├── learn/ # Core learning modules (loaders, splitters, embeddings, rerankers, evaluation, advanced methods)
├── chunsize/ # Chunk size experiments
├── graph_rag/ # Graph RAG
├── RLM/ # Recursive LLM experiments
├── data/ # Sample data
└── *.ipynb # Main implementation notebooks
In short
RAG_langchain is a practical, notebook-driven tutorial that shows you how to assemble all the pieces of a production-grade RAG system — from loading documents to evaluating the final answers — while also covering more advanced topics like agents and graph-based retrieval. It is aimed at people who want to learn by example rather than just reading theory.
Related
- Project
- Project
- Project
- Project