liveBook · Manning

Grounding

As explained in Build AI-Enhanced Web Apps

Grounding is the technique of checking generated information against a reliable external corpus to improve factual accuracy.

Grounding checks an AI-generated answer against reliable information instead of relying only on the model’s memory. In a document-question-answering app, it helps keep responses faithful to the supplied documents and reduces plausible-sounding inaccuracies. section 7.2.3 section 7.0

A grounded RAG flow starts with a user question, searches relevant documents, extracts useful context, and combines that context with the question in a prompt. The model generates an answer from the enhanced prompt; source annotations can then let users check where the answer came from. section 7.2.6

Figure 7.10 RAG approach for grounding LLMs with relevant information. The system performs a grounding search to extract the most relevant context, which is combined with the original user input to create an enhanced prompt. This prompt is then passed to the LLM, which generates the final grounded response that is provided to the user.

The diagram shows where retrieved context enters the prompt before the LLM produces its response. section 7.2.6

Choose a grounding method to match the application’s need:

  • Retrieval-augmented grounding brings external information into generation; knowledge-base grounding draws on a curated, trusted repository. section 7.2.6
  • Citation-based grounding attaches references users can inspect. Contextual grounding uses earlier interactions to tailor a response. section 7.2.6
  • Log-probability grounding examines token-level confidence and uncertainty. Treat those signals as an evaluation aid, not as a substitute for checking factual sources. section 7.2.6 section 7.2.3

Add a confidence-aware RAG query

In a Next.js RAG app, a conversation handler can import `LogProbsRag`, initialize the RAG service, and call `performEnhancedRAG(input, { confidenceThreshold: 85, fallbackStrategy: 'ask_user' })`. It can log returned `confidenceMetrics` and catch query errors. A separate `ChatOpenAI` configuration illustrates token-level signals with `logprobs: true` and `topLogprobs: 3`. These settings provide a way to assess uncertainty alongside the retrieved-document workflow; they do not themselves establish that an answer matches a source. section 7.2.6 section 7.2.3

How Build AI-Enhanced Web Apps covers it

How deep it goes
Explains the search-to-answer flow and illustrates confidence-aware integration, but does not establish token confidence as proof of factual accuracy.
Examples
Shows a RAG flow diagram, token log-probability settings, and an enhanced query with a confidence threshold and ask-user fallback.
What it assumes
Assumes comfort with Vercel AI SDK and LangChain.js workflows; benefits from familiarity with prompt engineering.
What you can do after
Apply it via LangChain.js RAG workflows to anchor answers to documents and inspect response confidence.
How it connects
Connects retrieval-augmented generation, document search, prompt engineering, citations, and log probabilities.

Also explained in

Compare how 8 books explain grounding →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Build AI-Enhanced Web Apps. The section links point to the parts of the book it draws on.