Home>Blog>Engineering
Engineering

AI Answers Explained: How AI Answer Engines Work, Why They Hallucinate, and How to Build One That Doesn't

ER
Elena Rostova
Published on August 4, 202613 min read
Share this article:

TL;DR / Quick Summary: Every ai answer produced by a modern system is the output of a pipeline: embed the question, retrieve semantically similar passages, assemble a bounded context, and generate strictly from it. When any step is skipped or fails silently, the model fills the gap with fluent invention. This is the technical breakdown of how answer engines work, where they break, and what to measure to keep them honest.

AI Answers Engine Architecture — CustomerGPT

Search engines give you links; ai answer engines give you the answer. That shift is small in the interface and large in the engineering, because the moment a system commits to a single response, it also owns being wrong.

The 4-Step Pipeline Behind Every AI Answer

Behind the chat box sits an architecture whose job is to turn unstructured documents into a bounded, checkable context for the model.

Figure 1 — Question to grounded answer
  1. 1Embed the questionThe query becomes a high-dimensional vector using the same model that embedded your documents.
  2. 2Retrieve by meaningThe vector store returns the closest passages by cosine distance, filtered to the right tenant and collection.
  3. 3Build the contextTop-ranked passages are assembled into a bounded prompt region, labelled as source material.
  4. 4Generate under constraintThe model answers from that context only, and declines when the context does not contain the answer.
Each step can fail independently. Step two failing quietly is what most people experience as hallucination.
// A minimal RAG query pipeline
const queryVector = await embeddings.create({ input: userQuestion });

const relevantDocs = await vectorDb.query({
  vector: queryVector,
  topK: 5,
  similarityThreshold: 0.82,
});

if (relevantDocs.length === 0) {
  return "I could not find this in the documentation.";
}

const response = await llm.generate({
  systemPrompt: [
    'Answer ONLY using the provided facts.',
    'Cite the source of each claim.',
    "If the facts are insufficient, say you cannot find the information.",
  ].join('\n'),
  context: relevantDocs.map((d) => d.text).join('\n\n'),
  userQuery: userQuestion,
});

The threshold and the empty-result branch are the two lines that separate a grounded answer engine from a confident guesser.

Why AI Answers Hallucinate

“Hallucination” bundles together several distinct failures with different fixes. Separating them is the first step to fixing any of them.

FailureWhat it looks likeActual causeFix
Empty-retrieval inventionFluent answer about a feature you do not haveNo relevant passages, generation ran anywaySimilarity floor plus a refusal path
Stale groundingCorrect citation, outdated numberIndex behind the published sourceEvent-driven re-indexing
Chunk-boundary errorHalf a procedure, presented as the wholeFixed-size splitting cut through a sectionHeading-aware chunking with overlap
ConflationTwo plans' limits merged into one answerNear-identical chunks, no disambiguationHeading path in the chunk, reranking
Citation driftRight answer, wrong linkCitations attached after generationBind citations to the passages actually used

The pattern is worth stating plainly: most hallucinations in a retrieval system are retrieval problems. Rewriting the system prompt is the cheapest thing to try and the least likely to help.

What Grounding Does and Does Not Fix

  • It fixes invented product facts, wrong pricing, imaginary API parameters, and answers about competitors you never documented.
  • It does not fix a corpus that is wrong, contradictory or out of date — grounding faithfully reproduces bad documentation.
  • It does not fix ambiguity. If two plans both have a “limit” section, retrieval needs help distinguishing them.
  • It does not fix questions with no documented answer. What it does is make refusing them possible.

Retrieval Quality Is the Whole Ballgame

Four adjustments account for most of the difference between an answer engine people trust and one they stop using.

  1. Chunk on structure. Split along headings so a retrieved passage is a complete thought, and prefix the heading path so the embedding carries context.
  2. Combine keyword and vector search. Pure semantic search is weak on exact identifiers — error codes, SKUs, flag names — where lexical matching is exactly right.
  3. Rerank the shortlist. Retrieve twenty candidates cheaply, then use a cross-encoder to pick the best five. This is usually the single biggest quality gain per unit of effort.
  4. Set a floor and honour it. Below the similarity threshold, refuse. An assistant that says “I cannot find that” keeps its credibility for the answers it does give.

Citations Are the Part Users Actually Check

A citation is not decoration; it is the mechanism by which a reader can verify you without asking a human. It has to point at the passage that produced the claim, not at the document that happened to rank first.

Figure 2 — A grounded answer
Answer engineonline

What is the rate limit on the search endpoint?

600 requests per minute per API key on Scale, and 60 on Starter. Bursts above the limit return 429 with a Retry-After header.

api/rate-limitsplans/scale
2 passages used, similarity 0.91 / 0.87

And on the legacy v1 endpoint?

I could not find a documented rate limit for the v1 endpoint. I can route this to a human who can confirm it.

no passage above threshold - refused rather than guessed
Direct answer, bounded scope, and citations bound to the passages the answer was generated from.

Answer Engines vs Search Engines

Figure 3 — Two different contracts with the reader

Search results

  • Returns ten candidate documents
  • The reader performs the synthesis
  • Being wrong is diffuse - a bad result among good ones
  • No opinion about which answer is correct

Answer engine

  • Returns one composed answer
  • The system performs the synthesis
  • Being wrong is concentrated and quotable
  • Must be able to decline when the corpus is silent
The trade is convenience for accountability. An answer engine has to be right, because there is no results page to fall back on.

How to Evaluate an Answer Engine

Accuracy on a set of easy questions tells you nothing useful. Four measures do.

  • Groundedness — the share of claims traceable to a retrieved passage. This is the headline number.
  • Citation precision — how often the cited passage actually contains the claim it is attached to.
  • Refusal correctness — how often the system declines exactly when the answer is genuinely absent, scored in both directions.
  • Retrieval recall@k — whether the passage that could have answered the question was in the top k at all. When this is low, nothing downstream can save you.
Figure 4 — Build checklist

An answer engine you can put in front of customers

  • Heading-aware chunking with overlap and a heading-path prefix
  • Hybrid keyword plus vector retrieval
  • Cross-encoder reranking over a wider candidate set
  • Similarity floor with an explicit, tested refusal path
  • Citations bound to the passages actually used
  • Tenant and collection filters enforced server-side
  • Event-driven re-indexing so the corpus is never stale
  • Evaluation set covering answerable, unanswerable and ambiguous questions
  • Groundedness and citation precision tracked over time
Run the evaluation set on every prompt change, model upgrade and corpus re-ingest — all three can move these numbers.

For the ingestion side of this pipeline, see how CustomerGPT indexes your documentation; for the adversarial side, securing AI support guardrails.

Build Your Own Factual AI Answer Engine

Integrate CustomerGPT into your application to deliver instant, grounded, source-cited AI answers backed by your own documentation.

References & Sources

  1. Meta AI: Retrieval-Augmented Generation for Knowledge-Intensive Tasks
  2. Stanford HAI: Human-Centered Artificial Intelligence
  3. Google Research: Measuring and Mitigating Hallucinations in LLMs
  4. Pinecone: What is a Vector Database & How it Works

Frequently Asked Questions

What is the difference between an AI answer engine and a search engine?

A search engine ranks documents and leaves the synthesis to you. An answer engine retrieves the relevant passages and composes a direct response from them, ideally with citations. The retrieval step is similar; what differs is that the answer engine commits to an answer, which is exactly why grounding and refusal behaviour matter so much.

Why do AI answers hallucinate even with RAG?

Because retrieval can fail quietly. If the top passages are irrelevant but the system still generates, the model fills the gap with plausible text. Most hallucinations in a RAG system are retrieval failures wearing a generation costume — which is why a similarity floor and an explicit refusal path fix more of them than prompt wording ever will.

Does a bigger model reduce hallucination?

It helps with reasoning and phrasing, but it does not tell the model what is in your documentation. On domain-specific questions, better retrieval beats a bigger model almost every time, and it is far cheaper per request.

How many passages should be retrieved per question?

Three to five is a common sweet spot for support content. Too few and you miss the passage that mattered; too many and the relevant sentence gets diluted among near-misses, which measurably degrades answer precision.

How do I know whether my answer engine is any good?

Score groundedness (is every claim supported by a retrieved passage), citation precision (do the citations actually contain the claim), and refusal correctness (does it decline when the answer genuinely is not in the corpus). Plain accuracy on a happy-path question set hides the failures that damage trust.

Ready to deploy secure, custom AI agents?

Train your ChatGPT experts in seconds on manual links, files, and PDFs. Get started for free.

Build Your Chatbot Free