Say "I Don't Know"
An assistant that answers from documents is only trustworthy if it also says so when the documents hold no answer. That does not happen by itself: a language model tends to produce an answer whatever it is given, and a vector search always finds some passages, however unrelated. This page explains why both happen and how two checks, one in the instructions to the model and one on the search distance before the model is called, let the assistant decline honestly.
Why a model answers anyway
A language model learns first by predicting the next word in a huge amount of text. That text carries no labels saying which statements are true; the model only sees fluent language and learns what fluent language looks like. Later training stages teach it to answer questions. The way those answers are usually scored rewards a guess over silence. OpenAI compares it to a multiple-choice test: a wild guess might be right, while a blank answer always scores zero. So when a model shaped this way is asked something it cannot know, it writes the most plausible answer it can instead of saying it does not know. Such a confident, plausible but false answer is called a hallucination.
Putting retrieved passages in the prompt helps when they contain the answer. When they do not, it can make things worse. Suppose someone asks how many days of leave contractors get, and the search returns passages about leave for employees. Those passages are clearly relevant to the question, but they are not sufficient to answer it: nothing in them is about contractors. A study by Google Research found that models given such insufficient context often answer wrongly instead of declining, and that adding context made them more confident, not more careful. For one model, wrong answers rose from 10.2% of questions with no context to 66.1% with insufficient context.
- Passages about employee leave
- model
The invented answer above is not a glitch that happens rarely. It is what the model was trained to do, so an assistant that should decline has to be built to decline.
True or false?
Once a model is given passages to answer from, it can no longer invent an answer.
False. When the passages are related but do not contain the answer, models often still answer, and the related text can make them more confident in a wrong answer.
A passage can be about the same topic as a question and still not answer it.
True. Passages about leave for employees are on the topic of a question about leave for contractors, but they say nothing about contractors.
Instructions that allow "I don't know"
The first check lives in the instructions sent with every question. They do two things. They restrict the answer to the passages, telling the model not to use what it learned in training. And they give the model an explicit, exact reply for when the passages do not contain the answer, so declining becomes one of the allowed answers instead of a blank on the test. The provider guides recommend both: Anthropic's advice to reduce hallucinations starts with giving the model explicit permission to say it does not know, and OpenAI's question-answering example ends its instruction with If the answer cannot be found, write "I don't know."
Answer the question using only the passages below.
Do not use anything you know from elsewhere.
If the passages do not contain the answer, reply exactly:
I don't know based on the documents.The reply is fixed word for word on purpose. A program can compare the model's reply with that sentence and know that the model declined, then show the reader a clear message instead of an answer with sources.
Instructions lower the rate of invented answers, but they do not bring it to zero. A model can still miss that the passages are insufficient, especially when they are close to the topic. That is why the instruction is one of two checks, and the other runs before the model is ever called.
True or false?
An instruction to answer only from the passages guarantees the model never invents an answer.
False. Such instructions reduce invented answers a lot, but the providers that recommend them say plainly that they do not remove them entirely.
Asking for an exact decline sentence makes it possible for code to recognise that the model declined.
True. A fixed sentence can be compared with the reply; a refusal worded differently each time could not be detected reliably.
A search always returns rows
It is tempting to think that if the search found passages, the documents must hold an answer. A nearest-neighbour search does not work that way. It orders every row by its distance to the question's embedding and keeps the first k. Nothing in it asks whether the nearest row is actually near.
SELECT id, content, embedding <=> %s AS distance
FROM chunks
ORDER BY distance
LIMIT 3;In PostgreSQL, LIMIT 3 returns no more than three rows, and fewer only when the query itself yields fewer. So on any table with at least three chunks, this query returns three rows for every question. Exact search, comparing the question with every row, always finds the true nearest rows, near or far. A question about pizza toppings, asked of a company handbook, still gets the three chunks that happen to be least far from it.
What differs is the distance. <=> is pgvector's cosine distance operator, one minus cosine similarity, so smaller means closer in meaning. Cosine similarity runs from -1 to 1, which puts cosine distance between 0 and 2. The illustrative numbers below show the pattern: both questions get three rows, but only one gets rows that are close.
| Question | Nearest | 2nd | 3rd |
|---|---|---|---|
| How many vacation days do employees get? | 0.21 | 0.34 | 0.40 |
| What is the best pizza topping? | 0.71 | 0.74 | 0.78 |
True or false?
A query with ORDER BY distance LIMIT 5 can return zero rows when nothing in the table is related to the question.
False. It returns five rows whenever the table holds at least five, however far away they are. Relatedness never enters the query.
With pgvector's cosine distance operator, a smaller value means a closer match.
True. Cosine distance is one minus cosine similarity, so identical directions give 0 and the value grows as meanings drift apart.
Declining before the model is called
The distance of the nearest row is the evidence that getting rows alone cannot give. Choose a distance beyond which a passage counts as too far: the threshold. If even the closest passage is farther from the question than the threshold, no passage is close enough to hold an answer. The program can then decline at once, without calling the model at all. That saves the cost and waiting time of a model call, and it removes the chance of an invented answer, because the model never sees the question.
- Question
- Nearest k chunks
- Nearest distance > threshold?
- Decline no model call
- Call the model instructions allow declining
- Answer or decline
- Question to Nearest k chunks
- Nearest k chunks to Nearest distance > threshold?
- Nearest distance > threshold? to Decline: yes
- Nearest distance > threshold? to Call the model: no
- Call the model to Answer or decline
Only the nearest row matters for this test: if the closest one is too far, the others are farther still. Since the query returns rows already ordered by distance, the check is one comparison in Python. The threshold is an upper bound on distance, so the program declines when the nearest distance is greater than it.
DECLINE = "I don't know based on the documents."
def answer(question, rows, threshold):
# rows come back ordered by distance, nearest first
if not rows or rows[0]["distance"] > threshold:
return DECLINE
return ask_model(question, rows)Passing the check does not prove an answer exists. A passage can be close to the question and still not contain the answer, as with the employee leave passages for a question about contractors. The threshold catches questions that are far from every document; the instruction to the model catches the close but insufficient case. The assistant needs both.
True or false?
When the nearest passage is closer than the threshold, the documents are sure to contain the answer.
False. Close means related, not sufficient. That case is left to the model, whose instructions still allow it to decline.
If the nearest of the k rows is farther than the threshold, every other row is farther too.
True. The rows are ordered by distance, so checking the first one is enough.
Choosing the threshold
There is no standard threshold to copy. Distances depend on the embedding model: the same pair of sentences gets different scores from different models, and a value measured for one model means nothing for another. Numbers found online, such as 0.75, are often cosine similarities used for clustering, not distances used for retrieval. The threshold has to be measured with the model and documents it will be used with.
The measurement is small. Write a handful of questions the documents do answer and a handful they do not, and include a few hard ones on both sides: an answerable question worded very differently from its passage, an unanswerable one close to a real topic. Run the search for each and note the distance of its nearest row. Then place the two groups on one line and look where they separate.
- 0
- 0.5
- 1.0
- distance of the nearest passage (illustrative)
- questions the documents answer
- questions with no answer
- threshold
Answerable questions tend to sit at small distances and unanswerable ones at larger distances, so a threshold between the two groups declines the second without touching the first. Where exactly it goes is a trade between two mistakes:
| Threshold | What passes | The mistake it risks |
|---|---|---|
| Too high (loose) | Almost every question reaches the model | Answering without support: a question with no answer gets an invented one |
| Too low (strict) | Only very close matches reach the model | Refusing a question the documents do answer, because its best passage is a little farther away |
Often the groups overlap, as in the picture: a hard answerable question lies a little beyond the nearest unanswerable one, and no threshold gets every question right. Then the choice depends on which mistake costs more. For a handbook that people act on, an unsupported answer is usually worse than a refusal, because a refusal sends the reader to a person while a wrong answer is believed. A threshold set a little loose, with the model's own instruction to decline behind it, is a common compromise: the threshold removes the far-off questions, and the instruction handles the ones that slip through.
Keep the test questions. When the documents change or the embedding model is replaced, run them again and see whether the groups still separate where the threshold says they do.
True or false?
A threshold measured with one embedding model can be reused unchanged after switching to another model.
False. Each model places texts differently, so distances shift; the test questions have to be measured again.
Lowering the threshold makes the assistant refuse more questions that its documents could have answered.
True. A stricter threshold also cuts off answerable questions whose best passage is not very close, trading unsupported answers for refusals.
With enough care, a threshold can always be placed so that no answerable question is refused and no unanswerable one gets through.
False. When the two groups overlap, every threshold makes at least one of the two mistakes; the instruction to the model remains the second check.