深度迭代检索增强系统
一个教学项目,带你从零开始,利用大语言模型构建一套融合多种先进技术的RAG系统,体验智能信息探索的魅力。
MetaSearch is an advanced Retrieval-Augmented Generation (RAG) system built upon the principle of deep iterative retrieval. It progressively refines searches, integrates multiple retrieval techniques, and leverages Large Language Models (LLMs) to provide comprehensive and contextually rich answers.
Learn best practices for building LLM projects with a clean, modular architecture following community standards.
Implements cutting-edge RAG algorithms, exploring information deeply through multiple search iterations.
Combines vector search, keyword search (TF-IDF), and knowledge graph retrieval for broader coverage.
Dynamically generates sub-queries using LLMs to achieve greater breadth and depth in knowledge exploration.
Decides whether to continue searching based on the ratio of newly discovered information, optimizing efficiency.
Utilizes Maximal Marginal Relevance (MMR) to balance relevance and diversity, providing more comprehensive results.
Splits raw documents into manageable text chunks with context and summaries.
Builds Vector, TF-IDF, and Knowledge Graph indexes for efficient retrieval.
Combines multiple retrieval methods (vector, keyword, graph) to find relevant documents.
Generates new sub-queries based on retrieved information using LLMs.
Coordinates the iterative retrieval process and synthesizes the final answer.
MetaSearch/
├── config/ # Configuration files (YAML)
├── data/ # Data directory (raw, processed, indexes)
│ ├── raw/
│ ├── processed/
│ └── indexes/
├── deepsearch/ # Core library code
│ ├── indexing/ # Indexing logic (vector, tfidf, graph)
│ ├── llm/ # LLM interface wrappers
│ ├── preprocessing/# Document parsing and chunking
│ ├── rag/ # RAG pipeline implementation (standard, deep)
│ ├── retrieval/ # Retrieval strategies and re-ranking
│ └── utils/ # Utility functions
├── scripts/ # Helper scripts (downloading, processing)
├── app.py # Main application entry point
├── requirements.txt # Project dependencies
└── README.md # Project documentation
Raw documents are parsed and split into overlapping chunks. Each chunk stores:
content
: The main text of the chunk.chunk_id
: A unique identifier.parent_content
: Optional larger context block.abstract
: LLM-generated summary (optional).# Example config (config/config.yaml)
processing:
chunk_size: 512 # Target size for each chunk
overlap_size: 64 # Overlap between consecutive chunks
generate_abstract: true # Whether to generate summaries
Multiple indexes capture different aspects of the data:
The retrieval module fuses results from enabled indexes.
Expands search scope iteratively:
The core engine operates in a loop:
# Example config (config/config.yaml)
deepsearch:
max_iterations: 3 # Max number of retrieval loops
growth_rate_threshold: 0.1 # Stop if less than 10% new info found
extend_query_num: 3 # Number of sub-queries per iteration
app.py --interactive
) to see it in action.app.py
: Understand initialization and the main RAG call.deepsearch/preprocessing/
: How are documents loaded and chunked?deepsearch/indexing/vector_index.py
: Basic vector index creation and search.deepsearch/llm/
: How does the code interface with LLMs (local or API)?deepsearch/rag/standard_rag.py
: The basic retrieve-then-generate pipeline.deepsearch/rag/deep_rag.py
: Understand the iterative loop, IGR, and query expansion logic.deepsearch/retrieval/
: Explore hybrid retrieval and MMR re-ranking.deepsearch/indexing/
.deepsearch/rag/query_expansion.py
.config/config.yaml
parameters (iterations, thresholds, models) and observe changes.MetaSearch is an open-source educational project. Contributions of all kinds are welcome!
Your Forks and PRs are welcome! ✨