liveBook · Manning

Grounding

As explained in Generative AI in Action

Grounding is the technique of supplying a generative model with relevant external information as context for its response.

Grounding supplies a generative model with external information to use when answering. For an enterprise assistant, that information might be a product FAQ or a domain-specific dataset. It can make responses more relevant and reduce hallucinations, but supplying context does not guarantee a correct answer. section 3.4.1 section 7.2

Choose how to provide context according to its size and use case:

  • For a small amount of information, put it in the chat completion’s system message alongside instructions for how the assistant should use it. section 3.4.1
  • For a larger collection, use embeddings and semantic search to retrieve the most relevant information. Retrieval-augmented generation (RAG) is a common way to ground responses in external data. section 3.4.1 section 7.2
  • Select sources for the task. A pharmaceutical research assistant, for example, could retrieve from a dataset of new drug research rather than rely only on the model’s training data. section 7.2

A grounded support answer

A support chatbot receives context describing Azure OpenAI Service in its system message. The same message instructs it to answer only from that context and to say “I don't know” when unsure. This is a small-context pattern; it is not a substitute for retrieving from a larger knowledge base. section 3.4.1

Listing 3.22 Grounding system message example
{"role": "system", "content": Assistant is an intelligent chatbot designed to help users answer technical questions about Azure OpenAI service. Only answer questions using the context below. Don’t make up the answer. If you are unsure of an answer, say 'I don't know'.

Context:
- Azure OpenAI Service provides REST API access to OpenAI's powerful language models including the GPT-3, Codex and Embeddings model series.
- Azure OpenAI Service gives customers advanced language AI with OpenAI GPT-3, Codex, and DALL-E models with the security and enterprise promise of Azure.
..."
},
{"role": "user", "content": "What is Azure OpenAI Service?"}

The system-message example shows the supplied context, answer constraint, uncertainty instruction, and user question together. section 3.4.1

Grounding also applies beyond question answering: GitHub Copilot uses the edited file and other open files as context for code suggestions. For data-heavy chat, grounding on selected data can be preferable to simply increasing the context window, which may add cost and leave the model more exposed to irrelevant, noisy, or contradictory information. Choose the source and retrieval approach for the application, then check whether answers actually reflect the supplied context. section 5.1.2 section 8.1.1 section 6.8

How Generative AI in Action covers it

How deep it goes
Explains inline system-message context and points to embeddings, semantic search, and RAG for larger datasets without detailing their implementation.
Examples
Uses an Azure OpenAI support chatbot, pharmaceutical research data, and GitHub Copilot’s open files as grounding examples.
What you can do after
Apply it via a chat-completion system message for small contexts, or choose retrieval for larger datasets.
How it connects
Connects grounding to system messages, embeddings, semantic search, RAG, hallucinations, and context windows.

Also explained in

Compare how 8 books explain grounding →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Generative AI in Action. The section links point to the parts of the book it draws on.