The problem
A language model asked about documents will usually produce an answer, whether or not the documents contain one. For policy questions — leave entitlements, notice periods — a fluent wrong answer is worse than no answer, because it looks authoritative.
Telling the model in the prompt to refuse when it doesn't know helps, but it leaves the decision to the component most likely to be confidently wrong. I wanted the refusal to be made before generation, by code that can be inspected and tested.
Options I considered
Prompt-only refusal: cheap and simple, but every unanswerable question still costs a model call and the refusal is not deterministic.
A single similarity threshold on the best retrieved chunk: deterministic, but embeddings can rate a passage about “annual leave” as close to a question about “jury duty leave”, and short exact-term questions can fall just under the bar.
A gate on similarity with a lexical override: pass the question if the best chunk is semantically close, or if it is reasonably close and literally contains nearly all of the question's content words. That is what Vericore implements.
The implementation
The retriever scores a pool of 25 candidates. Each gets hybrid = min(1, cosine + 0.5 · coverage²), where coverage is the share of the question's content words found in the chunk. The gate runs before anything is generated:
supported = top_cosine >= self.semantic_gate_threshold
if not supported and best_grounded is not None:
override_ok = (
best_grounded["similarity"] >= self.lexical_override_min_cosine
and best_grounded["coverage"] >= self.lexical_override_min_coverage
and best_grounded["matched_terms"] >= self.lexical_override_min_terms
)
if override_ok:
supported = TrueWhat it costs
I measured the design with a port of the same logic over Vericore's sample documents (the playground on this site). Without the gate, 75% of questions the corpus cannot answer still received an answer — “Who is the CEO of NovaTech?” came back as “Welcome to NovaTech.” With the gate that fell to 0%.
The price was 15.4% of answerable questions refused. Every one of them was a paraphrase: “Do I need a doctor's note?” never uses the policy's words “medical certificate”. The port uses lexical similarity rather than MiniLM embeddings, so it is harsher on paraphrases than Vericore itself — but the direction of the trade-off is the point.
A gap I found while writing this
After generation, Vericore keeps only the source ids the model cited that were actually supplied. But if the model cites none of them, main falls back to attaching every supplied source — so an answer with no valid citation is still shown with sources. The port on this site marks such an answer unverified instead.
source_map = {s.chunk_id: s for s in sources}
verified_sources = [source_map[sid] for sid in cited_source_ids if sid in source_map]
if not verified_sources:
verified_sources = sourcesWhat I would do next
Proposal, not implemented: treat an empty verified-source list as an unverified answer in Vericore itself, recalibrate the gate's thresholds whenever the embedding model changes, and add a claim-level check that the quoted passage entails the answer rather than merely sharing an id.