Move rag classes out of spring-ai-core and into new module spring-ai-rag

This commit is contained in:
Mark Pollack
2025-03-31 16:33:16 -04:00
parent 81fecefae8
commit 79671d47ec
43 changed files with 124 additions and 32 deletions

View File

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

View File

@@ -1,28 +0,0 @@
/*
* 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.
*/
/**
* RAG Module: Information Retrieval.
* <p>
* This package includes components for handling the retrieval stage in Retrieval
* Augmented Generation flows.
*/
@NonNullApi
@NonNullFields
package org.springframework.ai.rag.retrieval;
import org.springframework.lang.NonNullApi;
import org.springframework.lang.NonNullFields;

View File

@@ -54,6 +54,13 @@
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.ai</groupId>
<artifactId>spring-ai-rag</artifactId>
<version>${project.parent.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.ai</groupId>
<artifactId>spring-ai-starter-model-openai</artifactId>

99
spring-ai-rag/pom.xml Normal file
View File

@@ -0,0 +1,99 @@
<?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>
</parent>
<artifactId>spring-ai-rag</artifactId>
<packaging>jar</packaging>
<name>Spring AI RAG</name>
<description>Retrieval Augmented Generation (RAG) support 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

@@ -20,6 +20,7 @@ import java.util.List;
import org.junit.jupiter.api.Test;
import org.mockito.ArgumentCaptor;
import org.mockito.Mockito;
import org.springframework.ai.chat.client.ChatClient;
import org.springframework.ai.chat.messages.AssistantMessage;
@@ -47,8 +48,8 @@ class RetrievalAugmentationAdvisorTests {
@Test
void whenQueryTransformersContainNullElementsThenThrow() {
assertThatThrownBy(() -> RetrievalAugmentationAdvisor.builder()
.queryTransformers(mock(QueryTransformer.class), null)
.documentRetriever(mock(DocumentRetriever.class))
.queryTransformers(Mockito.mock(QueryTransformer.class), null)
.documentRetriever(Mockito.mock(DocumentRetriever.class))
.build()).isInstanceOf(IllegalArgumentException.class)
.hasMessageContaining("queryTransformers cannot contain null elements");
}
@@ -72,7 +73,7 @@ class RetrievalAugmentationAdvisorTests {
// Document Retriever
var documentContext = List.of(Document.builder().id("1").text("doc1").build(),
Document.builder().id("2").text("doc2").build());
var documentRetriever = mock(DocumentRetriever.class);
var documentRetriever = Mockito.mock(DocumentRetriever.class);
var queryCaptor = ArgumentCaptor.forClass(Query.class);
given(documentRetriever.retrieve(queryCaptor.capture())).willReturn(documentContext);

View File

@@ -120,7 +120,19 @@
<artifactId>micrometer-observation-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.ai</groupId>
<artifactId>spring-ai-advisors</artifactId>
<version>1.0.0-SNAPSHOT</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.ai</groupId>
<artifactId>spring-ai-advisors</artifactId>
<version>1.0.0-SNAPSHOT</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>