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







