Skip to content

Commit f028608

Browse files
committed
feat: add module rag example
Signed-off-by: yuluo-yx <yuluo08290126@gmail.com>
1 parent e65665b commit f028608

File tree

23 files changed

+271
-158
lines changed

23 files changed

+271
-158
lines changed
File renamed without changes.

docker-compose/mysql/docker-compose.yml

Whitespace-only changes.

docker-compose/pgvector/README.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,10 @@
22

33
此文件夹中用于存放一些 pgvector 服务常用的 Docker Compose 启动文件。
44

5-
- postgres16版本同时安装age和pgvector [DockerFile](./postgres16-age/DockerFile)
5+
- postgres16版本同时安装age和pgvector [DockerFile](./postgres16-age/DockerFile)
6+
7+
执行以下命令启动 pg:
8+
9+
```shell
10+
docker compose up -d --build
11+
```
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
services:
2+
3+
postgres:
4+
build:
5+
context: .
6+
dockerfile: ./postgres16-age/DockerFile
7+
container_name: spring-ai-alibaba-postgres
8+
healthcheck:
9+
test: [ "CMD", "pg_isready", "-q", "-d", "postgres", "-U", "root" ]
10+
timeout: 45s
11+
interval: 10s
12+
retries: 10
13+
environment:
14+
- POSTGRES_DB=vector_store
15+
- POSTGRES_USER=root
16+
- POSTGRES_PASSWORD=password
17+
ports:
18+
- "5432:5432"

docker-compose/pgvector/postgres16-age/DockerFile

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,5 @@ RUN echo "shared_preload_libraries = 'age,vector'" >> /usr/share/postgresql/post
5252

5353
# Start PostgreSQL
5454

55-
56-
5755
#CMD ["/cmd_command.sh"]
58-
CMD ["postgres"]
56+
CMD ["postgres"]

spring-ai-alibaba-rag-example/module-rag/README.md

Whitespace-only changes.

spring-ai-alibaba-rag-example/web-search/pom.xml renamed to spring-ai-alibaba-rag-example/module-rag/pom.xml

Lines changed: 38 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,45 +17,70 @@
1717
-->
1818

1919
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
20-
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
20+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
2121
<modelVersion>4.0.0</modelVersion>
22-
2322
<parent>
2423
<groupId>com.alibaba.cloud.ai</groupId>
2524
<artifactId>spring-ai-alibaba-rag-example</artifactId>
2625
<version>${revision}</version>
2726
<relativePath>../pom.xml</relativePath>
2827
</parent>
29-
30-
<artifactId>web-search</artifactId>
31-
<version>2025.03.01</version>
32-
33-
<name>internet-search</name>
34-
<description>Internet Search project for Spring AI Alibaba</description>
28+
<groupId>com.alibaba.cloud.ai</groupId>
29+
<artifactId>rag-pgvector-example</artifactId>
30+
<version>0.0.1-SNAPSHOT</version>
31+
<name>rag-pgvector-example</name>
32+
<description>Demo project for Spring AI Alibaba</description>
3533

3634
<properties>
35+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
36+
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
3737
<maven.compiler.source>17</maven.compiler.source>
3838
<maven.compiler.target>17</maven.compiler.target>
3939
<maven-deploy-plugin.version>3.1.1</maven-deploy-plugin.version>
4040

4141
<!-- Spring AI -->
42-
<spring-ai-alibaba.version>1.0.0-M5.1</spring-ai-alibaba.version>
43-
<spring-ai.version>1.0.0-M5</spring-ai.version>
42+
<spring-ai-alibaba.version>1.0.0-M3.1</spring-ai-alibaba.version>
43+
<spring-ai.version>1.0.0-M3</spring-ai.version>
4444
</properties>
4545

4646
<dependencies>
47+
<dependency>
48+
<groupId>com.alibaba.cloud.ai</groupId>
49+
<artifactId>spring-ai-alibaba-starter</artifactId>
50+
<version>${spring-ai-alibaba.version}</version>
51+
</dependency>
52+
4753
<dependency>
4854
<groupId>org.springframework.boot</groupId>
4955
<artifactId>spring-boot-starter-web</artifactId>
5056
</dependency>
5157

58+
5259
<dependency>
53-
<groupId>com.alibaba.cloud.ai</groupId>
54-
<artifactId>spring-ai-alibaba-starter</artifactId>
55-
<version>${spring-ai-alibaba.version}</version>
60+
<groupId>org.springframework.ai</groupId>
61+
<artifactId>spring-ai-pdf-document-reader</artifactId>
62+
<version>${spring-ai.version}</version>
5663
</dependency>
64+
65+
<dependency>
66+
<groupId>org.springframework.ai</groupId>
67+
<artifactId>spring-ai-pgvector-store-spring-boot-starter</artifactId>
68+
</dependency>
69+
5770
</dependencies>
5871

72+
<dependencyManagement>
73+
<dependencies>
74+
<dependency>
75+
<groupId>org.springframework.ai</groupId>
76+
<artifactId>spring-ai-bom</artifactId>
77+
<version>${spring-ai.version}</version>
78+
<type>pom</type>
79+
<scope>import</scope>
80+
</dependency>
81+
</dependencies>
82+
</dependencyManagement>
83+
5984
<build>
6085
<plugins>
6186
<plugin>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package com.alibaba.cloud.ai.example.rag;/**
2+
* @author yuluo
3+
* @author <a href="mailto:yuluo08290126@gmail.com">yuluo</a>
4+
*/public class ModuleRAGApplication {
5+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package com.alibaba.cloud.ai.example.rag.controller;
2+
3+
import org.springframework.web.bind.annotation.RequestMapping;
4+
import org.springframework.web.bind.annotation.RestController;
5+
6+
/**
7+
* @author yuluo
8+
* @author <a href="mailto:yuluo08290126@gmail.com">yuluo</a>
9+
*/
10+
11+
@RestController
12+
@RequestMapping("/module-rag")
13+
public class ModuleRAGController {
14+
15+
16+
17+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
package com.alibaba.cloud.ai.example.rag.controller;
2+
3+
import org.springframework.ai.chat.client.ChatClient;
4+
import org.springframework.ai.chat.client.advisor.RetrievalAugmentationAdvisor;
5+
import org.springframework.ai.rag.retrieval.search.VectorStoreDocumentRetriever;
6+
import org.springframework.ai.vectorstore.VectorStore;
7+
import org.springframework.web.bind.annotation.PostMapping;
8+
import org.springframework.web.bind.annotation.RequestMapping;
9+
import org.springframework.web.bind.annotation.RequestParam;
10+
import org.springframework.web.bind.annotation.RestController;
11+
12+
/**
13+
* @author yuluo
14+
* @author <a href="mailto:yuluo08290126@gmail.com">yuluo</a>
15+
*/
16+
17+
@RestController
18+
@RequestMapping("/module-rag")
19+
public class ModuleRAGRewriteController {
20+
21+
private final ChatClient chatClient;
22+
private final RetrievalAugmentationAdvisor retrievalAugmentationAdvisor;
23+
24+
public ModuleRAGRewriteController(ChatClient.Builder chatClientBuilder, VectorStore vectorStore) {
25+
26+
this.chatClient = chatClientBuilder.build();
27+
this.retrievalAugmentationAdvisor = RetrievalAugmentationAdvisor.builder()
28+
.documentRetriever(VectorStoreDocumentRetriever.builder()
29+
.similarityThreshold(0.50)
30+
.vectorStore(vectorStore)
31+
.build()
32+
).build();
33+
}
34+
35+
@PostMapping("/rag/basic")
36+
String chatWithDocument(@RequestParam("prompt") String prompt) {
37+
38+
return chatClient.prompt()
39+
.advisors(retrievalAugmentationAdvisor)
40+
.user(prompt)
41+
.call()
42+
.content();
43+
}
44+
45+
}

0 commit comments

Comments
 (0)