Tutorials
Hands-on, step-by-step builds: you finish each one with working code and know why every step is there
All Tutorials
How to Cut AI Agent Cost: Prompt Caching and Model Routing
Build a Python support-ticket triage agent on the Claude API, and measure caching, structured outputs, and a Haiku-to-Sonnet cascade at about a third of Sonnet-only cost.
Claude Code Stop Hook with Hypothesis Property Tests
Give Claude Code a verifier: Hypothesis property tests for a RAG chunker, wired into hooks so the agent cannot stop while a property fails, or edit the properties to make them pass.
How to Reduce Claude Code Token Usage: A Measured Setup
Shrink what Claude Code re-reads on every turn, stop tool output from flooding the context, and prove the saving with real numbers.
Building ChatGPT-Style Streaming in React: FastAPI + Next.js Production Guide
Cancel-on-disconnect misses the drops that cost money, and resumable streams bill every closed tab. Bind the generation to a presence lease instead.
Contract Tests for a LangGraph Agent: Test the Property, Not the Setting
Build a pytest suite that checks fan-out width, merge order, spend across resumes, and spend after a crash - and watch a setting-shaped fix fail each one.
How to Build a Claude Code Agent Loop That Cannot Run Away
Build a loop that reruns every failing test before it touches code, fixes only the failures that reproduce, and is stopped by a hook its own instructions cannot override.
MCP with LangGraph: A Practical 2026 Walkthrough
Your checkpoint is durable. The handle inside it is not. Nothing in either system compares the two.
Build a Kill Switch for a LangGraph Agent
Four independent mechanisms - a tool-call interceptor, a watchdog, an anomaly detector, and a manual override - that stop it even when it will not stop itself.
How SynthID Works: Build a Watermark in Python
Build the green-list watermark on GPT-2 and detect it from text alone at p = 3.07e-56. Then find out how few tokens it needs and how much editing it survives.
Superpowers Plugin for Claude Code: Install and Verify
Install it, prove which skills actually fire, and measure what it costs you - then switch it off where it does not belong.
BM25 vs Dense Retrieval: Measure It on Your Own Corpus
Build a bake-off harness that runs BM25, dense, hybrid, and reranked retrieval over a labelled query set - and tells you with Recall@k, nDCG, and cost per query which one your RAG system actually needs.
How to Rerank Retrieval Results with a Cross-Encoder
Build a two-stage search pipeline and measure the reranking gain yourself, in NDCG@10, on your own machine.
Building a Production MCP Server: Architecture, Pitfalls, and Best Practices
The four-layer architecture that survives an adversarial LLM client, rewritten for the stateless spec.
Claude Code Guide: Build Agentic Workflows with Commands, MCP, and Subagents
*A practical guide to using Claude Code as a programmable agent with commands, skills, memory, hooks, and MCP.* Most developers try Claude Code once, get med...
Building an MCP Server for Non-LLM Clients (CLIs, IDEs, Pipelines)
## The Problem: Context Access Is Locked Behind LLM Abstractions You've built an MCP server that provides rich context from your organization's systems—code ...
How to Build a Hybrid Search Service with BM25 and Docker
Fuse BM25 with dense retrieval, tune the fusion weight on real relevance judgments, and ship the whole thing as a container that shows you every stage's score.
Building Privacy-Preserving Machine Learning Applications in Python with Homomorphic Encryption
Data privacy is one of the biggest challenges in deploying AI systems. From healthcare to finance, sensitive datasets are often required to train or run machine...
Provenance in AI: Building a Provenance Graph with Neo4j – Part 3
In [Part 2](https://ranjankumar.in/provenance-in-ai-tracking-ai-lineage-with-signed-provenance-logs-in-python-part-2/), we built a `ProvenanceTracker` that gene...
Prompt Engineering Tutorial 2026: Prove Which Prompts Work
Build promptlab, a local Python harness that measures whether a prompt change helped, then use it to reproduce the prompting effects that still hold and the four that stopped.
LLM Text Clustering and Topic Modeling: HDBSCAN and BERTopic Tutorial
Cluster documents by meaning with sentence-transformer embeddings, UMAP and HDBSCAN, then turn clusters into labelled topics with BERTopic and an LLM. Updated for BERTopic's client-based OpenAI API and current model IDs.
Hands-on Tutorial on Making an Audio Bot using LLM, and RAG
Build an offline audio bot that answers questions from your own PDFs: Llama 3.2 via Ollama, a Qdrant + FastEmbed RAG pipeline, faster-whisper speech-to-text and pyttsx3 text-to-speech. Updated for qdrant-client 1.19 and LangChain 1.x.
How to Fine-Tune a Cross-Encoder for Semantic Similarity
Train a distilroberta cross-encoder on STS-B with the Sentence Transformers trainer, on a plain CPU, and use it to score sentence pairs and rerank search results.
Install Ollama and Run Llama 3.2 Locally: Python, LangChain
Install Ollama, run Llama 3.2 on your own machine, and call it from the terminal, a browser sidebar, plain HTTP, the official Python client and LangChain - then reach it from another machine without exposing it to the internet.
How to Record, Save and Play Audio in Python
Build a working voice recorder in about twenty minutes, on a stack that still installs on current Python.