This repository contains a code sample on how to build a Cloud Application Programming Model application exposing functionality of SAP AI Core and SAP HANA Cloud Vector Engine using the CAP LLM Plugin. The code also shows how a developer can leverage vector embeddings to provide contextual information to an LLM.
For more information about the end-to-end scenario, take a look at the architecture documentation.
If you want an instructional experience learning about the CAP LLM Plugin, SAP AI Core and SAP Generative AI Hub follow the Expose capabilities of SAP AI Core with the SAP Cloud Application Programming Model CodeJam.
- A suitable IDE like Visual Studio Code or Neovim
- Install the Cloud Foundry CLI
- Install the hana-cli (optional)
- Create an SAP BTP account
- Create an instance of SAP HANA Cloud.
- Create an instance of SAP AI Core
- Create deployments for model support ChatCompletion
gpt-35-turbo or gpt-4
and embedding modeltext-embedding-ada-002
- Create a destination for Generative AI Hub in the SAP BTP Cockpit of your subaccount based on the Service Key of SAP AI Core:
Name: GENERATIVE_AI_HUB
Description: SAP AI Core deployed service (generative AI hub)
URL: <AI-API-OF-AI-CORE-SERVICE-KEY>/v2 # make sure to add /v2!
Type: HTTP
ProxyType: Internet
Authentication: OAuth2ClientCredentials
tokenServiceURL: <TOKEN-SERVICE-URL-OF-AI-CORE-SERVICE-KEY>/oauth/token
clientId: <YOUR-CLIENT-ID-OF-AI-CORE-SERVICE-KEY>
clientSecret: <YOUR-CLIENT-SECRET-OF-AI-CORE-SERVICE-KEY>
# Additional Properties:
URL.headers.AI-Resource-Group: default # adjust if necessary
URL.headers.Content-Type: application/json
HTML5.DynamicDestination: true
- The SAP BTP account needs the following entitlements:
Name | Service/Application | Plan |
---|---|---|
AI Core | aicore |
extended |
AI Launchpad | ai-launchpad |
standard |
HANA Cloud | hana-cloud |
hana |
SAP HANA Schemas & HDI Containers | hdi-shared |
free |
- Clone this GitHub repository to your local machine and open it in VS Code or any other suitable editor.
- Run
npm install
in the root to install all dependencies - Connect to your SAP BTP subaccount:
cf login -a <subaccount-endpoint>
- Bind the following services to the application:
- SAP HDI instance, hdi-shared
cds bind --to <hdi-shared-instance>:<service-key-name>
- SAP BTP, Destination Service
cds bind --to <destination>
- SAP HDI instance, hdi-shared
- Build the database artifacts for the SAP HANA Cloud deployment:
cds build --for hana
- Deploy database artifacts to SAP HANA Cloud:
cds deploy --to hana:<hdi-shared-service-instance>
- For hybrid testing execute:
cds watch --profile hybrid
To properly run through the use case there are four API endpoints you can call which can be found in the API Documentation.
There are two services defined in this CAP application:
- The Embedding Storage; includes the input text chunking, creation of vector embeddings, storing and deletion of the vector embeddings in the SAP HANA Cloud vector engine.
- The Roadshow Service; includes calls for retrieving the RAG response and execution of a similarity search.
- Generative AI Hub TechBytes sample
- CAP LLM Plugin samples
- CAP LLM Plugin npm
- CAP Vector Embeddings
- Retrieval Augmented Generation with GenAI on SAP BTP
- What is SAP AI Core?
- Combine the Power of AI with Business Context Using SAP HANA Cloud Vector Engine
No known issues.
Create an issue in this repository if you find a bug or have questions about the content.
For additional support, ask a question in SAP Community.
If you wish to contribute code, offer fixes or improvements, please send a pull request. Due to legal reasons, contributors will be asked to accept a DCO when they create the first pull request to this project. This happens in an automated fashion during the submission process. SAP uses the standard DCO text of the Linux Foundation.
Copyright (c) 2024 SAP SE or an SAP affiliate company. All rights reserved. This project is licensed under the Apache Software License, version 2.0 except as noted otherwise in the LICENSE file.