Free & open · no paywall, ever

IntegrAuth Academy

Identity, security and practical AI — free, from zero. Byte-sized lessons, real diagrams, hands-on labs, zero fluff. Two programs, each with its own exam and certificate.

20 tracks 241 lessons 242 hands-on labs 230+ diagrams 100% free

English is hard? Your browser can translate this page into Tamil, Telugu, Kannada, Malayalam or Hindi. Tech words stay in English so you learn the real names.

How?
  • Chrome on phone: ⋮ menu → Translate
  • Chrome on computer: right-click → Translate to …
  • Edge: the translate icon in the address bar
Practical AI Track 5 · Building with AI
0/75 lessons read
BUILDING WITH AI · LESSON 3

Build retrieval that works

Priya's bot said the Bengaluru hotel limit was ₹4,500. The policy says ₹7,000. The right text never reached the AI. Your goal: make search find the right text, and prove it.

🧪 Interactive lab — enable JavaScript to play with this one.

Indexing — ahead of time, and again when documents changeQuery time — on every questionDocumentsParsetext + structureChunk+ header + metadataTwo indexeskeyword (BM25)vector (embeddings)QuestionFiltermetadata, accessSearchboth indexesFuseby rank (RRF)Rerankshortlist → top kModelanswers, cites [c7]measure recall@k here,before the model writes anythingboth indexes are searched
Figure — Two pipelines, one job. Most quality is set before the AI writes.
Key points
  • A wrong answer is often a search problem, not a model problem.
  • Cut at headings. Label each piece with where it came from.
  • Remove what this user may not read before any ranking.
  • Measure how often search finds the right text.

Two pipelines

Think of a coaching centre's help desk. A clerk finds the right page in the fee file, and the teacher answers only from it. Wrong page, wrong answer. In RAG (Search by meaning), search is the clerk. It takes two pipelines. The first runs ahead of time. It cuts each document into pieces, called chunks. Each chunk is stored with its source and who may read it.

The second runs on every question. It finds the best few chunks and sends them to the AI, each with an ID to cite.

Cut and search well

Cut at headings, not every 500 characters. Add a header to each chunk, like "Travel policy › Hotels". Now a chunk about metro cities says it is about hotels.

Fixed sizeFixed size + overlapStructure-aware + header…150 euros per night. In capital cities the cap risesto 200 euros. Event venues may be booked at……150 euros per night. In capital cities the cap risesIn capital cities the cap rises to 200 euros. Event…Travel policy › Hotels: In capital cities the cap rises to 200 euros. Event venues may be booked…✗ the fact is cut in two: neither chunk holds it✓ the edge is repeated, so one chunk holds the whole sentence
Figure — Where you cut decides what can be found.

Meaning search can miss exact codes, like CC-4410. So add keyword search, like BM25. Using both is hybrid search. A reranker can then reorder the best matches.

Measure it

Collect real questions and mark the text that answers each. This is your golden set. How often is that text in the top few results? That share is recall@k. The AI can't use text it never saw. Measure search first.

Search ignores who is asking. Order the steps safely.

🧪 Interactive lab — enable JavaScript to play with this one.

Go deeper: reading files and chunk size

A PDF stores letters at positions, not paragraphs. A careless reader can merge two columns. It can lose a table's column names. Open-source tools like Apache Tika, Unstructured and Docling help. As of October 2026, none is perfect on every layout. So read the text of some real documents first.

Size is a trade-off. Small chunks are precise but lose context. Big chunks keep context but mix topics and cost more tokens. Overlap repeats the end of one chunk in the next. It saves facts cut at the edge. Start with a middle size, then measure.

Some teams have a model write a short note for each chunk. The note says where the chunk fits in the document. Anthropic calls this "contextual retrieval".

Go deeper: how the scores work

BM25 counts a rare word, like CC-4410, much more than a common one, like "policy". But it doesn't know words with the same meaning.

The two searches give scores on different scales. So hybrid search merges by rank, not score. A common method is reciprocal rank fusion, or RRF. Each list gives a chunk 1 ÷ (60 + its rank). Add the parts up. A chunk ranked 2nd in both lists gets 1/62 + 1/62 ≈ 0.032. A chunk ranked 1st in one list only gets 1/61 ≈ 0.016. Chunks both searches agree on win.

Go deeper: reranking, top k and citations

A reranker reads the question and one chunk together. It is more accurate, but too slow for everything. So search wide, rerank the short list, and keep the best few. A reranker adds time and cost. Measure whether it helps.

The number of chunks the AI gets is called k. A bigger k makes it more likely the right chunk is in. But it costs tokens and can bury the answer. Models use the middle of a long prompt less well.

Send each chunk with an ID and its source. Tell the AI to cite IDs. Tell it to say when the sources don't answer. Then check in code that each cited ID is one you sent.

Go deeper: find which half is broken

Priya wrote 40 test questions from real chats. Her first setup found the right text in the top 5 for 26 of them. Cutting at headings, with a header, fixed the capital-cities miss. Adding BM25 found CC-4410. Now it scores 38 of 40. The 2 misses are real gaps in the policy.

What if the right text is in the top k, and the answer is still wrong? Then search did its job. Look at the prompt or the model next. So run the set after every change.

Go deeper: keep it fresh, or skip it

An index is a copy, and copies get old. Index a document again when it changes. Delete the chunks of old documents. A new embedding model means embedding everything again. Who may read a document can change too. So check it at question time.

Sometimes you don't need RAG. In 2024, Anthropic suggested that a knowledge base under about 200,000 tokens can go straight into the prompt. That is about 500 pages. Agentic search often works better for code and fast-changing files.

Watch out

A document can hide orders for the AI. This is prompt injection. Treat found text as data, never as orders.

🧪 Try it free

Paste 10 numbered paragraphs into an AI assistant. Ask questions and add "cite the paragraph number". Check each citation.