Search⌘ K

Grounding Responses and Working with Long Documents

Learn how to ground AI responses in provided documents to ensure factual accuracy and overcome the challenges of long contexts.

We have learned to engineer prompts that control the structure, voice, and reasoning of LLMs. Now, we must tackle one of the most critical aspects of building trustworthy applications: ensuring the AI’s answers are factually accurate and based on reliable information.

Consider a high-stakes scenario. A financial services company deploys an AI assistant to support advisors in answering questions about a new, complex investment product. The AI is provided with the 100-page product prospectus as its reference document. An advisor asks an important question: “What is the early withdrawal penalty for this fund?” The AI, unable to locate the specific clause in the lengthy document, does not indicate that it lacks sufficient information to answer. Instead, it generates a plausible but incorrect response, such as “a standard 1% fee.” The advisor relays this incorrect information to a client, resulting in a financial loss and a breach of trust.

This scenario highlights two deeply intertwined challenges that every AI engineer must solve. First, how do we force an AI to adhere strictly to the facts we provide and, just as importantly, to admit when it doesn’t know something? Second, how do we apply this discipline when the required facts are buried within a document that is far too long for a human or even the AI to process casually?

In this lesson, we will learn the essential technique of grounding to reduce AI hallucinations. Then, we will learn the practical strategies and architectural patterns required to apply grounding to the lengthy documents common in professional and enterprise settings.

The principle of grounding: A defense against hallucination

To address the issue of factual inaccuracy, we must first understand its underlying cause. The default behavior of an LLM is not always conducive to accurately recalling facts from a specific document. This can lead to two issues: hallucination and knowledge blending.

What is an AI hallucination?

In the context of AI, a hallucination is the phenomenon where a language model generates information that is plausible-sounding but is factually incorrect, nonsensical, or not present in the provided source data. It is the model effectively “making things up”. ...