Start learning free

LESSON 57 OF 129 · AI ENGINEERING: RETRIEVAL (RAG)

Why the Model Doesn't Know Your Shop

Practice

A language model has read a great deal of text, but it has never read your shop's documents. Ask it something only your shop knows and it still answers, with what is usual elsewhere, and it sounds sure.

A model can only use what is in the prompt. So when the answer is in a text you have, send that text together with the question. Put it inside a pair of tags, so the model can tell the text from the question:

notes = "Open Monday to Saturday, 9 to 18. Closed on Sunday."
prompt = "<notes>" + notes + "</notes> Are you open on Sunday?"

In this lesson you ask the model the same question twice: first alone, then with the shop's returns policy from docs/returns.md in the prompt. Then you print what the second call cost: every reply reports the tokens the model had to read, in reply.usage.input_tokens. Your program must print:

Without the document: You have 30 days from the date of purchase to return an item for a full refund.
With the document: You have 14 days from delivery to return an item. It must be unused and in its original packaging.
Tokens sent: 182
With 200 documents: 36400

One document is cheap. Hundreds of documents with every question are not, and a few thousand no longer fit in a prompt at all. The way out is retrieval: first find the few pieces of text that fit the question, then send only those. You build it in the next lessons.

Your task: client, MODEL and question are already there. Ask the model the question alone and print "Without the document:" with its answer. Then read docs/returns.md, put its text in the prompt inside <document> tags, ask again and print "With the document:" with the answer. Last, print "Tokens sent:" with the input tokens of the second call, and "With 200 documents:" with that number times 200.


Assignment
Follow the Coding Tutorial to ask the model with and without the shop's returns policy, and to print what sending the document costs.


Hint
The second call is the same as the first. Only the message's content changes, from question to prompt. The token count is in reply.usage.input_tokens.


STEP 1 OF 11
    Ctrl + Enter to check