SAP Home Learn Build Integrate Model Operate Extend with AI ConnectTutorial navigator Knowledge Graph API Devtoberfest Developer Advocates App Space

Manage my Account SAP Devs YouTube ↗ Learnings ↗ Community ↗ Provide Feedback ↗
Logout
โคข Open full site

Retrieval Augmented Generation using generative-ai-hub-sdk and HANA vector search

Using HANA vector store to store vector embeddings and using them in Retrieval Augmented Generation.

Overview

🎓 beginner 20 min. SAP Ai CoreBeginnerMachine Learning

You will learn

  • โœ”How to create a table and store embeddings in HANA Vector Store.
  • โœ”How to use the embeddings in Retrieval Augmented Generation. Please find downloadable sample notebooks for the tutorials : Note that these tutorials are for demonstration purposes only and should not be used in production environments. To execute them properly, you’ll need to set up your own S3 bucket or provision services from BTP, including an AI Core with a standard plan for narrow AI and an extended plan for GenAI HUB. Ensure you input the service keys of these services into the relevant cells of the notebook. Link to notebook
Dhrubajyoti Paul D Dhrubajyoti Paul September 13, 2024
Created by January 22, 2024
Contributors

Prerequisites

Prerequisites

  • A BTP global account If you are an SAP Developer or SAP employee, please refer to the following links ( for internal SAP stakeholders only ) - How to create a BTP Account (internal) SAP AI Core If you are an external developer or a customer or a partner kindly refer to this tutorial
  • Access to SAP AI core with sap extended plan.
  • Have python3 installed in your system.
  • Have generative-ai-hub-sdk installed in your system.

Steps

Step 1 Installing generative-ai-hub-sdk
โ€”

To install the generative-ai-hub-sdk package in your system, open your terminal or command prompt and run the following command.

Code
pip3 install generative-ai-hub-sdk

Once the package is installed, you need to configure proxy modules to use the large language models. We recommend setting these values as environment variables for AI Core credentials via a configuration file. The default path for this file is ~/.aicore/config.json.

Open Notepad and replace the placeholder values in the JSON file with your AI Core service keys, which you downloaded from BTP. Save the file by pressing Command + S. When prompted, navigate to ~/.aicore/ and save the file as config.json.

The default path can be overridden by setting the AICORE_HOME environment variable to the folder path from which the config file should be read.

image

Source: https://pypi.org/project/generative-ai-hub-sdk/

Step 2 Loading vector data from a csv file
+
Step 3 Creating a connection using dbapi
+
Step 4 Creating a table and adding data
+
Step 5 Setting up hana_ml and generative-ai-hub-sdk
+
Step 6 Get Embeddings
+
Step 7 Running vector search
+
Step 8 Creating a prompt template
+
Step 9 Querying the LLM
+
Step 10 Testing the function
+

Resources

Discussion

Share feedback on this tutorial or join the conversation in SAP Community.

Submit detailed feedback Discuss in Community
Steps
Step 1 of 10
1. Installing generative-ai-hub-sdk 2. Loading vector data from a csv file 3. Creating a connection using dbapi 4. Creating a table and adding data 5. Setting up hana_ml and generative-ai-hub-sdk 6. Get Embeddings 7. Running vector search 8. Creating a prompt template 9. Querying the LLM 10. Testing the function

Learn more →