Dayward AIWeChat Mini Program
RAG in 14 Days: From Retrieval to Trustworthy Answers
Week 1 · D6🔒 LockedAbout 5 hours

The Generation Side: Ordering Context, Labeling Citations, When You Must Refuse to Answer, and Streaming Responses

Once retrieval brings back a pile of chunks, what actually decides the user experience is how you assemble them, how you get the model to cite its sources, and how it stays quiet when the evidence is thin. Today write a question-answering endpoint with verifiable citations and a refusal policy, and stream the answer.

Today's goals 0/3

Sign in to tick these off and save your progress.

Today's Goals

  1. Design a prompt structure that makes the model answer only from the given material and cite sources by chunk number
  2. Implement post-hoc citation verification that catches sources the model fabricated before they reach the user
  3. Explain the two triggers for refusing to answer — too-low retrieval scores and contradicting materials — and write a handling strategy for each

Five days were about fetching material. Today turns around and covers only what happens after it arrives — write this side badly and not one bit of those five days' work survives. Once you have read this and finished the lab, scroll back to the top and tick off the three goals.

Plain-Language Walkthrough

The chain of evidence in court

A courtroom has a rule: counsel may not state facts from memory. Saying "this contract was signed on the twelfth of March," they are not believed for sounding certain; the judge asks which exhibit and which page. Counsel gives the number, reads that line aloud, the clerk verifies it, and only then does the sentence enter the record. The point is not whether counsel is honest but that every sentence has a chain that can be independently checked.

Now map the roles. The model is counsel, the retrieved chunks are exhibits, and your server code is the clerk verifying the numbers. The first five days were evidence gathering: finding the material completely and accurately. Today is courtroom procedure: how material is laid on the table, how conclusions are attributed, how the clerk verifies, and what happens when verification fails.

One premise must be accepted first: the citations a model produces are untrustworthy by default. It is not lying but doing what it always does — predicting what the next stretch of text most likely looks like. A conclusion followed by a bracketed number is a pattern it has seen ten million times, so it writes them very naturally and very convincingly. Inventing a nonexistent id and inventing a nonexistent API parameter are the same behavior.

So today's real watershed is this sentence: a citation's credibility cannot come from the model's conscientiousness and can only come from the code's after-the-fact verification. Writing "please make sure the citations are accurate" ten times in the prompt gains nearly nothing; adding twenty lines of verification in code lets not one fabricated citation out. That judgment shapes every design that follows.

D1 left two shortcomings, and the second is repaid today: the corpus has two documents on the file upload limit, one saying 200 MB and one saying 100 MB, retrieval fetches them together, and faced with two clashing numbers the model's default behavior is to pick the more plausible one and state it with the same confidence. Courtroom procedure exists exactly for that moment.

Sign in and link WeChat to read

Sign in, then link your WeChat mini program account on the account page. Linked accounts share one free article per day. Unlock additional articles with rewarded videos in the mini program.

Mini program QR code

Scan in WeChat to open Dayward AI. Open the same course and chapter, choose the rewarded video, then refresh this page after completion.

Interview questions

  • How do you make sure a model's citations are real rather than fabricated? Describe a scheme that does not rely on the model behaving well.怎么让模型的引用是真的而不是编的?说出一个不依赖模型自觉的方案。
    Common in ChinaCommon overseasIntermediate#citation-verification#grounding#hallucination

    🔒 Unlock this chapter to see the answer keys.

  • Does the ordering of retrieved passages in the context affect answer quality? If so, how would you order them?上下文里材料的排列顺序会影响回答质量吗?如果会,你会怎么排?
    Common in ChinaCommon overseasBasic#context-assembly#prompt-engineering#ordering

    🔒 Unlock this chapter to see the answer keys.

  • How do you set the refusal threshold for a knowledge-base assistant, and what does it cost you when the threshold is too high or too low?知识库问答的拒答阈值怎么定?定高了和定低了各自的代价是什么?
    Common in ChinaCommon overseasDeep dive#refusal#thresholds#evaluation

    🔒 Unlock this chapter to see the answer keys.

  • In a streaming setup, how do you make sure nothing you have already sent needs to be retracted because its citation failed verification?流式输出的场景下,你怎么保证吐出去的内容不会因为引用校验失败而需要撤回?
    Common in ChinaCommon overseasDeep dive#streaming#citation-verification#api-design

    🔒 Unlock this chapter to see the answer keys.

Comments