Move advisors that depend on vector store to spring-ai-advisors module

This commit is contained in:
Mark Pollack
2025-03-31 15:58:56 -04:00
parent 3233e10054
commit 81fecefae8
7 changed files with 152 additions and 18 deletions

View File

@@ -0,0 +1,100 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Copyright 2023-2024 the original author or authors.
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
~ You may obtain a copy of the License at
~
~ https://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->
<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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.ai</groupId>
<artifactId>spring-ai</artifactId>
<version>1.0.0-SNAPSHOT</version>
<relativePath>../../pom.xml</relativePath>
</parent>
<artifactId>spring-ai-advisors</artifactId>
<packaging>jar</packaging>
<name>Spring AI Advisors</name>
<description>Chat client advisors for Spring AI</description>
<url>https://github.com/spring-projects/spring-ai</url>
<scm>
<url>https://github.com/spring-projects/spring-ai</url>
<connection>git://github.com/spring-projects/spring-ai.git</connection>
<developerConnection>git@github.com:spring-projects/spring-ai.git</developerConnection>
</scm>
<properties>
<maven.compiler.target>17</maven.compiler.target>
<maven.compiler.source>17</maven.compiler.source>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.ai</groupId>
<artifactId>spring-ai-core</artifactId>
<version>${project.parent.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.ai</groupId>
<artifactId>spring-ai-vector-store</artifactId>
<version>${project.parent.version}</version>
</dependency>
<!-- Spring Framework -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
</dependency>
<dependency>
<groupId>io.projectreactor</groupId>
<artifactId>reactor-core</artifactId>
</dependency>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-stdlib</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-reflect</artifactId>
<optional>true</optional>
</dependency>
<!-- test dependencies -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.module</groupId>
<artifactId>jackson-module-kotlin</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
</project>

View File

@@ -0,0 +1,25 @@
/*
* Copyright 2023-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* Spring AI chat client advisors package.
*/
@NonNullApi
@NonNullFields
package org.springframework.ai.chat.client.advisor;
import org.springframework.lang.NonNullApi;
import org.springframework.lang.NonNullFields;

View File

@@ -20,6 +20,7 @@ import java.time.Duration;
import java.util.List;
import java.util.Map;
import org.assertj.core.api.Assertions;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.ArgumentCaptor;
@@ -128,19 +129,19 @@ public class QuestionAnswerAdvisorTests {
//formatter:on
// Ensure the metadata is correctly copied over
assertThat(response.getMetadata().getModel()).isEqualTo("model1");
assertThat(response.getMetadata().getId()).isEqualTo("678");
assertThat(response.getMetadata().getRateLimit().getRequestsLimit()).isEqualTo(5L);
assertThat(response.getMetadata().getRateLimit().getRequestsRemaining()).isEqualTo(6L);
assertThat(response.getMetadata().getRateLimit().getRequestsReset()).isEqualTo(Duration.ofSeconds(7));
assertThat(response.getMetadata().getRateLimit().getTokensLimit()).isEqualTo(8L);
assertThat(response.getMetadata().getRateLimit().getTokensRemaining()).isEqualTo(8L);
assertThat(response.getMetadata().getRateLimit().getTokensReset()).isEqualTo(Duration.ofSeconds(9));
assertThat(response.getMetadata().getUsage().getPromptTokens()).isEqualTo(6L);
assertThat(response.getMetadata().getUsage().getCompletionTokens()).isEqualTo(7L);
assertThat(response.getMetadata().getUsage().getTotalTokens()).isEqualTo(6L + 7L);
assertThat(response.getMetadata().get("key6").toString()).isEqualTo("value6");
assertThat(response.getMetadata().get("key1").toString()).isEqualTo("value1");
Assertions.assertThat(response.getMetadata().getModel()).isEqualTo("model1");
Assertions.assertThat(response.getMetadata().getId()).isEqualTo("678");
Assertions.assertThat(response.getMetadata().getRateLimit().getRequestsLimit()).isEqualTo(5L);
Assertions.assertThat(response.getMetadata().getRateLimit().getRequestsRemaining()).isEqualTo(6L);
Assertions.assertThat(response.getMetadata().getRateLimit().getRequestsReset()).isEqualTo(Duration.ofSeconds(7));
Assertions.assertThat(response.getMetadata().getRateLimit().getTokensLimit()).isEqualTo(8L);
Assertions.assertThat(response.getMetadata().getRateLimit().getTokensRemaining()).isEqualTo(8L);
Assertions.assertThat(response.getMetadata().getRateLimit().getTokensReset()).isEqualTo(Duration.ofSeconds(9));
Assertions.assertThat(response.getMetadata().getUsage().getPromptTokens()).isEqualTo(6L);
Assertions.assertThat(response.getMetadata().getUsage().getCompletionTokens()).isEqualTo(7L);
Assertions.assertThat(response.getMetadata().getUsage().getTotalTokens()).isEqualTo(6L + 7L);
Assertions.assertThat(response.getMetadata().get("key6").toString()).isEqualTo("value6");
Assertions.assertThat(response.getMetadata().get("key1").toString()).isEqualTo("value1");
String content = response.getResult().getOutput().getText();
@@ -171,9 +172,9 @@ public class QuestionAnswerAdvisorTests {
the user that you can't answer the question.
""");
assertThat(this.vectorSearchCaptor.getValue().getFilterExpression()).isEqualTo(new FilterExpressionBuilder().eq("type", "Spring").build());
assertThat(this.vectorSearchCaptor.getValue().getSimilarityThreshold()).isEqualTo(0.99d);
assertThat(this.vectorSearchCaptor.getValue().getTopK()).isEqualTo(6);
Assertions.assertThat(this.vectorSearchCaptor.getValue().getFilterExpression()).isEqualTo(new FilterExpressionBuilder().eq("type", "Spring").build());
Assertions.assertThat(this.vectorSearchCaptor.getValue().getSimilarityThreshold()).isEqualTo(0.99d);
Assertions.assertThat(this.vectorSearchCaptor.getValue().getTopK()).isEqualTo(6);
}
@Test
@@ -201,7 +202,7 @@ public class QuestionAnswerAdvisorTests {
var userPrompt = this.promptCaptor.getValue().getInstructions().get(0).getText();
assertThat(userPrompt).doesNotContain(userTextTemplate);
assertThat(userPrompt).contains(expectedQuery);
assertThat(this.vectorSearchCaptor.getValue().getQuery()).isEqualTo(expectedQuery);
Assertions.assertThat(this.vectorSearchCaptor.getValue().getQuery()).isEqualTo(expectedQuery);
}
@Test
@@ -230,7 +231,7 @@ public class QuestionAnswerAdvisorTests {
var userPrompt = this.promptCaptor.getValue().getInstructions().get(0).getText();
assertThat(userPrompt).doesNotContain(userTextTemplate);
assertThat(userPrompt).contains(expectedQuery);
assertThat(this.vectorSearchCaptor.getValue().getQuery()).isEqualTo(expectedQuery);
Assertions.assertThat(this.vectorSearchCaptor.getValue().getQuery()).isEqualTo(expectedQuery);
}
}

View File

@@ -37,6 +37,7 @@
<module>spring-ai-model</module>
<module>spring-ai-test</module>
<module>spring-ai-vector-store</module>
<module>advisors/spring-ai-advisors</module>
<module>auto-configurations/common/spring-ai-autoconfigure-retry</module>

View File

@@ -48,6 +48,13 @@
<version>${project.parent.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.ai</groupId>
<artifactId>spring-ai-advisors</artifactId>
<version>${project.parent.version}</version>
</dependency>
<dependency>
<groupId>com.zaxxer</groupId>
<artifactId>HikariCP</artifactId>