Indu Learning Platform
Course/Unit 5 · AI foundations
Lesson 5-3

Embeddings and RAG

How embeddings capture meaning, and how retrieval-augmented generation lets a model answer from your own project documents.

Watch firstWhat is Retrieval-Augmented Generation (RAG)? · IBM TechnologyOpen on YouTube ↗

The problem RAG solves

Your specs, IMG notes and tickets are unknown to the model and far too big to paste into every prompt. Retrieval-augmented generation (RAG) first retrieves the few most relevant passages, then generates an answer from only those, with citations. The model's job shifts from remembering to reading, which it does well.

Embeddings: meaning as numbers

An embedding is a vector of numbers that an embedding model produces from text. Similar meanings get vectors pointing in similar directions: 'supplier blocked for payment' lands near 'vendor payment block'. Cosine similarity (-1 to 1) measures that closeness; near 1 means same topic. It measures meaning, not correctness.

vendor payment block0.89supplier posting block incompany code0.78BP central block flag0.66customer credit limit check0.41material valuation class0.12
Illustrative similarity to 'supplier blocked for payment'. Real values depend on the model.

Offline: indexing your documents

Specs, IMG notes,ticketssourcesChunk~300–800 tokensEmbedvectorsVector store+ metadata
Done once, refreshed whenever documents change.

Online: following one question

Step through · 1 of 7
Questionuser asksEmbed questionvectorRetrieve top-ksimilarity searchFilter & rerankmetadataBuild promptchunks + questionGenerateLLMAnswer + sourcescitations
A data steward asks: 'Which CR type do we use to block a supplier for payment in company code 1000?'
One RAG query, from question to cited answer.

Try it: build the pipeline

Try it · Put in order

Put the full RAG pipeline in order, from raw documents to a cited answer.

  1. 1Embed each chunk
  2. 2Store vectors with metadata
  3. 3Split specs and tickets into chunks
  4. 4Embed the user's question with the same model
  5. 5Retrieve the top-k most similar chunks
  6. 6Put the chunks and question into the prompt
  7. 7Generate an answer that cites its sources

Chunking and metadata decide quality

Chunks must be small enough to retrieve precisely, big enough to make sense alone. Split along the document's own structure, with a small overlap so rules are not cut in half. Tag each chunk with metadata (doc ID, section, object, release, status) to filter and cite.

Document typeChunking strategyFunctional specBRFplus rule exportIMG / config notesDefect ticketsSteward handbookSplit by headingOne rule per chunkOne activity per chunkOne ticket per chunkSplit by procedurekeep section titleinclude rule IDkeep IMG pathsummary + resolutionstep order intact
Chunk along the structure the authors already used.

When RAG answers badly

Check the retrieved chunks first. If the right passage is missing, it is a retrieval problem: fix chunking, search or metadata. If it was retrieved and the answer is still wrong, it is a generation problem: tighten the prompt, require citations, or use a stronger model.

Python
import numpy as np

def cosine(a, b):
    a, b = np.array(a), np.array(b)
    return float(a @ b / (np.linalg.norm(a) * np.linalg.norm(b)))

# embed() = your platform's embedding API; chunks are embedded once, offline
chunks = [
    {"id": "FS-BP-017 4.2", "text": "Payment block for suppliers is set via CR type ZSUP_BLK ..."},
    {"id": "TCK-2231",      "text": "Supplier posting block not replicated to ECC via DRF ..."},
]
for c in chunks:
    c["vec"] = embed(c["text"])
q = embed("How do we block a supplier for payment?")
top = sorted(chunks, key=lambda c: cosine(q, c["vec"]), reverse=True)[:2]

Real systems use a vector database, but the logic is the same.

Try it: retrieval or generation?

Try it · Sort

A RAG assistant gave a bad answer. Where is the problem?

Retrieval problem
Generation problem
Click an item, then a bucket (or drag it).

Try it: the outdated answer

Try it · What would you do?

Your spec assistant confidently quotes the 2023 rule for supplier group ZINT payment terms. The 2025 spec changed it, and both versions are in the index. What do you do?

Remember

  • RAG = retrieve relevant passages from your documents, then answer from them with citations.
  • Embeddings capture meaning; chunking, metadata and hybrid search decide retrieval quality.
  • Debug retrieval first, generation second, and filter by access rights.

Check yourself

What is the main benefit of RAG on project documents?
A RAG assistant answers wrongly. The right spec passage was not among the retrieved chunks. Where do you fix it?
Why might pure embedding search struggle with 'CREMAS05 segment E1LFA1M'?
Two chunks have cosine similarity 0.92 with a question. What does that indicate?