Skip to content

Commit 81fecef

Browse files
committed
Move advisors that depend on vector store to spring-ai-advisors module
1 parent 3233e10 commit 81fecef

File tree

7 files changed

+152
-18
lines changed

7 files changed

+152
-18
lines changed

advisors/spring-ai-advisors/pom.xml

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
~ Copyright 2023-2024 the original author or authors.
4+
~
5+
~ Licensed under the Apache License, Version 2.0 (the "License");
6+
~ you may not use this file except in compliance with the License.
7+
~ You may obtain a copy of the License at
8+
~
9+
~ https://www.apache.org/licenses/LICENSE-2.0
10+
~
11+
~ Unless required by applicable law or agreed to in writing, software
12+
~ distributed under the License is distributed on an "AS IS" BASIS,
13+
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
~ See the License for the specific language governing permissions and
15+
~ limitations under the License.
16+
-->
17+
18+
<project xmlns="http://maven.apache.org/POM/4.0.0"
19+
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">
20+
<modelVersion>4.0.0</modelVersion>
21+
<parent>
22+
<groupId>org.springframework.ai</groupId>
23+
<artifactId>spring-ai</artifactId>
24+
<version>1.0.0-SNAPSHOT</version>
25+
<relativePath>../../pom.xml</relativePath>
26+
</parent>
27+
<artifactId>spring-ai-advisors</artifactId>
28+
<packaging>jar</packaging>
29+
<name>Spring AI Advisors</name>
30+
<description>Chat client advisors for Spring AI</description>
31+
<url>https://github.com/spring-projects/spring-ai</url>
32+
33+
<scm>
34+
<url>https://github.com/spring-projects/spring-ai</url>
35+
<connection>git://github.com/spring-projects/spring-ai.git</connection>
36+
<developerConnection>git@github.com:spring-projects/spring-ai.git</developerConnection>
37+
</scm>
38+
39+
<properties>
40+
<maven.compiler.target>17</maven.compiler.target>
41+
<maven.compiler.source>17</maven.compiler.source>
42+
</properties>
43+
44+
<dependencies>
45+
46+
<dependency>
47+
<groupId>org.springframework.ai</groupId>
48+
<artifactId>spring-ai-core</artifactId>
49+
<version>${project.parent.version}</version>
50+
</dependency>
51+
52+
<dependency>
53+
<groupId>org.springframework.ai</groupId>
54+
<artifactId>spring-ai-vector-store</artifactId>
55+
<version>${project.parent.version}</version>
56+
</dependency>
57+
58+
<!-- Spring Framework -->
59+
<dependency>
60+
<groupId>org.springframework</groupId>
61+
<artifactId>spring-context</artifactId>
62+
</dependency>
63+
64+
<dependency>
65+
<groupId>com.fasterxml.jackson.core</groupId>
66+
<artifactId>jackson-databind</artifactId>
67+
</dependency>
68+
69+
<dependency>
70+
<groupId>io.projectreactor</groupId>
71+
<artifactId>reactor-core</artifactId>
72+
</dependency>
73+
74+
<dependency>
75+
<groupId>org.jetbrains.kotlin</groupId>
76+
<artifactId>kotlin-stdlib</artifactId>
77+
<optional>true</optional>
78+
</dependency>
79+
80+
<dependency>
81+
<groupId>org.jetbrains.kotlin</groupId>
82+
<artifactId>kotlin-reflect</artifactId>
83+
<optional>true</optional>
84+
</dependency>
85+
86+
<!-- test dependencies -->
87+
<dependency>
88+
<groupId>org.springframework.boot</groupId>
89+
<artifactId>spring-boot-starter-test</artifactId>
90+
<scope>test</scope>
91+
</dependency>
92+
93+
<dependency>
94+
<groupId>com.fasterxml.jackson.module</groupId>
95+
<artifactId>jackson-module-kotlin</artifactId>
96+
<scope>test</scope>
97+
</dependency>
98+
</dependencies>
99+
100+
</project>
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/*
2+
* Copyright 2023-2024 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
/**
18+
* Spring AI chat client advisors package.
19+
*/
20+
@NonNullApi
21+
@NonNullFields
22+
package org.springframework.ai.chat.client.advisor;
23+
24+
import org.springframework.lang.NonNullApi;
25+
import org.springframework.lang.NonNullFields;

spring-ai-core/src/test/java/org/springframework/ai/chat/client/advisor/QuestionAnswerAdvisorTests.java renamed to advisors/spring-ai-advisors/src/test/java/org/springframework/ai/chat/client/advisor/QuestionAnswerAdvisorTests.java

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import java.util.List;
2121
import java.util.Map;
2222

23+
import org.assertj.core.api.Assertions;
2324
import org.junit.jupiter.api.Test;
2425
import org.junit.jupiter.api.extension.ExtendWith;
2526
import org.mockito.ArgumentCaptor;
@@ -128,19 +129,19 @@ public Duration getTokensReset() {
128129
//formatter:on
129130

130131
// Ensure the metadata is correctly copied over
131-
assertThat(response.getMetadata().getModel()).isEqualTo("model1");
132-
assertThat(response.getMetadata().getId()).isEqualTo("678");
133-
assertThat(response.getMetadata().getRateLimit().getRequestsLimit()).isEqualTo(5L);
134-
assertThat(response.getMetadata().getRateLimit().getRequestsRemaining()).isEqualTo(6L);
135-
assertThat(response.getMetadata().getRateLimit().getRequestsReset()).isEqualTo(Duration.ofSeconds(7));
136-
assertThat(response.getMetadata().getRateLimit().getTokensLimit()).isEqualTo(8L);
137-
assertThat(response.getMetadata().getRateLimit().getTokensRemaining()).isEqualTo(8L);
138-
assertThat(response.getMetadata().getRateLimit().getTokensReset()).isEqualTo(Duration.ofSeconds(9));
139-
assertThat(response.getMetadata().getUsage().getPromptTokens()).isEqualTo(6L);
140-
assertThat(response.getMetadata().getUsage().getCompletionTokens()).isEqualTo(7L);
141-
assertThat(response.getMetadata().getUsage().getTotalTokens()).isEqualTo(6L + 7L);
142-
assertThat(response.getMetadata().get("key6").toString()).isEqualTo("value6");
143-
assertThat(response.getMetadata().get("key1").toString()).isEqualTo("value1");
132+
Assertions.assertThat(response.getMetadata().getModel()).isEqualTo("model1");
133+
Assertions.assertThat(response.getMetadata().getId()).isEqualTo("678");
134+
Assertions.assertThat(response.getMetadata().getRateLimit().getRequestsLimit()).isEqualTo(5L);
135+
Assertions.assertThat(response.getMetadata().getRateLimit().getRequestsRemaining()).isEqualTo(6L);
136+
Assertions.assertThat(response.getMetadata().getRateLimit().getRequestsReset()).isEqualTo(Duration.ofSeconds(7));
137+
Assertions.assertThat(response.getMetadata().getRateLimit().getTokensLimit()).isEqualTo(8L);
138+
Assertions.assertThat(response.getMetadata().getRateLimit().getTokensRemaining()).isEqualTo(8L);
139+
Assertions.assertThat(response.getMetadata().getRateLimit().getTokensReset()).isEqualTo(Duration.ofSeconds(9));
140+
Assertions.assertThat(response.getMetadata().getUsage().getPromptTokens()).isEqualTo(6L);
141+
Assertions.assertThat(response.getMetadata().getUsage().getCompletionTokens()).isEqualTo(7L);
142+
Assertions.assertThat(response.getMetadata().getUsage().getTotalTokens()).isEqualTo(6L + 7L);
143+
Assertions.assertThat(response.getMetadata().get("key6").toString()).isEqualTo("value6");
144+
Assertions.assertThat(response.getMetadata().get("key1").toString()).isEqualTo("value1");
144145

145146
String content = response.getResult().getOutput().getText();
146147

@@ -171,9 +172,9 @@ public Duration getTokensReset() {
171172
the user that you can't answer the question.
172173
""");
173174

174-
assertThat(this.vectorSearchCaptor.getValue().getFilterExpression()).isEqualTo(new FilterExpressionBuilder().eq("type", "Spring").build());
175-
assertThat(this.vectorSearchCaptor.getValue().getSimilarityThreshold()).isEqualTo(0.99d);
176-
assertThat(this.vectorSearchCaptor.getValue().getTopK()).isEqualTo(6);
175+
Assertions.assertThat(this.vectorSearchCaptor.getValue().getFilterExpression()).isEqualTo(new FilterExpressionBuilder().eq("type", "Spring").build());
176+
Assertions.assertThat(this.vectorSearchCaptor.getValue().getSimilarityThreshold()).isEqualTo(0.99d);
177+
Assertions.assertThat(this.vectorSearchCaptor.getValue().getTopK()).isEqualTo(6);
177178
}
178179

179180
@Test
@@ -201,7 +202,7 @@ public void qaAdvisorTakesUserTextParametersIntoAccountForSimilaritySearch() {
201202
var userPrompt = this.promptCaptor.getValue().getInstructions().get(0).getText();
202203
assertThat(userPrompt).doesNotContain(userTextTemplate);
203204
assertThat(userPrompt).contains(expectedQuery);
204-
assertThat(this.vectorSearchCaptor.getValue().getQuery()).isEqualTo(expectedQuery);
205+
Assertions.assertThat(this.vectorSearchCaptor.getValue().getQuery()).isEqualTo(expectedQuery);
205206
}
206207

207208
@Test
@@ -230,7 +231,7 @@ public void qaAdvisorTakesUserParameterizedUserMessagesIntoAccountForSimilarityS
230231
var userPrompt = this.promptCaptor.getValue().getInstructions().get(0).getText();
231232
assertThat(userPrompt).doesNotContain(userTextTemplate);
232233
assertThat(userPrompt).contains(expectedQuery);
233-
assertThat(this.vectorSearchCaptor.getValue().getQuery()).isEqualTo(expectedQuery);
234+
Assertions.assertThat(this.vectorSearchCaptor.getValue().getQuery()).isEqualTo(expectedQuery);
234235
}
235236

236237
}

pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
<module>spring-ai-model</module>
3838
<module>spring-ai-test</module>
3939
<module>spring-ai-vector-store</module>
40+
<module>advisors/spring-ai-advisors</module>
4041

4142
<module>auto-configurations/common/spring-ai-autoconfigure-retry</module>
4243

vector-stores/spring-ai-pgvector-store/pom.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,13 @@
4848
<version>${project.parent.version}</version>
4949
</dependency>
5050

51+
<dependency>
52+
<groupId>org.springframework.ai</groupId>
53+
<artifactId>spring-ai-advisors</artifactId>
54+
<version>${project.parent.version}</version>
55+
</dependency>
56+
57+
5158
<dependency>
5259
<groupId>com.zaxxer</groupId>
5360
<artifactId>HikariCP</artifactId>

0 commit comments

Comments
 (0)