Extract core modules for improved architecture
Extract functionality from spring-ai-core into dedicated modules: - spring-ai-commons: Common utilities and document handling - spring-ai-model: Core model interfaces and implementations - spring-ai-vector-store: Vector store abstraction and implementation This modularization creates clearer responsibility boundaries and allows consumers to include only what they need. The restructuring will make the codebase easier to maintain and extend as the project grows.
This commit is contained in:
committed by
Soby Chacko
parent
8f20aabfdc
commit
7f3852ee4d
3
pom.xml
3
pom.xml
@@ -32,8 +32,11 @@
|
||||
<modules>
|
||||
<module>spring-ai-docs</module>
|
||||
<module>spring-ai-bom</module>
|
||||
<module>spring-ai-commons</module>
|
||||
<module>spring-ai-core</module>
|
||||
<module>spring-ai-model</module>
|
||||
<module>spring-ai-test</module>
|
||||
<module>spring-ai-vector-store</module>
|
||||
|
||||
<module>auto-configurations/common/spring-ai-autoconfigure-retry</module>
|
||||
|
||||
|
||||
108
spring-ai-commons/pom.xml
Normal file
108
spring-ai-commons/pom.xml
Normal file
@@ -0,0 +1,108 @@
|
||||
<?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:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
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-commons</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
<name>Spring AI Commons</name>
|
||||
<description>Common classes used across 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>
|
||||
|
||||
<dependencies>
|
||||
<!-- Spring Framework -->
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-context</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>io.micrometer</groupId>
|
||||
<artifactId>micrometer-core</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>io.micrometer</groupId>
|
||||
<artifactId>context-propagation</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>io.micrometer</groupId>
|
||||
<artifactId>micrometer-tracing-bridge-otel</artifactId>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
|
||||
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.module</groupId>
|
||||
<artifactId>jackson-module-jsonSchema</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.core</groupId>
|
||||
<artifactId>jackson-databind</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>
|
||||
|
||||
<!-- JTokkit for tokenization -->
|
||||
<dependency>
|
||||
<groupId>com.knuddels</groupId>
|
||||
<artifactId>jtokkit</artifactId>
|
||||
<version>${jtokkit.version}</version>
|
||||
</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>
|
||||
@@ -16,11 +16,9 @@
|
||||
|
||||
package org.springframework.ai.document;
|
||||
|
||||
import org.springframework.ai.vectorstore.VectorStore;
|
||||
|
||||
/**
|
||||
* Common set of metadata keys used in {@link Document}s by {@link DocumentReader}s and
|
||||
* {@link VectorStore}s.
|
||||
* VectorStores.
|
||||
*
|
||||
* @author Thomas Vitale
|
||||
* @since 1.0.0
|
||||
@@ -39,4 +39,4 @@ public interface BatchingStrategy {
|
||||
*/
|
||||
List<List<Document>> batch(List<Document> documents);
|
||||
|
||||
}
|
||||
}
|
||||
@@ -169,4 +169,4 @@ public class TokenCountBatchingStrategy implements BatchingStrategy {
|
||||
return batches;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -41,4 +41,4 @@ public interface Content {
|
||||
*/
|
||||
Map<String, Object> getMetadata();
|
||||
|
||||
}
|
||||
}
|
||||
@@ -25,4 +25,4 @@ public interface MediaContent extends Content {
|
||||
*/
|
||||
List<Media> getMedia();
|
||||
|
||||
}
|
||||
}
|
||||
@@ -151,4 +151,4 @@ public enum AiObservationAttributes {
|
||||
|
||||
// @formatter:on
|
||||
|
||||
}
|
||||
}
|
||||
@@ -56,4 +56,4 @@ public enum AiObservationEventNames {
|
||||
|
||||
// @formatter:on
|
||||
|
||||
}
|
||||
}
|
||||
@@ -51,4 +51,4 @@ public enum AiObservationMetricAttributes {
|
||||
|
||||
// @formatter:on
|
||||
|
||||
}
|
||||
}
|
||||
@@ -52,4 +52,4 @@ public enum AiObservationMetricNames {
|
||||
return this.value;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -72,4 +72,4 @@ public enum AiOperationType {
|
||||
|
||||
// @formatter:on
|
||||
|
||||
}
|
||||
}
|
||||
@@ -117,4 +117,4 @@ public enum AiProvider {
|
||||
|
||||
// @formatter:on
|
||||
|
||||
}
|
||||
}
|
||||
@@ -59,4 +59,4 @@ public enum AiTokenType {
|
||||
|
||||
// @formatter:on
|
||||
|
||||
}
|
||||
}
|
||||
@@ -58,4 +58,4 @@ public enum SpringAiKind {
|
||||
|
||||
// @formatter:on
|
||||
|
||||
}
|
||||
}
|
||||
@@ -119,4 +119,4 @@ public enum VectorStoreObservationAttributes {
|
||||
|
||||
// @formatter:on
|
||||
|
||||
}
|
||||
}
|
||||
@@ -47,4 +47,4 @@ public enum VectorStoreObservationEventNames {
|
||||
|
||||
// @formatter:on
|
||||
|
||||
}
|
||||
}
|
||||
@@ -151,4 +151,4 @@ public enum VectorStoreProvider {
|
||||
return this.value;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -63,4 +63,4 @@ public enum VectorStoreSimilarityMetric {
|
||||
|
||||
// @formatter:on
|
||||
|
||||
}
|
||||
}
|
||||
@@ -22,4 +22,4 @@
|
||||
package org.springframework.ai.observation.conventions;
|
||||
|
||||
import org.springframework.lang.NonNullApi;
|
||||
import org.springframework.lang.NonNullFields;
|
||||
import org.springframework.lang.NonNullFields;
|
||||
@@ -15,11 +15,6 @@
|
||||
*/
|
||||
|
||||
/**
|
||||
* Provides classes for observing events in the system.
|
||||
* Core observation abstractions.
|
||||
*/
|
||||
@NonNullApi
|
||||
@NonNullFields
|
||||
package org.springframework.ai.observation;
|
||||
|
||||
import org.springframework.lang.NonNullApi;
|
||||
import org.springframework.lang.NonNullFields;
|
||||
package org.springframework.ai.observation;
|
||||
@@ -78,4 +78,4 @@ public final class TracingHelper {
|
||||
return stringsJoiner.toString();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -87,4 +87,4 @@ public class JTokkitTokenCountEstimator implements TokenCountEstimator {
|
||||
return totalSize;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -48,4 +48,4 @@ public interface TokenCountEstimator {
|
||||
*/
|
||||
int estimate(Iterable<MediaContent> messages);
|
||||
|
||||
}
|
||||
}
|
||||
@@ -88,4 +88,4 @@ public abstract class JacksonUtils {
|
||||
return modules;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -54,4 +54,4 @@ public class TokenCountBatchingStrategyTests {
|
||||
.isInstanceOf(IllegalArgumentException.class);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -63,4 +63,4 @@ class AiOperationMetadataTests {
|
||||
.hasMessageContaining("provider cannot be null or empty");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -140,4 +140,4 @@ class TracingHelperTests {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -42,4 +42,4 @@ class JacksonUtilsKotlinTests {
|
||||
|
||||
data class User(val name: String, val age: Int)
|
||||
|
||||
}
|
||||
}
|
||||
4124
spring-ai-commons/src/test/resources/text_source.txt
Normal file
4124
spring-ai-commons/src/test/resources/text_source.txt
Normal file
File diff suppressed because it is too large
Load Diff
@@ -38,6 +38,24 @@
|
||||
|
||||
<dependencies>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.ai</groupId>
|
||||
<artifactId>spring-ai-commons</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.ai</groupId>
|
||||
<artifactId>spring-ai-vector-store</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.ai</groupId>
|
||||
<artifactId>spring-ai-model</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.module</groupId>
|
||||
<artifactId>jackson-module-jsonSchema</artifactId>
|
||||
@@ -165,35 +183,7 @@
|
||||
</dependencies>
|
||||
|
||||
<profiles>
|
||||
<profile>
|
||||
<id>antlr4</id>
|
||||
<activation>
|
||||
<activeByDefault>false</activeByDefault>
|
||||
</activation>
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.antlr</groupId>
|
||||
<artifactId>antlr4-maven-plugin</artifactId>
|
||||
<version>${antlr.version}</version>
|
||||
<configuration>
|
||||
<sourceDirectory>${basedir}/src/main/resources/antlr4</sourceDirectory>
|
||||
<outputDirectory>${basedir}/src/main/java</outputDirectory>
|
||||
<!--
|
||||
<outputDirectory>${project.build.directory}/generated-sources/antlr4</outputDirectory> -->
|
||||
<visitor>true</visitor>
|
||||
</configuration>
|
||||
<executions>
|
||||
<execution>
|
||||
<goals>
|
||||
<goal>antlr4</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</profile>
|
||||
<!-- ANTLR profile moved to spring-ai-vector-store -->
|
||||
</profiles>
|
||||
|
||||
|
||||
|
||||
128
spring-ai-model/pom.xml
Normal file
128
spring-ai-model/pom.xml
Normal file
@@ -0,0 +1,128 @@
|
||||
<?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-model</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
<name>Spring AI Model</name>
|
||||
<description>Core model interfaces and classes 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-commons</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.micrometer</groupId>
|
||||
<artifactId>micrometer-observation</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>io.micrometer</groupId>
|
||||
<artifactId>micrometer-tracing-bridge-otel</artifactId>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>io.projectreactor</groupId>
|
||||
<artifactId>reactor-core</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.github.victools</groupId>
|
||||
<artifactId>jsonschema-generator</artifactId>
|
||||
<version>${jsonschema.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.github.victools</groupId>
|
||||
<artifactId>jsonschema-module-jackson</artifactId>
|
||||
<version>${jsonschema.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.github.victools</groupId>
|
||||
<artifactId>jsonschema-module-swagger-2</artifactId>
|
||||
<version>${jsonschema.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>io.swagger.core.v3</groupId>
|
||||
<artifactId>swagger-annotations</artifactId>
|
||||
<version>${swagger-annotations.version}</version>
|
||||
</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>io.micrometer</groupId>
|
||||
<artifactId>micrometer-observation-test</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
@@ -162,4 +162,4 @@ public class DefaultUsage implements Usage {
|
||||
+ ", totalTokens=" + this.totalTokens + '}';
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -42,4 +42,4 @@ public class EmptyUsage implements Usage {
|
||||
return Map.of();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -65,4 +65,4 @@ public interface Usage {
|
||||
*/
|
||||
Object getNativeUsage();
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Provides a set of interfaces and classes for a generic API designed to interact with
|
||||
* various AI models. This package includes interfaces for handling AI model calls,
|
||||
* requests, responses, results, and associated metadata. It is designed to offer a
|
||||
* flexible and adaptable framework for interacting with different types of AI models,
|
||||
* abstracting the complexities involved in model invocation and result processing. The
|
||||
* use of generics enhances the API's capability to work with a wide range of models,
|
||||
* ensuring a broad applicability across diverse AI scenarios.
|
||||
*
|
||||
*/
|
||||
|
||||
package org.springframework.ai.model;
|
||||
@@ -259,4 +259,4 @@ public class DefaultUsageTests {
|
||||
// value
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user