You explored the foundational concepts of document grounding, vector embeddings, and the SAP HANA vector engine.
In this lesson, you will discover how to leverage the generative AI hub’s Orchestration Service to implement document grounding. Using the RAG approach, you will see a step-by-step process of setting up your knowledge base and configuring the grounding module to generate highly accurate and contextually relevant AI responses.
Implementing Document Grounding in the Generative AI Hub
The grounding capability is integral to the orchestration module of the generative AI hub. This module facilitates specialized data retrieval from vector databases, ensuring the AI’s responses are grounded in external, context-relevant information. In addition, the Pipeline API integrates vector stores like the managed SAP HANA database, which is directly accessible and works within the SAP Generative AI Hub via SAP AI Core.

SAP AI Launchpad also provides the grounding management app lets you manage the lifecycle of your data pipelines.
The generative AI hub supports robust document grounding through several key features and streamlined processes:
- Access to Diverse LLMs: The generative AI hub provides instant access to a wide range of LLMs from various providers, including Azure OpenAI models (gpt-5), Anthropic models(anthropic--claude-4-sonnet), and open-source models like Mistral and Meta models. This broad access enables you to orchestrate multiple LLMs to best suit grounding and content generation needs. To see all the available models, refer to 3437766 - Availability of Generative AI Models.
- Seamless Integration with SAP AI Launchpad: You can execute and monitor grounded prompts directly within the SAP AI Launchpad. This integration shows how generative AI, combined with your business data, can directly assist business processes while leveraging the underlying SAP AI Core infrastructure for secure operations.
- Efficient Document Indexing: Unstructured and semi-structured documents are preprocessed, divided into chunks, and converted to numerical embeddings with embedding models. These embeddings are efficiently stored in the SAP HANA Vector Engine for rapid and precise querying, fundamental to grounding AI responses in real, relevant data.
These integrated features empower you to build generative AI solutions that leverage your organization's trusted document repositories and provide reliable, transparent, and contextually accurate responses.
Grounding for Content Generation
Using the RAG approach, you will utilize the Document Grounding module within the Orchestration Service to generate content effectively. This module aligns user queries with relevant documents by retrieving them from a knowledge base. This knowledge base can be sourced from various repositories, including SharePoint folders, Elasticsearch engines, or dedicated vector data repositories.
You perform the following steps:
- Create the knowledge base with relevant documents.
- Configure the Document Grounding module in the Orchestration Service.
- Generate content using the RAG approach based on the knowledge base.
Prerequisites
- Install the SAP Cloud SDK for AI (Python) - generative using the command:Python1%pip install "sap-ai-sdk-gen[all]"
- Set the credentials for the SDK.
Detailed Steps
Step 1: Create a Vector Knowledge Base
- Prepare your knowledge base before using the Grounding module in the orchestration pipeline.
- The generative AI hub provides several options for users to prepare their knowledge base data:
- Upload documents to a supported data repository, then run the data pipeline to vectorize the documents. For more details, refer to the Pipeline API.
- Use the Vector API to directly provide chunks of the document. For additional information, see the Vector API.
Grounding Module Options
Choose one of the following options to use grounding:
Option 1: Upload Documents to Supported Data Repository and Run Data Pipeline
- The pipeline collects documents and segments the data into chunks.
- It generates embeddings, which are multidimensional representations of textual information, and stores them efficiently in a vector database.
The process involves the following steps:
- Perform Initial One-Time Administrative Steps: Create a resource group and a generic secret for grounding. For more information, see:
- Prepare Vector Knowledge Base: Configure the Pipeline API to read unstructured data from data repositories and store it in a vector database. Use the Pipeline API to:
- Read unstructured documents from various data repositories. Break the data into chunks and create embeddings.
- Store the multidimensional representations of the textual information in the vector database.
- Provide a repository ID to access the data.
For more information, see Preparing Data Using the Pipeline API.
Option 2: Provide Chunks of Documents via Vector API Directly
Provide chunks of data directly and store them using the Vector API. The process involves the following steps:
- Perform Initial One-Time Administrative Steps:Create a Resource Group for Grounding.
- Prepare Vector Knowledge Base: Provide chunks of information directly and store data in the vector database using the Vector API. Use the Vector API to:
- Create collections.
- Create documents by directly using the chunks of data provided by users.
- Store data in the vector database.
- Assign repository IDs to access the data.
- For more information, see Preparing Data Using the Vector API.
- Configure Grounding Module in the Orchestration: In the orchestration pipeline, you add configuration for the grounding requests:
- Create a grounding request configuration in the orchestration pipeline using the repository IDs and filters.
- Run the orchestration pipeline and check that the response refers to the user data. For more information, see Using the Grounding Module.
A detailed setup is also described here to prepare a knowledge base and verify it.
Step 2: Configure the Document Grounding Module
Now, you must define the configuration for the Document Grounding module, including setting up filters, and specifying the data repositories.
1orchestration_service_url = <your url code from deployment of the orchestration service>You must have at least one orchestration-compatible deployment for a generative AI model running. For more information, see and Create a Deployment for Orchestration in SAP AI Core.
Next, you must import all relevant libraries. See the code in the code repository here.
1234567891011121314151617181920212223# Set up the Orchestration Service
aicore_client = get_proxy_client().ai_core_client
orchestration_service = OrchestrationService(api_url=orchestration_service_url)
llm = LLM(
name="gpt-4o",
parameters={
'temperature': 0.0,
}
)
template = Template(
messages=[
SystemMessage("""Facility Solutions Company provides services to luxury residential complexes, apartments,
individual homes, and commercial properties such as office buildings, retail spaces, industrial facilities, and educational institutions.
Customers are encouraged to reach out with maintenance requests, service deficiencies, follow-ups, or any issues they need by email.
"""),
UserMessage("""You are a helpful assistant for any queries for answering questions.
Answer the request by providing relevant answers that fit to the request.
Request: {{ ?user_query }}
Context:{{ ?grounding_response }}
"""),
]
)
This Python code sets up an orchestration service crucial for handling complex tasks. It initializes an AI core client and configures an orchestration service with a given URL. The code then sets up an LLM with specific parameters to ensure consistent responses. Lastly, it creates a message template to aid in answering customer inquiries efficiently and effectively.
Next, we set up grounding services.
12345678910111213141516171819# Set up Document Grounding
filters = [DocumentGroundingFilter(id="vector",
data_repositories=["<add your data repository ID>"], ,
search_config=GroundingFilterSearch(max_chunk_count=15),
data_repository_type=DataRepositoryType.VECTOR.value
)
]
grounding_config = GroundingModule(
type="document_grounding_service",
config=DocumentGrounding(input_params=["user_query"], output_param="grounding_response", filters=filters)
)
config = OrchestrationConfig(
template=template,
llm=llm,
grounding=grounding_config
)
This Python code sets up and configures a document grounding service. It defines filters for document repositories and specifies search parameters. The grounding configuration is then integrated into an orchestration system, which uses templates and a language model to process and respond to user queries. This setup ensures efficient and accurate document retrieval based on user inputs.
Step 3: Generate Context-Relevant Answers
Run the orchestration service with the configured settings to generate answers based on user queries.
123456response = orchestration_service.run(config=config,
template_values=[
TemplateValue("user_query", "List the issues that are reported by customers."),
])
print(response.orchestration_result.choices[0].message.content)
This Python code sends a request to an orchestration service to run a specific configuration. It includes a template value with a user query asking to list customer-reported issues. After running the service, it prints the response from the orchestration result, specifically the message content of the first choice. This helps automate and fetch data on customer issues efficiently.
You get the following output:

You can see that the list of issues reported by customer, which is grounded in mails that customers provided.
You can see the documents that were retrieved for the context from the data repository.
1print(response.module_results.grounding.data['grounding_result'])This code extracts and displays the value of 'grounding_result' from a nested data structure within the 'response' object. This specific piece of data could be critical for understanding the outcome of a grounding module, making the code essential for debugging or analysis.
The output lists all the relevant mails used for response earlier, providing a deep insight into the context of the grounding technique. You can see this output in the repository.
Conclusion
In this lesson, you have accomplished the following key tasks:
- Established a Vector Knowledge Base: You learned to upload and vectorize documents, forming a robust, searchable knowledge base.
- Configured the Document Grounding Module: You set up the module within the Orchestration Service to intelligently retrieve relevant documents based on user queries.
- Generated Grounded AI Responses: You utilized the Orchestration Service to produce accurate and contextually relevant answers, demonstrating the power of grounding.
Lesson Summary
Building on your understanding of document grounding’s foundational concepts, vector embeddings, the SAP HANA vector engine, and RAG, this lesson provided a practical deep dive into implementation. You successfully learned to establish a vector knowledge base, configure the Document Grounding module within the Generative AI Hub’s Orchestration Service, and generate accurate, context-relevant AI responses. This end-to-end experience solidified how grounding significantly enhances AI’s reliability and relevance by integrating precise, external data into your solutions.
This course provided comprehensive conceptual and practical coverage of a grounding technique to solve business problems.
Learning Journey Summary
Throughout this learning journey, you started with discovering the significance of SAP Business AI and how it addresses business challenges by automating processes, enhancing decision-making, and supporting scalable, responsible innovation.
You then explored the foundations of LLMs, how they function, their remarkable strengths, and their inherent limitations. You saw how LLMs can automate tasks, generate content, and synthesize information at scale, but also why it’s essential to use them thoughtfully, with an awareness of risks like hallucinations, bias, and data privacy. You discovered that practical prompt engineering is the key to guiding LLMs to deliver relevant and reliable results.
You then delved into SAP’s generative AI hub, part of AI Foundation, understanding how it is a secure gateway to enterprise-grade AI. The hub empowers you to access and orchestrate leading LLMs, manage prompts, and confidently integrate AI into business processes. It ensures that your solutions are grounded in a real business context, reliable through robust security and compliance, and responsible by design.
Building on this foundation, you learned practical techniques for solving real business problems with LLMs, from prompt development and refinement to integrating prompts into applications using SDKs. You understood the art of prompt engineering, version control, and evaluation, ensuring your AI solutions are accurate, actionable, and scalable. The scalability is supported by creating and managing prompt templates in generative AI hub. Advanced techniques like few-shot prompting and meta prompting further enhanced the quality and consistency of AI outputs, enabling you to tackle even more complex scenarios.
Finally, you discovered how document grounding connects LLMs to your organization’s trusted knowledge sources, ensuring accurate and context-aware responses. You can transform documents into searchable vectors by leveraging SAP HANA Vector Engine and embedding models, enabling semantic search and RAG. Grounding minimizes hallucinations and aligns AI outputs with real business facts, making your solutions more trustworthy and effective.
In summary, you are now equipped to design, build, and deploy intelligent, reliable, and business-ready AI solutions, combining the power of LLMs, robust prompt engineering, and SAP Business AI to drive real value and innovation.