explaingit

honestsoul/rag_patterns

29Python

TLDR

This repository is a teaching collection of five small Python scripts, each one showing a different way to wire up a Retrieval-Augmented Generation system.

Mindmap

A visual breakdown will appear here once this repo is fully enriched.

In plain English

This repository is a teaching collection of five small Python scripts, each one showing a different way to wire up a Retrieval-Augmented Generation system. RAG, in plain terms, is the technique of looking things up from a document store and then handing those snippets to a language model so it can write a better answer. The five scripts are kept simple on purpose: nothing calls a real cloud model, no API keys are needed, and the embeddings and LLM responses are faked with deterministic random numbers. The point is to see the shape of each pipeline, not to measure quality. The first script, hybrid RAG, runs two searches at once over the same documents. One uses dense vector similarity (the kind powered by neural embeddings) and the other uses BM25, a classic keyword scoring method written from scratch here. The two ranked lists are merged with Reciprocal Rank Fusion and the top results go to the model. The second script builds a knowledge graph with the networkx library, where people, companies, technologies, and locations become nodes and verbs like founded or ceo_of become labelled edges. A query first extracts entities, then walks the graph a few hops to gather a subgraph, then summarises that subgraph before sending it to the model. The third script, agentic RAG, sets up a planner that picks tools to call (vector search, web search, or SQL), runs them in a loop until confidence is high enough, and then asks a reasoner agent to write the final answer. The fourth script, corrective RAG, scores the retrieved chunks and branches on the verdict: keep them, rewrite the query and try again, or fall back to a simulated web search. The fifth script is multimodal, mapping text chunks, image captions, and tables into one shared vector space and re-ranking by the modality the query asks for. Dependencies are just numpy and networkx.

Open on GitHub → Explain another repo

Generated 2026-05-21 · Model: sonnet-4-6 · Verify against the repo before relying on details.