Skip to content

feat: (Grounding) Initial client classes with generated API and model #317

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 45 commits into from
Feb 25, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
80089ca
Initial
a-d Jan 23, 2025
b959d0e
intermediate
a-d Jan 28, 2025
f46b313
Remove hashmap extension
a-d Jan 30, 2025
14a461d
Refine; Add test code
a-d Jan 30, 2025
90c7924
Fix thresholds; Add missing test class
a-d Jan 30, 2025
d922bae
Update pom.xml
newtork Jan 31, 2025
3a9f057
Merge remote-tracking branch 'origin/main' into grounding-client
a-d Jan 31, 2025
3fb8af0
Fix merge conflict
a-d Jan 31, 2025
9964613
Merge remote-tracking branch 'origin/main' into grounding-client
a-d Feb 4, 2025
53a5ad1
Update generated code
a-d Feb 4, 2025
65f6dca
Mark the module for release
a-d Feb 5, 2025
939cd79
Extract service and destination to test root
a-d Feb 5, 2025
648a0b0
Formatting
bot-sdk-js Feb 5, 2025
7f2393f
Rename client class
a-d Feb 5, 2025
804428a
add test app controller and unit test
a-d Feb 6, 2025
8abc5e8
Merge branch 'main' into grounding-client
newtork Feb 10, 2025
73d7425
Merge remote-tracking branch 'origin/main' into grounding-client
a-d Feb 11, 2025
2806fdf
format
a-d Feb 12, 2025
2987e92
Remove Beta annotation on client
a-d Feb 13, 2025
affa192
Fix E2E tests
a-d Feb 13, 2025
a84ab71
Merge remote-tracking branch 'origin/grounding-client' into grounding…
a-d Feb 13, 2025
2f4bcc7
Merge remote-tracking branch 'origin/main' into grounding-client
a-d Feb 14, 2025
dcad8a1
Add extended test case for documents
a-d Feb 14, 2025
f9b8ab0
Update tests
a-d Feb 14, 2025
0a2ce03
Format, Syntax, checks
a-d Feb 14, 2025
1bda813
Add some frontend links
a-d Feb 14, 2025
08810c1
Migrate from public static factory method to constructor
a-d Feb 14, 2025
1bdf622
Merge branch 'main' into grounding-client
newtork Feb 17, 2025
eb7a00a
small changes
CharlesDuboisSAP Feb 17, 2025
f1132c8
Merge branch 'main' into grounding-client
newtork Feb 21, 2025
a96b058
Update thresholds
a-d Feb 21, 2025
bfab7e0
Update grounding/src/test/java/com/sap/ai/sdk/grounding/GroundingClie…
newtork Feb 21, 2025
4e73e29
Formatting
bot-sdk-js Feb 21, 2025
5430c52
Fix JavaDoc
a-d Feb 21, 2025
801c706
Update grounding/pom.xml
newtork Feb 21, 2025
10c715b
Fix test method name
a-d Feb 21, 2025
461e0e4
Merge remote-tracking branch 'origin/grounding-client' into grounding…
a-d Feb 21, 2025
af877e8
Add doc
a-d Feb 21, 2025
fce7127
Merge remote-tracking branch 'origin/main' into grounding-client
a-d Feb 24, 2025
a255bd5
Update docs/guides/GROUNDING.md
newtork Feb 24, 2025
c2951d5
Update docs/guides/GROUNDING.md
newtork Feb 24, 2025
8e927ae
Fix doc
a-d Feb 24, 2025
5b3ebd8
Update docs/guides/GROUNDING.md
newtork Feb 24, 2025
fb6252a
Merge branch 'grounding-client' of https://github.com/SAP/ai-sdk-java…
a-d Feb 24, 2025
4e20287
Migrate files from "api" namespace to "client" namespace
a-d Feb 24, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .pipeline/checkstyle-suppressions.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
<suppress files="[/\\]core[/\\]model[/\\]" checks=".*"/>
<suppress files="[/\\]openai[/\\]generated[/\\]model[/\\]" checks=".*"/>
<suppress files="[/\\]orchestration[/\\]model[/\\]" checks=".*"/>
<suppress files="[/\\]grounding[/\\]api[/\\]" checks=".*"/>
<suppress files="[/\\]grounding[/\\]model[/\\]" checks=".*"/>
<!-- Suppress TODOs -->
<suppress files="OpenAiChatMessage.java" checks="TodoComment" lines="257,7" />
<suppress files="ChatCompletionResponseMessage.java" checks="TodoComment" lines="53,34" />
Expand Down
2 changes: 2 additions & 0 deletions .pipeline/spotbugs-exclusions.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
<Package name="com.sap.ai.sdk.core.client"/>
<Package name="com.sap.ai.sdk.core.model"/>
<Package name="com.sap.ai.sdk.orchestration.model"/>
<Package name="com.sap.ai.sdk.grounding.client"/>
<Package name="com.sap.ai.sdk.grounding.model"/>
</Or>
</Match>
</FindBugsFilter>
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ For more detailed information and advanced usage, please refer to the following:
- [<img src="sample-code/spring-app/src/main/resources/static/Open-AI-Logo.svg" width="16"/> OpenAI Chat Completion](docs/guides/OPENAI_CHAT_COMPLETION.md)
- [<img src="https://spring.io/favicon-32x32.png" width="16"/> Spring AI Integration](docs/guides/SPRING_AI_INTEGRATION.md)
- [🧰 AI Core Deployment](docs/guides/AI_CORE_DEPLOYMENT.md)
- [<img src="sample-code/spring-app/src/main/resources/static/grounding.png" width="16"/> AI Core Grounding](docs/guides/GROUNDING.md)

For updating versions, please refer to the [**Release Notes**](docs/release-notes/release-notes-0-to-14.md).

Expand Down
155 changes: 155 additions & 0 deletions docs/guides/GROUNDING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
# Grounding Services

## Table of Contents

- [Introduction](#introduction)
- [Prerequisites](#prerequisites)
- [Maven Dependencies](#maven-dependencies)
- [Usage](#usage)
- [Data Ingestion](#data-ingestion)
- [Pipeline API](#pipeline-api)
- [Vector API](#vector-api)
- [Data Retrieval](#retrieval-api)
- [Retrieval API](#create-a-deployment)
- [Grounding via Orchestration](#grounding-via-orchestration)

## Introduction

This guide provides examples on how to manage data in SAP Document Grounding.
It's divided into two main sections: Data Ingestion and Data Retrieval.

> [!WARNING]
> The below examples rely on generated model classes.
> Please be aware of the [implications described here](/README.md#general-requirements).

## Prerequisites

Before using the Grounding module, ensure that you have met all the general requirements outlined in the [README.md](../../README.md#general-requirements).
Additionally, include the necessary Maven dependency in your project.

### Maven Dependencies

Add the following dependency to your `pom.xml` file:

```xml
<dependency>
<groupId>com.sap.ai.sdk</groupId>
<artifactId>grounding</artifactId>
<version>${ai-sdk.version}</version>
</dependency>
```

See [an example pom in our Spring Boot application](../../sample-code/spring-app/pom.xml)

## Usage

In addition to the prerequisites above, we assume you have already set up the following to carry out the examples in this guide:

- A running instance of SAP AI Core with correctly setup credentials, including a resource group id.

## Data Ingestion

The following APIs are available for data ingestion: Pipeline and Vector.

### Pipeline API

Consider the following code sample to read pipelines, create a new one and get its status:

```java
var api = new GroundingClient().pipelines();
var resourceGroupId = "default";

// get all pipelines
Pipelines pipelines = api.getAllPipelines(resourceGroupId);

// create new pipeline
var type = "MSSharePoint"; // or "S3" or "SFTP"
var pipelineSecret = "my-secret-name";
var config = PipelinePostRequstConfiguration.create().destination(pipelineSecret);
var request = PipelinePostRequst.create().type(type)._configuration(config);
PipelineId pipeline = api.createPipeline(resourceGroupId, request);

// get pipeline status
PipelineStatus status = api.getPipelineStatus(resourceGroupId, pipeline.getPipelineId());
```

### Vector API

```java
var api = new GroundingClient().vector();
var resourceGroupId = "default";

// resolve collection id
var collectionId = UUID.fromString("12345-123-123-123-0123456abcdef");

var request = DocumentCreateRequest.create()
.documents(BaseDocument.create()
.chunks(TextOnlyBaseChunk.create()
.content("The dog makes _woof_")
.metadata(KeyValueListPair.create()
.key("animal").value("dog")))
.metadata(DocumentKeyValueListPair.create()
.key("topic").value("sound")));
DocumentsListResponse response = api.createDocuments(resourceGroupId, collectionId, request);
```

Refer to the [DeploymentController.java](../../sample-code/spring-app/src/main/java/com/sap/ai/sdk/app/controllers/DeploymentController.java) in our Spring Boot application for a complete example.

## Data Retrieval

The following APIs are available for data retrieval: Retrieval and Orchestration.


### Retrieval API

Consider the following code sample to search for relevant grounding data based on a query:

```java
var api = new GroundingClient().retrieval();
var resourceGroupId = "default";

var filter =
RetrievalSearchFilter.create()
.id("question")
.dataRepositoryType(DataRepositoryType.VECTOR)
.dataRepositories(List.of("*"))
.searchConfiguration(SearchConfiguration.create().maxChunkCount(10));
var search = RetrievalSearchInput.create().query("What is SAP Cloud SDK for AI?").filters(filter);
RetievalSearchResults results = api.search(resourceGroupId, search);
```

### Grounding via Orchestration

You can use the grounding service via orchestration.
Please find the [documentation on Orchestration client in the dedicated document](ORCHESTRATION_CHAT_COMPLETION.md).

```java
OrchestrationClient client;

var databaseFilter =
DocumentGroundingFilter.create()
.dataRepositoryType(DataRepositoryType.VECTOR)
.searchConfig(GroundingFilterSearchConfiguration.create().maxChunkCount(3));
var groundingConfigConfig =
GroundingModuleConfigConfig.create()
.inputParams(List.of("query"))
.outputParam("results")
.addFiltersItem(databaseFilter);
var groundingConfig =
GroundingModuleConfig.create()
.type(GroundingModuleConfig.TypeEnum.DOCUMENT_GROUNDING_SERVICE)
.config(groundingConfigConfig);
var configWithGrounding =
new OrchestrationModuleConfig()
.withLlmConfig(GPT_4O)
.withGroundingConfig(groundingConfig);

var inputParams = Map.of("query", "What is SAP Cloud SDK for AI?");

var prompt =
new OrchestrationPrompt(
inputParams,
Message.system("Context message with embedded grounding results. {{?results}}"));

OrchestrationChatResponse response = client.chatCompletion(prompt, configWithGrounding);
```
152 changes: 152 additions & 0 deletions grounding/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.sap.ai.sdk</groupId>
<artifactId>sdk-parent</artifactId>
<version>1.4.0-SNAPSHOT</version>
</parent>
<artifactId>grounding</artifactId>
<name>Grounding client</name>
<description>SAP Cloud SDK for AI is the official Software Development Kit (SDK) for SAP AI Core, SAP Generative AI Hub, and Orchestration Service. This is the client for the Grounding Service.</description>

<url>https://github.com/SAP/ai-sdk-java?tab=readme-ov-file#documentation</url>
<organization>
<name>SAP SE</name>
<url>https://www.sap.com</url>
</organization>
<licenses>
<license>
<name>The Apache Software License, Version 2.0</name>
<url>https://www.apache.org/licenses/LICENSE-2.0.txt</url>
</license>
</licenses>
<developers>
<developer>
<name>SAP</name>
<email>[email protected]</email>
<organization>SAP SE</organization>
<organizationUrl>https://www.sap.com</organizationUrl>
</developer>
</developers>
<properties>
<project.rootdir>${project.basedir}/../</project.rootdir>
<coverage.complexity>80%</coverage.complexity>
<coverage.line>71%</coverage.line>
<coverage.instruction>85%</coverage.instruction>
<coverage.branch>100%</coverage.branch>
<coverage.method>80%</coverage.method>
<coverage.class>100%</coverage.class>
</properties>

<dependencies>
<!-- used by generated API classes -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
</dependency>
<!-- scope "compile" -->
<dependency>
<groupId>com.sap.ai.sdk</groupId>
<artifactId>core</artifactId>
</dependency>
<dependency>
<groupId>com.sap.cloud.sdk.cloudplatform</groupId>
<artifactId>cloudplatform-connectivity</artifactId>
</dependency>
<dependency>
<groupId>com.sap.cloud.sdk.datamodel</groupId>
<artifactId>openapi-core</artifactId>
</dependency>
<dependency>
<groupId>com.google.code.findbugs</groupId>
<artifactId>jsr305</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
</dependency>
<!-- scope "provided" -->
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<scope>provided</scope>
</dependency>
<!-- scope "test" -->
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.wiremock</groupId>
<artifactId>wiremock</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<profiles>
<profile>
<id>generate</id>
<activation>
<activeByDefault>false</activeByDefault>
<property>
<name>generate</name>
</property>
</activation>
<build>
<plugins>
<plugin>
<groupId>com.sap.cloud.sdk.datamodel</groupId>
<artifactId>openapi-generator-maven-plugin</artifactId>
<configuration>
<outputDirectory>${project.basedir}/src/main/java</outputDirectory>
<apiMaturity>beta</apiMaturity>
<enableOneOfAnyOfGeneration>true</enableOneOfAnyOfGeneration>
<compileScope>COMPILE</compileScope>
<deleteOutputDirectory>true</deleteOutputDirectory>
</configuration>
<executions>
<execution>
<id>orchestration</id>
<goals>
<goal>generate</goal>
</goals>
<phase>generate-sources</phase>
<configuration>
<inputSpec>${project.basedir}/src/main/resources/spec/grounding.yaml</inputSpec>
<apiPackage>com.sap.ai.sdk.grounding.client</apiPackage>
<modelPackage>com.sap.ai.sdk.grounding.model</modelPackage>
<additionalProperties>
<pojoBuilderMethodName>create</pojoBuilderMethodName>
<pojoBuildMethodName/>
<pojoConstructorVisibility>protected</pojoConstructorVisibility>
<enumUnknownDefaultCase>true</enumUnknownDefaultCase>
<useOneOfInterfaces>true</useOneOfInterfaces>
</additionalProperties>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>
Loading
Loading