Answers from client documents
Why not paste everything?
Northstar has fee sheets, course pages and policies: about 120 pages. You could paste all of it into every model call.
But that's expensive, slow, and the model can miss the one line that matters.
Instead, for each question, find the few pieces that answer it, and send only those. This is called retrieval-augmented generation, or RAG: retrieve first, then generate the reply.
First, the documents need cutting up.
Cut documents into chunks
You can only send pieces if the documents are cut into pieces. Each piece is a chunk.
Too big, and each chunk carries lots of text that doesn't matter. Too small, and a chunk loses what it's about.
Neighbouring chunks often share a few words, called overlap, so an idea split at a boundary isn't lost.
How do you find the right chunk for a question?
Meaning as numbers
Searching for exact words fails: a parent types "mern course fees", and the page says "Full Stack Web Development".
So a model turns every chunk into a list of numbers that captures its meaning, called an embedding. Texts that mean similar things get similar numbers, so they sit close together.
Real embeddings have hundreds of numbers. Here, just two, so you can see them on a map.
"Close" needs a number.
Score the matches
To measure how close two embeddings are, multiply their numbers pair by pair and add them up:
score = a₁ × b₁ + a₂ × b₂
For embeddings of length 1, as most are, this is called cosine similarity. Higher means closer. You give the model the top few chunks.
Your turn to score.
✏️ Practice 5.1
score = a₁ × b₁ + a₂ × b₂
Higher score = closer meaning.
Answer only from what was found
Finding the right chunks isn't enough. The model must answer only from them, and say so when they don't contain the answer.
So the rules say: use only these pieces, and if the answer isn't there, say you don't know and offer a counsellor. Answering only from given sources is called grounding.
What if the documents themselves are wrong?
Bad documents, bad answers
Remember the two fee sheets? Both get cut into chunks, and both match "fees for full stack". The model gets ₹1,35,000 and ₹1,45,000.
No prompt fixes that. Fix it at the source: decide which document is the truth, and keep labels on each chunk, like its date and owner. Labels like these are called metadata.
Time to count some chunks.
✏️ Practice 5.2
With chunk size c words and overlap o, each new chunk starts c − o words after the last one:
chunks = (words − o) ÷ (c − o), rounded up
Do it for real
Now build it on Northstar's own course pages and policies. In the notebook you'll cut them into chunks, turn the chunks into embeddings, and search them.
Then you'll make the agent answer only from what it found, catch the old fee list, and measure how often your search finds the right page.
Colab runs Python in your browser for free. The embeddings model is free too, and needs no key. About 45 minutes.
Then check what stuck.
Lesson test
Five questions, all on new examples.