RAG from first principles: embeddings, vector databases, chunking, and a lab copilot behind BIG-IP

RAG built from first principles and run for real: keyword search, embeddings and cosine similarity by hand, vector databases, chunking, a grounded prompt, and a RAG app behind a BIG-IP with monitors, least connections, caching and failure handling.
Hand-drawn RAG stack: your documents, retrieve, augment, generate, with the title 'RAG from first principles, behind a BIG-IP'

On this page

This post goes with a hands-on video on the LevelUP I.T. YouTube channel. It builds retrieval augmented generation (RAG) from first principles and then runs it for real: a "lab copilot" that answers questions about the F5 series' own lab guides, deployed as three replicas behind a BIG-IP virtual server, with a health monitor, least-connections load balancing, caching and failure handling. Every script below is the exact code typed in the video's labs, and every result quoted is what it printed.

The whole system in one picture

A RAG system has two halves that run at different times. Ingestion runs before anyone asks anything, and again when documents change: load the documents, clean them, split them into chunks, embed every chunk into a vector, store the vectors in an index. The query path runs for every question: embed the question with the same model, find the nearest chunks, put them into a prompt with the question, let the language model generate the answer, return it with its sources.

RAG end to end: ingestion offline, the query path online, a grounded prompt
RAG end to end: ingestion offline, the query path online, a grounded prompt

What you'll find here

  • RAG in one picture, and when prompt engineering or fine-tuning is the better tool.
  • Keyword search: grep, TF-IDF and BM25, with the arithmetic, and lab 1.
  • Embeddings, contrastive training, task prefixes, and the dot product and cosine similarity by hand, with lab 2.
  • Vector databases: brute force, HNSW and IVF, memory sizing, and lab 3 with Chroma.
  • Chunking: the truncation problem, overlap, recursive splitting, metadata, and lab 4.
  • The complete pipeline and the grounded prompt, lab 5.
  • Deploying it behind a BIG-IP: monitor, pool, least connections, the request path, lab 6.
  • Caching, monitoring and error handling, measured on the lab; and what production adds.

This post is for paying subscribers only

Subscribe to LevelUp I.T. newsletter and stay updated.

Don't miss anything. Get all the latest posts delivered straight to your inbox. It's free!
Great! Check your inbox and click the link to confirm your subscription.
Error! Please enter a valid email address!