Free forever

Knowledge Lab

Master AI/ML from first principles

πŸ€–LLM Fundamentals52
πŸ”RAG Techniques40
⚑Intelligent Search10

102 articles

Search
Beginner

What Is Vector Search?

How machines find meaning by turning words into coordinates β€” and why search changed forever when they did.

5 min
Read
Search
Beginner

Embeddings: Turning Text into Vectors

What embedding models are, how they produce vectors, why context changes the output, and how to generate and cache embeddings efficiently.

7 min
Read
Search
Beginner

Similarity Metrics: Cosine, Euclidean, Dot Product

How the three main distance functions work, when each one wins, and the key insight that cosine ignores magnitude β€” which is almost always what you want for text.

6 min
Read
Search
Intermediate

kNN and HNSW: How Vector Search Scales

Why brute-force kNN breaks at scale, how HNSW solves it with a multi-layer graph, and which three parameters control the accuracy vs. speed tradeoff.

8 min
Read
Search
Intermediate

Dense Vector Search: How Semantic Search Works

The full lifecycle of dense semantic search β€” from document ingestion through embedding, HNSW indexing, and query β€” with benchmarks on what it gets right and where it fails.

8 min
Read
Search
Intermediate

Sparse Encoding: Fast, Interpretable, and Underrated

TF-IDF sparse vectors explained β€” why 99.97% of the vector is zeros, how that makes search 10x faster than dense, and when sparse consistently beats semantic.

8 min
Read
Search
Intermediate

Hybrid Search: Combining Dense, Sparse, and Keyword

How combining three search engines β€” keyword, sparse, and dense β€” pushes NDCG from 0.85 to 0.91, with score normalization, weight tuning, and the architecture that makes it fast.

9 min
Read
Search
Intermediate

Vector Indexes: How Search Engines Store and Retrieve Vectors

How vector indexes work under the hood β€” collections, payload filtering, snapshot strategy, and the operational details that matter when serving real search traffic.

7 min
Read
Search
Intermediate

Quantization: Cut Vector Memory by 4–40x

INT8, FP16, and binary quantization explained β€” the memory-recall tradeoff, how rescoring recovers lost precision, and when compression actually hurts.

6 min
Read
Search
Intermediate

Measuring Search Quality: NDCG, Recall, and A/B Testing

How to measure search quality with NDCG@10 and recall@k, build a ground-truth dataset, benchmark your pipeline, and run A/B tests to validate improvements.

7 min
Read
LLM
Beginner

LLM (Large Language Model)

Transformer-based model trained on massive text corpora that generates text by predicting the next token.

6 min
Read
LLM
Beginner

Token

The atomic unit of text that an LLM processes β€” a sub-word piece that balances vocabulary size and semantic meaning.

5 min
Read
LLM
Beginner

Tokenization

Converting raw text into token IDs the model can process β€” and back again.

5 min
Read
LLM
Beginner

Embeddings

Dense numerical vectors that encode semantic meaning β€” similar concepts cluster together in high-dimensional space.

6 min
Read
LLM
Intermediate

Latent Space

The high-dimensional space where embeddings live and organize by semantic meaning.

5 min
Read
LLM
Beginner

Parameters

The learned numerical weights that store everything the model knows β€” billions of numbers shaped by training.

5 min
Read
LLM
Beginner

Next Token Prediction

The core training objective: given prior tokens, predict the most probable next one.

4 min
Read
LLM
Intermediate

Transformer Architecture

The neural architecture underlying all modern LLMs β€” processes all tokens in parallel using self-attention.

8 min
Read
LLM
Intermediate

Attention / Self-Attention

The mechanism that lets every token dynamically focus on every other token based on relevance.

8 min
Read
LLM
Advanced

Scaling Laws

Empirical rules predicting LLM performance as a function of model size, data, and compute.

6 min
Read
LLM
Intermediate

Logits & Softmax

Raw unnormalized scores from the model output layer, converted to probabilities via softmax.

5 min
Read
LLM
Advanced

Mixture of Experts (MoE)

Architecture where only a subset of parameters activate per token β€” enabling massive scale efficiently.

6 min
Read
LLM
Intermediate

Pre-training

Training a model from scratch on massive text corpora using next-token prediction as the objective.

6 min
Read
LLM
Beginner

Base Model

The raw pre-trained model β€” powerful but not instruction-following. The foundation everything else builds on.

4 min
Read
LLM
Beginner

Instruct Model

A base model fine-tuned to follow instructions as a helpful assistant.

4 min
Read
LLM
Intermediate

Fine-Tuning

Continued training on a smaller task-specific dataset to adapt the model for particular behaviors.

6 min
Read
LLM
Advanced

LoRA & PEFT

Parameter-Efficient Fine-Tuning β€” adapt only a tiny fraction of parameters (0.1–1%) rather than the full model.

6 min
Read
LLM
Advanced

Quantization

Reducing weight precision from FP32 to INT8/INT4 to shrink memory footprint and speed up inference.

5 min
Read
LLM
Intermediate

Alignment

Training the model to be helpful, honest, and harmless β€” making model behavior match human values.

5 min
Read
LLM
Advanced

RLHF

Reinforcement Learning from Human Feedback β€” using human preference rankings to guide model behavior.

7 min
Read
LLM
Advanced

DPO (Direct Preference Optimization)

A simpler alternative to RLHF that directly optimizes from preference pairs without a reward model.

6 min
Read
LLM
Intermediate

Guardrails

Safety mechanisms that block harmful or off-policy inputs and outputs in production systems.

5 min
Read
LLM
Intermediate

Prompt Injection

Malicious input that overrides developer instructions to hijack model behavior.

5 min
Read
LLM
Beginner

Prompt

The full text input sent to the model β€” everything it sees before generating a response.

4 min
Read
LLM
Beginner

System Prompt

Developer-set instructions that define the model's role, rules, and behavior for a session.

4 min
Read
LLM
Beginner

User Prompt

The end user's actual question or instruction sent at runtime.

3 min
Read
LLM
Beginner

Zero-Shot Prompting

Asking the model to perform a task without any examples β€” relying purely on its training.

4 min
Read
LLM
Beginner

Few-Shot Prompting

Providing examples in the prompt to guide model behavior without changing model weights.

4 min
Read
LLM
Intermediate

Chain of Thought

Prompting the model to show step-by-step reasoning before answering, dramatically improving accuracy on complex tasks.

5 min
Read
LLM
Intermediate

In-Context Learning

The model's ability to adapt to new tasks purely from examples in the prompt β€” no weight updates needed.

5 min
Read
LLM
Beginner

Context Window

The maximum number of tokens the model can see and process at once β€” its working memory.

5 min
Read
LLM
Beginner

Inference

The process of generating output from a trained model β€” what happens when you call the API.

5 min
Read
LLM
Beginner

Latency

Time-to-first-token and total generation time β€” the key performance metrics for production LLM systems.

5 min
Read
LLM
Beginner

Temperature

The parameter controlling randomness in token sampling β€” 0 is deterministic, higher values are more creative.

5 min
Read
LLM
Intermediate

Top-P & Top-K Sampling

Sampling strategies that filter which tokens can be selected as the next output token.

5 min
Read
LLM
Advanced

KV Cache

Cached attention key-value states enabling efficient autoregressive generation without recomputing past tokens.

6 min
Read
LLM
Beginner

Streaming

Delivering tokens incrementally as they are generated rather than waiting for the full response.

4 min
Read
LLM
Advanced

Reasoning Models

Models that use extended internal 'thinking' β€” visible chain-of-thought before answering β€” for complex tasks.

6 min
Read
LLM
Beginner

Hallucination

When the model confidently generates false, fabricated, or unsupported content as if it were fact.

5 min
Read
LLM
Intermediate

Grounding

Constraining model outputs to provided, verifiable information to prevent hallucination.

5 min
Read
LLM
Intermediate

RAG (Retrieval-Augmented Generation)

Retrieving relevant external documents at query time and injecting them into the prompt to ground generation.

6 min
Read
LLM
Intermediate

Workflow

A fixed, predefined sequence of LLM-powered steps with deterministic control flow.

5 min
Read
LLM
Intermediate

Agent

An LLM used as a dynamic reasoning engine that plans, uses tools, and adapts based on feedback.

6 min
Read
LLM
Intermediate

Tool Use & Function Calling

The model outputs structured requests to invoke external tools β€” APIs, databases, code executors.

6 min
Read
LLM
Intermediate

Structured Output

Constraining model output to a predefined schema β€” JSON, XML β€” for reliable downstream processing.

5 min
Read
LLM
Advanced

MCP (Model Context Protocol)

Anthropic's open protocol for connecting LLMs to external tools, data sources, and services.

6 min
Read
LLM
Advanced

Prompt Caching

Reusing precomputed KV states for repeated prompt prefixes to slash latency and cost.

5 min
Read
LLM
Beginner

Benchmarks

Standardized tests used to compare model capabilities across tasks and providers.

5 min
Read
LLM
Intermediate

Evals

Custom evaluation frameworks for measuring model performance on your specific use case.

6 min
Read
LLM
Intermediate

LLM-as-Judge

Using a powerful model to evaluate another model's outputs β€” scalable alternative to human evaluation.

5 min
Read
LLM
Intermediate

Multimodality

Models that process and generate across text, images, audio, and video simultaneously.

5 min
Read
LLM
Advanced

Emergent Abilities

Capabilities that appear suddenly and unpredictably in models above certain scale thresholds.

5 min
Read
RAG
Intermediate

33 RAG Patterns β€” Complete Tier Guide

33 production RAG patterns organized across 9 tiers β€” from basic chunking to multi-tenant federation. Each pattern links to a working notebook.

12 min
Read
RAG
Beginner

Simple RAG

The foundation β€” load a PDF, split into chunks, embed with Bedrock Titan, store in Qdrant, and retrieve by similarity.

8 min
Read
RAG
Beginner

Semantic Chunking

Same as Simple RAG but with smarter scissors β€” splits where the topic actually changes instead of every 1000 characters.

8 min
Read
RAG
Advanced

Hierarchical Indexing - Multi-Level Document Structure

Index documents at multiple granularities β€” summaries at the top, sections in the middle, sentences at the bottom β€” and retrieve at the right level for each query.

8 min
Read
RAG
Intermediate

Parent Document Retrieval - Fine Retrieve, Broad Context

Index small child chunks for precise retrieval, but return their larger parent chunk to the LLM β€” combining retrieval precision with generation context.

7 min
Read
RAG
Intermediate

Sentence Window Retrieval - Precise Match, Rich Context

Index individual sentences for precise embedding match, then expand each match to its surrounding N-sentence window before passing to the LLM.

7 min
Read
RAG
Intermediate

Hybrid Search RAG - Best of All Worlds

Pattern #34 - Hybrid Search RAG - Best of All Worlds. Complete implementation with AWS Bedrock, code examples, and performance metrics.

8 min
Read
RAG
Intermediate

HyDE - Hypothetical Document Embeddings

Generate hypothetical ideal answers, embed them, and use those embeddings to find better source documents. Improves retrieval for complex queries.

6 min
Read
RAG
Intermediate

Reranking

The quality filter β€” retrieves 10 docs, then a second model re-scores them. Two methods: fast cross-encoder or smarter LLM reranking.

10 min
Read
RAG
Intermediate

Cross-Encoder Reranking - Precise Relevance Scoring

Re-score retrieved candidates with a cross-encoder model that jointly encodes query and document for highly accurate relevance ranking.

7 min
Read
RAG
Intermediate

Contextual Compression - Smart Context Reduction

Intelligently compress retrieved context by removing irrelevant information while preserving key facts. Reduces tokens and improves response quality.

7 min
Read
RAG
Intermediate

Query Decomposition - Break Complex Queries

Pattern #9 - Query Decomposition - Break Complex Queries. Complete implementation with AWS Bedrock, code examples, and performance metrics.

6 min
Read
RAG
Intermediate

Step-Back Prompting - Abstract Before You Search

Transform a specific, narrow query into a broader abstract question first, retrieve general principles, then combine abstract and specific context for a grounded answer.

7 min
Read
RAG
Intermediate

Fusion Retrieval - Multi-Strategy Search

Combine multiple retrieval strategies (vector, keyword, graph) with reciprocal rank fusion for robust search results across diverse query types.

7 min
Read
RAG
Intermediate

Multi-Query RAG - Parallel Retrieval from Multiple Angles

Generate several distinct sub-queries from a complex question, retrieve for each in parallel, then merge and deduplicate before generation.

7 min
Read
RAG
Intermediate

Query Routing - Send Each Query to the Right Retriever

Classify each incoming query and route it to the most appropriate retrieval backend β€” vector store, SQL, graph, or web β€” instead of always using the same index.

7 min
Read
RAG
Advanced

Corrective RAG (CRAG) - Self-Correcting Retrieval

Automatically detect and correct irrelevant or incorrect retrievals. Uses relevance grading and web search fallback for improved accuracy.

8 min
Read
RAG
Intermediate

Self-RAG

The smart decision maker β€” decides if retrieval is needed, filters irrelevant docs, generates multiple answers, and picks the best one.

10 min
Read
RAG
Advanced

Iterative Retrieval - Progressive Query Refinement

Retrieve, inspect intermediate results, refine the query, retrieve again β€” iterate until the retrieved context is sufficient to answer the question.

8 min
Read
RAG
Intermediate

Recursive RAG - Iterative Deep Search

Pattern #10 - Recursive RAG - Iterative Deep Search. Complete implementation with AWS Bedrock, code examples, and performance metrics.

8 min
Read
RAG
Advanced

Agentic RAG - Autonomous Decision Making

Empower LLMs to autonomously decide when to retrieve, what to search, and how to combine information. Advanced pattern for complex multi-step reasoning.

10 min
Read
RAG
Intermediate

Memory Augmented RAG - Conversational Context Across Turns

Persist conversation history and user context across turns so retrieval is conditioned on the full dialogue, not just the latest query.

7 min
Read
RAG
Intermediate

Ensemble Retrieval - Combining Multiple Retrieval Strategies

Run multiple retrieval strategies in parallel and merge results using Reciprocal Rank Fusion for higher recall than any single retriever.

7 min
Read
RAG
Intermediate

Adaptive RAG - Dynamic Strategy Selection

Pattern #8 - Adaptive RAG - Dynamic Strategy Selection. Complete implementation with AWS Bedrock, code examples, and performance metrics.

7 min
Read
RAG
Intermediate

Streaming RAG - Real-Time Responses

Pattern #32 - Streaming RAG - Real-Time Responses. Complete implementation with AWS Bedrock, code examples, and performance metrics.

7 min
Read
RAG
Beginner

Cached RAG - Performance Optimization

Pattern #33 - Cached RAG - Performance Optimization. Complete implementation with AWS Bedrock, code examples, and performance metrics.

5 min
Read
RAG
Advanced

Production RAG - Enterprise Deployment

Pattern #35 - Production RAG - Enterprise Deployment. Complete implementation with AWS Bedrock, code examples, and performance metrics.

10 min
Read
RAG
Advanced

RAPTOR

Recursive Abstractive Processing for Tree-Organized Retrieval β€” builds a hierarchical summary tree for multi-level querying.

10 min
Read
RAG
Intermediate

Graph RAG - Knowledge Graph Enhanced Retrieval

Enhance RAG with knowledge graphs to capture entity relationships and improve contextual understanding. Learn how to build graph-based retrieval systems.

8 min
Read
RAG
Advanced

Tree of Thoughts RAG - Branching Reasoning

Pattern #15 - Tree of Thoughts RAG - Branching Reasoning. Complete implementation with AWS Bedrock, code examples, and performance metrics.

10 min
Read
RAG
Advanced

Knowledge Graph RAG - Structured Reasoning with Entity Graphs

Augment RAG with a knowledge graph of entities and relationships for multi-hop reasoning, precise entity lookups, and explainable answers.

9 min
Read
RAG
Advanced

Multimodal RAG - Text, Images & Beyond

Pattern #11 - Multimodal RAG - Text, Images & Beyond. Complete implementation with AWS Bedrock, code examples, and performance metrics.

9 min
Read
RAG
Intermediate

Hypothetical Questions - Index by Questions, Not Answers

At index time, generate hypothetical questions each chunk could answer. At query time, match the user query to these questions for dramatically better semantic alignment.

7 min
Read
RAG
Intermediate

Auto-Merging Retrieval - Reconstruct Context from Overlapping Chunks

When enough child chunks from the same parent are retrieved, automatically merge them back into the parent chunk for richer, coherent context.

7 min
Read
RAG
Intermediate

RAG Fusion - Multi-Query Generation with Reciprocal Rank Fusion

Generate multiple query variants from a single question, retrieve for each, then fuse ranked results with RRF to surface the most relevant documents.

7 min
Read
RAG
Advanced

Reliable RAG

The trust-but-verify system β€” adds 3 verification layers: relevance grading, hallucination detection, and source highlighting.

12 min
Read
RAG
Intermediate

Retrieval with Feedback Loop

The learning system β€” collects user feedback after each answer and uses it to improve future retrievals. Gets smarter the more you use it.

10 min
Read
RAG
Intermediate

Relevant Segment Extraction (RSE)

The context reconstructor β€” instead of returning scattered chunks, finds the best contiguous section of the document that answers the query.

10 min
Read
RAG
Advanced

Recursive Summarization - Hierarchical Document Compression

Recursively summarize a document bottom-up β€” chunk summaries β†’ section summaries β†’ document summary β€” creating a compression tree for efficient retrieval at any level.

8 min
Read
RAG
Intermediate

Citation RAG - Grounded Answers with Source Attribution

Force the LLM to cite specific source chunks inline while generating, making every claim verifiable and reducing hallucination by anchoring to retrieved evidence.

7 min
Read