Why the model can't read your documents

2026-12-03来源 dev.toEnglish

Asked how many days a customer has to return a lantern, the model in my series said it had no information about the company's return policy. The policy is in a file it has never seen. Paste that one file into the prompt and it answers correctly, 40 days from delivery, for under a cent. Paste in the whole folder, twelve Markdown files, and it still answers correctly, for nine cents of input on every question. This post is why that does not scale, the way out of it, retrieval, and the way retrieval failed on my own two-page résumé.

Free, step by step: the video series at https://www.youtube.com/@JoelStevick and the site, https://joelstevick.com, with the demo and the book.

Watch the episode: Why it can't read your documents

What a model knows

A model knows what was in its training data: the text it learned from, collected up to a date, its knowledge cutoff. Anything published after that it has not seen, and anything private it never will: your policies, your price list, your orders. When the model answers, it reads nothing except what you send. So the facts have to arrive in the request, and the obvious way to do that is to paste the document in.

The context window

Everything you send counts against the context window: the most the model can read in one call, prompt and answer together, measured in tokens. A token is a piece of text a few characters long; a short word is one token, and numbers and product names split into several. For the model in my series the window is a million tokens, and you pay for every token you send, $2 per million in and $10 per million out. And the model keeps nothing between calls, so whatever it needs for a question, you send again with that question.

Here is the script that pastes a document in. The prompt has three parts: an instruction, the document, and the question. Before it sends anything it counts the prompt's tokens, which is free, so you know the price of a question before you ask it.

const prompt = `Answer the question from the document below. If the document does not answer it, say so. <document> ${readMarkdown(path)} </document> Question: ${question}`; const tokens = await countTokens(prompt); const perQuestion = cost({ input_tokens: tokens, output_tokens: 0 }); console.log(`prompt: ${tokens.toLocaleString()} tokens, $${perQuestion.toFixed(4)} of input`); console.log(); const answer = await ask([{ role: "user", content: prompt }]); console.log(answer.text); 

Given a folder instead of a file, readMarkdown pastes in every Markdown file, each labelled with its name, so the model can say which file an answer came from.

One file, then the folder

One file, returns-policy.md, and the question: 3,720 tokens, $0.0074 of input. The answer is right, 40 days from the delivery date the carrier recorded, and it found the holiday extension too. The whole call, answer included, was $0.0084, and the bill matched the count exactly. The model did not change. The request did.

Then the folder, all twelve files, and a trap question: what is the free shipping threshold. The shipping page and the FAQ say $75; the release notes for a later version of the online store lowered it to $60. The prompt is 45,331 tokens, $0.0907 of input. The model says $60, notices that the release notes are newer than the policy pages, and names two pages that still say $75 as out of date. It could do that because it read everything. The whole call came to $0.0926.

Where it breaks

Nine cents sounds small. But every question pays to read all twelve files again, because nothing is kept between calls. A thousand questions a day is over ninety dollars a day. With ten times the documents it is about ninety cents a question, and every answer waits while the model reads all of it. With thirty times the documents it does not fit in the million-token window at all. The window is the hard limit, and the price becomes a problem long before you reach it. And most of what it read, it did not need. The shipping answer came from a few paragraphs, and the question paid for 45,331 tokens.

Retrieval

The way out is to send only the few paragraphs that matter, which means finding them first. Finding them is retrieval: searching your documents for the passages that answer a question, before the model sees any of them. The model then answers from those passages. That is retrieval-augmented generation, RAG. Retrieval does not make the model smarter. It makes the prompt smaller and puts the right facts in it. It is a search problem, and a search can miss.

When retrieval missed: my résumé

My site has a free demo: upload your PDFs and ask questions about them. I uploaded my own two-page résumé and asked the most obvious question there is, what jobs has he held. It answered that the passages it had did not list my job history. Asked about one employer by name, it answered correctly, from page 2, with dates. The text was there. The broad question never reached it.

My first guess was chunking, the cutting of a document into passages, and it was wrong. The résumé became 9 chunks of about 900 characters, and the seven employers sat in 5 of them, across both pages. Three things lined up. The answer only ever saw 5 chunks, so seven jobs in five chunks plus a summary could never fit. The words of the question matched the wrong chunks: "jobs" and "held" appear in my summary and in a paragraph about outbound calls, not in the headings that name the roles, and keyword search put those first. And the model said the information was absent, which my check let through. The check rejects an answer that cites a passage it was not given or states a figure no cited passage has, and that sentence did neither.

Before changing anything I wrote a test that fails the way the demo did: a fictional two-page résumé with seven jobs, two on page 1 and five on page 2, after a summary full of the question's words, with scripted models that can only list jobs in the passages they are given. On the old code it named five jobs, because the chunk holding the other two never reached the answer. The fix: the answer is now written from up to 12 passages, and the reranker, the model that orders the retrieved passages by relevance, puts them in order instead of cutting them. With the limit set back to 5, the same assertion goes red.

What to try next: at tag s1e4 of the series repository, run src/ask-with-doc.ts against one of your own Markdown files and read the token count it prints before the answer. Then point it at a folder and multiply the count by the questions you get in a day. The next four episodes replace that paste with a search.

First published at joelstevick.com/blog/why-the-model-cant-read-your-documents.

Watch the series: https://www.youtube.com/@JoelStevick. Everything else, the demo and the book included: https://joelstevick.com

原文:https://www.a8q9.cn/en/article/why-the-model-can-t-read-your-documents-8e67a8.html

相关文章