# A document Q&A demo on one page: a 0.02 threshold margin, and why keyword search was dropped

> A demo page where you paste a document and the AI answers only from it. On a small document the semantic threshold had only a 0.02 margin, and the site's semantic-plus-keyword merge let through questions it should refuse.

- Date: 2026-12-01
- Topics: AI, Privacy
- Chinese original: https://kbs0830.com/blog/private-doc-qa-small-corpus-threshold

A request I hear often from client work is "feed the company's documents to an AI, and the data must not leave the company". I built a scaled-down version on this site: [private document Q&A](/ask/private) (in Chinese). You paste a document, ask one question, and the AI answers only from the document, with the source passages quoted.

The flow is simple: cut the document into passages, use an embedding model to find the 1 to 3 most relevant ones, and give only those to the local Gemma 3 (4B). This post covers the places where, while building it, I did things differently from the site's "ask me" feature, and where I first got it wrong.

## On a small document, the semantic threshold has only 0.02 of room

I used a fictional FAQ for a coffee bean shop (four passages: opening hours, shipping, returns, membership perks), marked the correct answers for 10 questions myself, and measured each question's similarity to the four passages:

- Questions whose answer is in the document: the correct passage scored 0.48 to 0.66.
- Questions not in the document: "Do you sell coffee machines?" topped out at 0.46, the weather at 0.15, and "who is the CEO" at 0.14.

There is only 0.02 of room between the two sides (highest without an answer 0.46, lowest with an answer 0.48), so the threshold has to sit in the middle at 0.47, and the "coffee machine" question misses being let through by just 0.01. That is a result from 10 questions; with a very different document, the boundary could shift entirely. The page and the code comments both say this is the calibration of a demo.

## Why not reuse the "ask me" semantic-plus-keyword merge

The retrieval behind "ask me" is embeddings plus keywords, merging two rankings so that what each misses is covered by the other, and it works well on a few hundred passages of site content. I first just moved it over, then found it was wrong:

The keyword side has a rule: "matching just one uncommon word counts as a hit". On a site with a few hundred passages, "YOLO" and "Ollama" really are rare. But when a document has only four passages, every word appears only a few times, and even "coffee" becomes an "uncommon word". As a result, "Do you sell coffee machines" was let through by the single word "coffee" on the keyword side, and a question that should get a direct "not in the document" instead went to the model to decide.

So document Q&A uses only semantic similarity, and keywords are only a fallback when the embedding service is off.

## When nothing is found, the model is not called

When no passage is selected, the server directly returns one fixed sentence, "No content related to this question was found in the document", without calling the model. There are two benefits: it answers in 0.1 seconds, and the model has no chance to make things up. The screen also says "the model was not called", so people can see this behavior.

## The small model contradicting itself

After the right passage was selected, the first version of the prompt still had a problem: asked "Are you open on Sundays", the model answered "The document does not say; closed on Sundays and national holidays". The passage plainly says closed on Sundays, yet it first said it was not written. The reason is that the question is "are you open or not", and the text has no literal "open".

I added one line to the prompt: "if there is an answer, the first sentence is the answer, and for yes/no questions answer yes or no using the passage". The same question became "Closed on Sundays, so not open", and two re-runs gave the same result.

## What "private" actually means

The page is blunt about it: the document is used only within that one request, is not saved, and is not logged (unlike "ask me", which records questions). After asking, I searched the folder and the logs and found no trace of the document or the question.

But the request does pass through Cloudflare on its way into my desktop, and Cloudflare can technically see that traffic, so the page also says "please do not paste truly confidential content". For real company use, the whole thing would be placed inside the client's own network without Cloudflare in the path: this demo proves the flow and the behavior, not that "putting it on the internet is fully private".

---

Author: PINGWEI LI (李秉威, Li Ping-Wei)
Original page: https://kbs0830.com/en/blog/private-doc-qa-small-corpus-threshold
