[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"project-80981":3},{"id":4,"name":5,"fullName":6,"owner":7,"repo":5,"description":8,"homepage":8,"htmlUrl":8,"language":9,"languages":8,"totalLinesOfCode":8,"stars":10,"forks":11,"watchers":12,"openIssues":13,"contributorsCount":13,"subscribersCount":13,"size":13,"stars1d":13,"stars7d":12,"stars30d":14,"stars90d":13,"forks30d":13,"starsTrendScore":13,"compositeScore":15,"rankGlobal":8,"rankLanguage":8,"license":8,"archived":16,"fork":16,"defaultBranch":17,"hasWiki":18,"hasPages":16,"topics":19,"createdAt":8,"pushedAt":8,"updatedAt":20,"readmeContent":21,"aiSummary":22,"trendingCount":13,"starSnapshotCount":13,"syncStatus":12,"lastSyncTime":23,"discoverSource":24},80981,"rag_patterns","honestsoul\u002Frag_patterns","honestsoul",null,"Python",33,18,2,0,3,39.14,false,"claude\u002Fcreate-sequential-examples-ZD52z",true,[],"2026-06-12 04:01:31","# RAG Architecture Patterns\n\nFive self-contained Python examples demonstrating different Retrieval-Augmented\nGeneration (RAG) architectures. Every script runs fully offline — no API keys\nrequired. All LLM responses and embeddings are mocked or generated with\ndeterministic random vectors so the focus stays on the pipeline logic.\n\n## Setup\n\n```bash\npip install -r requirements.txt\n```\n\n## Patterns\n\n### 1. Hybrid RAG (`01_hybrid_rag.py`)\n\nCombines **dense vector search** (fake CLIP-style embeddings + cosine similarity\nstore) with **sparse keyword search** (hand-rolled BM25). Both retrievers run in\nparallel on the same query, then results are merged via **Reciprocal Rank Fusion\n(RRF)**. The fused top-K chunks are passed to the LLM.\n\n```\nQuery → Dense Retrieval ─┐\n      → BM25 Retrieval  ─┴→ RRF → Top-K chunks → LLM → Answer\n```\n\n```bash\npython 01_hybrid_rag.py\n```\n\n---\n\n### 2. GraphRAG (`02_graph_rag.py`)\n\nBuilds a **Knowledge Graph** (using `networkx`) from the document corpus.\nNamed entities (Person, Company, Technology, Location) become nodes; typed\nrelationships (founded, ceo_of, invested_in, …) become directed edges.\nAt query time, query entities seed a **multi-hop subgraph traversal**; the\nretrieved subgraph is summarised into a community description fed to the LLM.\n\n```\nQuery → Entity Extraction → KG Subgraph Retrieval → Community Summary → LLM → Answer\n```\n\n```bash\npython 02_graph_rag.py\n```\n\n---\n\n### 3. Agentic RAG (`03_agentic_rag.py`)\n\nA **Planner Agent** analyses the query and selects an ordered sequence of tools\nto invoke. Three tools are available: `VectorSearchTool`, `WebSearchTool`, and\n`SQLDatabaseTool`. The agent loop executes each tool, tracks accumulated\nconfidence, and short-circuits when confidence is high enough. A **Reasoner\nAgent** then synthesises all tool results into a final answer.\n\n```\nQuery → Planner → [Tool Loop: Vector \u002F Web \u002F SQL] → Reasoner → Answer\n```\n\n```bash\npython 03_agentic_rag.py\n```\n\n---\n\n### 4. Corrective RAG — CRAG (`04_corrective_rag.py`)\n\nAfter initial retrieval an **Evaluator\u002FGrader** scores relevance via keyword\noverlap and emits one of three verdicts:\n\n- **CORRECT** → pass chunks directly to the LLM.\n- **AMBIGUOUS** → rewrite the query and re-retrieve, then go to LLM.\n- **INCORRECT** → fall back to a simulated web search, then go to LLM.\n\nThree demo queries exercise all three branches in one run.\n\n```\nQuery → Retriever → Evaluator ──CORRECT──→ LLM → Answer\n                             ├─AMBIGUOUS─→ Rewriter → Re-retrieve → LLM → Answer\n                             └─INCORRECT─→ Web Search → LLM → Answer\n```\n\n```bash\npython 04_corrective_rag.py\n```\n\n----\n\n### 5. Multimodal RAG (`05_multimodal_rag.py`)\n\nIndexes three modality types — **text chunks**, **images\u002Fcharts** (represented\nby captions and tags), and **tables** — into a single unified vector index using\na mock CLIP-style embedder that maps every modality to the same 64-dimensional\nspace. At query time, modality preferences are detected (\"chart\", \"table\", …)\nand a post-retrieval **modality boost** re-ranks results before the mock\nMultimodal LLM generates an answer referencing text, images, and tables together.\n\n```\nText Chunks ─┐\nImages      ─┼→ Multimodal Embedder → Unified Index → Retrieval → Boost → MLLM → Answer\nTables      ─┘\n```\n\n```bash\npython 05_multimodal_rag.py\n```\n\n---\n\n## Dependencies\n\n| Library    | Used by                          |\n|------------|----------------------------------|\n| `numpy`    | all files (fake embeddings)      |\n| `networkx` | `02_graph_rag.py` (KG traversal) |\n\nBM25 is implemented from scratch in `01_hybrid_rag.py` — no extra package needed.\n","该项目提供了五个独立的Python示例，演示了不同的检索增强生成（RAG）架构。每个脚本都可以完全离线运行，无需API密钥，所有大型语言模型响应和嵌入都是通过确定性随机向量模拟或生成的，重点在于展示管道逻辑。核心功能包括混合RAG、GraphRAG、Agentic RAG、Corrective RAG以及Multimodal RAG，分别展示了密集向量搜索与稀疏关键词搜索结合、基于知识图谱的信息检索、代理辅助查询处理、结果校正机制以及多模态数据索引等技术特点。这些模式适用于需要高效信息检索与生成的应用场景，如智能客服、内容推荐系统或文档理解工具，特别适合于希望在不依赖外部服务的情况下实现复杂查询处理的研究人员和开发者。","2026-06-11 04:03:04","CREATED_QUERY"]