Skip to content

This repository contains sample code for a CAP application utilizing the CAP-LLM-Plugin to establish a connection to SAP AI Core and SAP HANA Cloud for creating and storing vector embeddings, perform similarity searches and requesting RAG responses.

License

Notifications You must be signed in to change notification settings

SAP-samples/cap-ai-vector-engine-sample

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

CAP with SAP HANA Vector Engine & SAP Core AI

REUSE status

Description

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.

Requirements

  • 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 model text-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

Download and Installation

  1. Clone this GitHub repository to your local machine and open it in VS Code or any other suitable editor.
  2. Run npm install in the root to install all dependencies
  3. Connect to your SAP BTP subaccount:
    cf login -a <subaccount-endpoint>
  4. 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>
  5. Build the database artifacts for the SAP HANA Cloud deployment:
    cds build --for hana
  6. Deploy database artifacts to SAP HANA Cloud:
    cds deploy --to hana:<hdi-shared-service-instance>
  7. For hybrid testing execute:
    cds watch --profile hybrid

How to use the application

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.

Further Information

Known Issues

No known issues.

How to obtain support

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.

Contributing

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.

License

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.

About

This repository contains sample code for a CAP application utilizing the CAP-LLM-Plugin to establish a connection to SAP AI Core and SAP HANA Cloud for creating and storing vector embeddings, perform similarity searches and requesting RAG responses.

Topics

Resources

License

Code of conduct

Security policy

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published