How AI agents remember, reason over relationships, and retrieve knowledge at scale — from raw text to navigable knowledge graphs.
A stateless agent forgets everything between conversations. RAG — Retrieval-Augmented Generation — solves this by storing knowledge externally and fetching only what's relevant, when it's needed.
Stores text as numerical vectors. Retrieves by semantic similarity — "find things with similar meaning." Fast, scalable, excellent fuzzy search.
Stores entities and relationships as a knowledge graph. Retrieves by traversing connections — "follow the chain from A to B to C."
Vector RAG is a filing cabinet — search by similarity, retrieve relevant documents, each unaware of the others.
Graph RAG is a murder board — photos and strings connecting people, events, and locations. The connections are the intelligence.
Hybrid is the full detective operation. Cabinet for fast lookup, board for deep reasoning.
Before anything else works, text must become numbers. An embedding model converts any text into a vector such that similar meanings produce numerically close vectors.
The algorithm that asks: which weights caused the error, and by exactly how much should each one change? It computes all N gradients in a single backward pass — the reason training billion-parameter models is feasible.
| Step | Operation | Value |
|---|---|---|
| Inputs | x₁=2.0, x₂=3.0, w₁=0.5, w₂=−0.3, b=0.1, y=1.0 | — |
| z | 0.5(2.0) + (−0.3)(3.0) + 0.1 | 0.2 |
| a = σ(z) | 1 / (1 + e⁻⁰·²) | 0.550 |
| L = (a−y)² | (0.550 − 1.0)² | 0.2025 |
| ∂L/∂a | 2 × (0.550 − 1.0) | −0.900 |
| ∂a/∂z | 0.550 × (1 − 0.550) | 0.2475 |
| ∂L/∂z | −0.900 × 0.2475 | −0.2228 |
| ∂L/∂w₁ | −0.2228 × 2.0 | −0.4456 |
| New w₁ | 0.5 − 0.1 × (−0.4456) | 0.5446 ↑ |
| New w₂ | −0.3 − 0.1 × (−0.6683) | −0.2332 ↑ |
After building the knowledge graph, the Leiden algorithm clusters it into communities — dense groups of related nodes. It maximises modularity Q while guaranteeing every community is internally connected.
Hierarchical Navigable Small World graphs make nearest-neighbour search on millions of vectors run in milliseconds. The key insight: long-range shortcuts for fast global navigation, dense local edges for precise fine-grained search.
Every algorithm in this guide is an essential gear in the same machine. Here is the complete flow — from new information arriving to an answer being generated.
Vectors find the right neighbourhood in the knowledge base. Graphs navigate the streets and connections within that neighbourhood. Leiden organises the map. HNSW makes the search instant. Backpropagation is what taught the model to read the map at all.