升级说明

升级到 1.1.0-RC1

破坏性变更

文本转语音 (TTS) API 迁移

OpenAI 文本转语音实现已从特定于提供商的类迁移到共享接口。这使得编写可在多个 TTS 提供商(OpenAI、ElevenLabs 和未来的提供商)之间工作的可移植代码成为可能。

已移除的类

以下已弃用的类已从 org.springframework.ai.openai.audio.speech 包中移除

  • SpeechModel → 使用 TextToSpeechModel (来自 org.springframework.ai.audio.tts)

  • StreamingSpeechModel → 使用 StreamingTextToSpeechModel (来自 org.springframework.ai.audio.tts)

  • SpeechPrompt → 使用 TextToSpeechPrompt (来自 org.springframework.ai.audio.tts)

  • SpeechResponse → 使用 TextToSpeechResponse (来自 org.springframework.ai.audio.tts)

  • SpeechMessage → 使用 TextToSpeechMessage (来自 org.springframework.ai.audio.tts)

  • Speech (在 org.springframework.ai.openai.audio.speech 中) → 使用 Speech (来自 org.springframework.ai.audio.tts)

此外,为了与其他 TTS 提供商保持一致,所有 OpenAI TTS 组件中的 speed 参数类型已从 Float 更改为 Double

迁移步骤
  1. 更新导入:将所有来自 org.springframework.ai.openai.audio.speech. 的导入替换为 org.springframework.ai.audio.tts.

  2. 更新类型引用:将旧类名的所有出现替换为新类名

    Find:    SpeechModel
    Replace: TextToSpeechModel
    
    Find:    StreamingSpeechModel
    Replace: StreamingTextToSpeechModel
    
    Find:    SpeechPrompt
    Replace: TextToSpeechPrompt
    
    Find:    SpeechResponse
    Replace: TextToSpeechResponse
    
    Find:    SpeechMessage
    Replace: TextToSpeechMessage
  3. 更新速度参数:从 Float 更改为 Double

    Find:    .speed(1.0f)
    Replace: .speed(1.0)
    
    Find:    Float speed
    Replace: Double speed
  4. 更新依赖注入:如果您注入 SpeechModel,请更新为 TextToSpeechModel

    // Before
    public MyService(SpeechModel speechModel) { ... }
    
    // After
    public MyService(TextToSpeechModel textToSpeechModel) { ... }
好处
  • 可移植性:一次编写代码,轻松在 OpenAI、ElevenLabs 或其他 TTS 提供商之间切换

  • 一致性:与 ChatModel 和其他 Spring AI 抽象的模式相同

  • 类型安全:通过适当的接口实现改进了类型层次结构

  • 面向未来:新的 TTS 提供商将自动与您现有的代码一起工作

其他资源

有关包含详细代码示例的全面迁移指南,请参阅

升级到 1.0.0-SNAPSHOT

概述

1.0.0-SNAPSHOT 版本包括对 artifact ID、包名和模块结构的重大更改。本节提供使用 SNAPSHOT 版本的具体指导。

添加 Snapshot 仓库

要使用 1.0.0-SNAPSHOT 版本,您需要将 snapshot 仓库添加到构建文件中。有关详细说明,请参阅入门指南中的 Snapshots - Add Snapshot Repositories 部分。

更新依赖管理

在您的构建配置中将 Spring AI BOM 版本更新为 1.0.0-SNAPSHOT。有关配置依赖管理的详细说明,请参阅入门指南中的 Dependency Management 部分。

Artifact ID、包和模块更改

1.0.0-SNAPSHOT 包括对 artifact ID、包名和模块结构的更改。

有关详细信息,请参阅: - 通用 Artifact ID 更改 - 通用包更改 - 通用模块结构

升级到 1.0.0-RC1

您可以使用 OpenRewrite recipe 自动化升级到 1.0.0-RC1 的过程。此 recipe 有助于应用此版本的许多必要代码更改。在 Arconia Spring AI Migrations 找到 recipe 和使用说明。

重大更改

聊天客户端和顾问

影响最终用户代码的主要更改是

  • VectorStoreChatMemoryAdvisor

    • 常量 CHAT_MEMORY_RETRIEVE_SIZE_KEY 已重命名为 TOP_K

    • 常量 DEFAULT_CHAT_MEMORY_RESPONSE_SIZE (值: 100) 已重命名为 DEFAULT_TOP_K,新默认值为 20。

  • 常量 CHAT_MEMORY_CONVERSATION_ID_KEY 已重命名为 CONVERSATION_ID 并从 AbstractChatMemoryAdvisor 移动到 ChatMemory 接口。更新您的导入以使用 org.springframework.ai.chat.memory.ChatMemory.CONVERSATION_ID

顾问中的自包含模板

执行提示增强的内置顾问已更新为使用自包含模板。目标是使每个顾问都能够执行模板操作,而不影响也不受其他顾问中模板和提示决策的影响。

如果您为以下顾问提供自定义模板,则需要更新它们以确保包含所有预期的占位符。

  • QuestionAnswerAdvisor 需要一个包含以下占位符的模板(参见 更多详细信息

    • 一个 query 占位符,用于接收用户问题。

    • 一个 question_answer_context 占位符用于接收检索到的上下文。

  • PromptChatMemoryAdvisor 需要一个包含以下占位符的模板(参见 更多详细信息

    • 一个 instructions 占位符用于接收原始系统消息。

    • 一个 memory 占位符用于接收检索到的对话内存。

  • VectorStoreChatMemoryAdvisor 需要一个包含以下占位符的模板(参见 更多详细信息

    • 一个 instructions 占位符用于接收原始系统消息。

    • 一个 long_term_memory 占位符用于接收检索到的对话内存。

可观察性

  • 重构了内容观察以使用日志而不是跟踪(ca843e8

    • 将内容观察过滤器替换为日志处理程序

    • 重命名配置属性以更好地反映其目的

      • include-promptlog-prompt

      • include-completionlog-completion

      • include-query-responselog-query-response

    • 添加了 TracingAwareLoggingObservationHandler 用于跟踪感知日志

    • micrometer-tracing-bridge-otel 替换为 micrometer-tracing

    • 删除了基于事件的跟踪,转而采用直接日志记录

    • 删除了对 OTel SDK 的直接依赖

    • 在观察属性中将 includePrompt 重命名为 logPrompt(在 ChatClientBuilderPropertiesChatObservationPropertiesImageObservationProperties 中)

聊天内存仓库模块和自动配置重命名

我们通过在整个代码库中添加仓库后缀来标准化聊天内存组件的命名模式。此更改影响 Cassandra、JDBC 和 Neo4j 实现,影响 artifact ID、Java 包名和类名以提高清晰度。

Artifact ID

所有与内存相关的 artifact 现在都遵循一致的模式

  • spring-ai-model-chat-memory-spring-ai-model-chat-memory-repository-

  • spring-ai-autoconfigure-model-chat-memory-spring-ai-autoconfigure-model-chat-memory-repository-

  • spring-ai-starter-model-chat-memory-spring-ai-starter-model-chat-memory-repository-

Java 包

  • 包路径现在包含 .repository.

  • 示例:org.springframework.ai.chat.memory.jdbcorg.springframework.ai.chat.memory.repository.jdbc

配置类

  • 主要自动配置类现在使用 Repository 后缀

  • 示例:JdbcChatMemoryAutoConfigurationJdbcChatMemoryRepositoryAutoConfiguration

属性

  • 配置属性从 spring.ai.chat.memory.<storage>…​ 重命名为 spring.ai.chat.memory.repository.<storage>…​

需要迁移: - 更新您的 Maven/Gradle 依赖项以使用新的 artifact ID。 - 更新所有使用旧包或类名的导入、类引用或配置。

消息聚合器重构

更改
  • MessageAggregator 类已从 spring-ai-client-chat 模块中的 org.springframework.ai.chat.model 包移动到 spring-ai-model 模块(相同的包名)

  • aggregateChatClientResponse 方法已从 MessageAggregator 中移除,并移动到 org.springframework.ai.chat.client 包中的新类 ChatClientMessageAggregator

迁移指南

如果您直接使用 MessageAggregatoraggregateChatClientResponse 方法,则需要改用新的 ChatClientMessageAggregator

// Before
new MessageAggregator().aggregateChatClientResponse(chatClientResponses, aggregationHandler);

// After
new ChatClientMessageAggregator().aggregateChatClientResponse(chatClientResponses, aggregationHandler);

不要忘记添加适当的导入

import org.springframework.ai.chat.client.ChatClientMessageAggregator;

Watson

Watson AI 模型被移除,因为它基于较旧的文本生成,这被认为是过时的,因为有新的聊天生成模型可用。希望 Watson 会在 Spring AI 的未来版本中重新出现

MoonShot 和 QianFan

Moonshot 和 Qianfan 已被移除,因为它们无法在中国境外访问。这些已移至 Spring AI 社区仓库。

已移除的向量存储

  • 移除 HanaDB 向量存储自动配置 (f3b4624)

内存管理

  • 移除 CassandraChatMemory 实现 (11e3c8f)

  • 简化了聊天内存顾问层次结构并移除了已弃用的 API (848a3fd)

  • 移除了 JdbcChatMemory 中的弃用 (356a68f)

  • 重构了聊天内存仓库 artifact 以提高清晰度 (2d517ee)

  • 重构了聊天内存仓库自动配置和 Spring Boot 启动器以提高清晰度 (f6dba1b)

消息和模板 API

  • 移除了已弃用的 UserMessage 构造函数 (06edee4)

  • 移除了已弃用的 PromptTemplate 构造函数 (722c77e)

  • 移除了 Media 中的已弃用方法 (228ef10)

  • 重构了 StTemplateRenderer:将 supportStFunctions 重命名为 validateStFunctions (0e15197)

  • 移除了移动后剩余的 TemplateRender 接口 (52675d8)

额外的客户端 API 更改

  • 移除了 ChatClient 和 Advisors 中的弃用 (4fe74d8)

  • 移除了 OllamaApi 和 AnthropicApi 中的弃用 (46be898)

包结构更改

  • 移除了 spring-ai-model 中的包间依赖循环 (ebfa5b9)

  • 将 MessageAggregator 移动到 spring-ai-model 模块 (54e5c07)

依赖关系

  • 移除了 spring-ai-openai 中未使用的 json-path 依赖项 (9de13d1)

行为更改

Azure OpenAI

  • 为 Azure OpenAI 添加了 Entra ID 身份管理,并进行了干净的自动配置 (3dc86d3)

一般清理

升级到 1.0.0-M8

您可以使用 OpenRewrite recipe 自动化升级到 1.0.0-M8 的过程。此 recipe 有助于应用此版本的许多必要代码更改。在 Arconia Spring AI Migrations 找到 recipe 和使用说明。

重大更改

从 Spring AI 1.0 M7 升级到 1.0 M8 时,以前注册过工具回调的用户会遇到重大更改,导致工具调用功能悄然失败。这特别影响了使用已弃用 tools() 方法的代码。

示例

以下是一个在 M7 中有效但在 M8 中不再按预期工作的代码示例

// This worked in M7 but silently fails in M8
ChatClient chatClient = new OpenAiChatClient(api)
    .tools(List.of(
        new Tool("get_current_weather", "Get the current weather in a given location",
            new ToolSpecification.ToolParameter("location", "The city and state, e.g. San Francisco, CA", true))
    ))
    .toolCallbacks(List.of(
        new ToolCallback("get_current_weather", (toolName, params) -> {
            // Weather retrieval logic
            return Map.of("temperature", 72, "unit", "fahrenheit", "description", "Sunny");
        })
    ));

解决方案

解决方案是使用 toolSpecifications() 方法而不是已弃用的 tools() 方法

// This works in M8
ChatClient chatClient = new OpenAiChatClient(api)
    .toolSpecifications(List.of(
        new Tool("get_current_weather", "Get the current weather in a given location",
            new ToolSpecification.ToolParameter("location", "The city and state, e.g. San Francisco, CA", true))
    ))
    .toolCallbacks(List.of(
        new ToolCallback("get_current_weather", (toolName, params) -> {
            // Weather retrieval logic
            return Map.of("temperature", 72, "unit", "fahrenheit", "description", "Sunny");
        })
    ));

已移除的实现和 API

内存管理

  • 移除 CassandraChatMemory 实现 (11e3c8f)

  • 简化了聊天内存顾问层次结构并移除了已弃用的 API (848a3fd)

  • 移除了 JdbcChatMemory 中的弃用 (356a68f)

  • 重构了聊天内存仓库 artifact 以提高清晰度 (2d517ee)

  • 重构了聊天内存仓库自动配置和 Spring Boot 启动器以提高清晰度 (f6dba1b)

客户端 API

  • 移除了 ChatClient 和 Advisors 中的弃用 (4fe74d8)

  • 对聊天客户端工具调用的重大更改 (5b7849d)

  • 移除了 OllamaApi 和 AnthropicApi 中的弃用 (46be898)

消息和模板 API

  • 移除了已弃用的 UserMessage 构造函数 (06edee4)

  • 移除了已弃用的 PromptTemplate 构造函数 (722c77e)

  • 移除了 Media 中的已弃用方法 (228ef10)

  • 重构了 StTemplateRenderer:将 supportStFunctions 重命名为 validateStFunctions (0e15197)

  • 移除了移动后剩余的 TemplateRender 接口 (52675d8)

模型实现

  • 移除 Watson 文本生成模型 (9e71b16)

  • 移除 Qianfan 代码 (bfcaad7)

  • 移除 HanaDB 向量存储自动配置 (f3b4624)

  • 从 OpenAiApi 中移除 Deepseek 选项 (59b36d1)

包结构更改

  • 移除了 spring-ai-model 中的包间依赖循环 (ebfa5b9)

  • 将 MessageAggregator 移动到 spring-ai-model 模块 (54e5c07)

依赖关系

  • 移除了 spring-ai-openai 中未使用的 json-path 依赖项 (9de13d1)

行为更改

可观察性

  • 重构了内容观察以使用日志而不是跟踪(ca843e8

    • 将内容观察过滤器替换为日志处理程序

    • 重命名配置属性以更好地反映其目的

      • include-promptlog-prompt

      • include-completionlog-completion

      • include-query-responselog-query-response

    • 添加了 TracingAwareLoggingObservationHandler 用于跟踪感知日志

    • micrometer-tracing-bridge-otel 替换为 micrometer-tracing

    • 删除了基于事件的跟踪,转而采用直接日志记录

    • 删除了对 OTel SDK 的直接依赖

    • 在观察属性中将 includePrompt 重命名为 logPrompt(在 ChatClientBuilderPropertiesChatObservationPropertiesImageObservationProperties 中)

Azure OpenAI

  • 为 Azure OpenAI 添加了 Entra ID 身份管理,并进行了干净的自动配置 (3dc86d3)

一般清理

  • 移除了 1.0.0-M8 的所有弃用 (76bee8c)

  • 一般弃用清理 (b6ce7f3)

升级到 1.0.0-M7

变更概述

Spring AI 1.0.0-M7 是 RC1 和 GA 版本之前的最后一个里程碑版本。它引入了对 artifact ID、包名和模块结构的几项重要更改,这些更改将在最终版本中保留。

Artifact ID、包和模块更改

1.0.0-M7 包含与 1.0.0-SNAPSHOT 相同的结构更改。

有关详细信息,请参阅: - 通用 Artifact ID 更改 - 通用包更改 - 通用模块结构

MCP Java SDK 升级到 0.9.0

Spring AI 1.0.0-M7 现在使用 MCP Java SDK 0.9.0 版本,该版本包含与以前版本不同的重大更改。如果您在应用程序中使用 MCP,则需要更新代码以适应这些更改。

主要变化包括

接口重命名

  • ClientMcpTransportMcpClientTransport

  • ServerMcpTransportMcpServerTransport

  • DefaultMcpSessionMcpClientSessionMcpServerSession

  • 所有 *Registration 类 → *Specification

服务器创建更改

  • 使用 McpServerTransportProvider 而不是 ServerMcpTransport

// Before
ServerMcpTransport transport = new WebFluxSseServerTransport(objectMapper, "/mcp/message");
var server = McpServer.sync(transport)
    .serverInfo("my-server", "1.0.0")
    .build();

// After
McpServerTransportProvider transportProvider = new WebFluxSseServerTransportProvider(objectMapper, "/mcp/message");
var server = McpServer.sync(transportProvider)
    .serverInfo("my-server", "1.0.0")
    .build();

处理程序签名更改

所有处理程序现在都将 exchange 参数作为第一个参数接收

// Before
.tool(calculatorTool, args -> new CallToolResult("Result: " + calculate(args)))

// After
.tool(calculatorTool, (exchange, args) -> new CallToolResult("Result: " + calculate(args)))

通过 Exchange 进行客户端交互

以前在服务器上可用的方法现在通过 exchange 对象访问

// Before
ClientCapabilities capabilities = server.getClientCapabilities();
CreateMessageResult result = server.createMessage(new CreateMessageRequest(...));

// After
ClientCapabilities capabilities = exchange.getClientCapabilities();
CreateMessageResult result = exchange.createMessage(new CreateMessageRequest(...));

根更改处理程序

// Before
.rootsChangeConsumers(List.of(
    roots -> System.out.println("Roots changed: " + roots)
))

// After
.rootsChangeHandlers(List.of(
    (exchange, roots) -> System.out.println("Roots changed: " + roots)
))

有关迁移 MCP 代码的完整指南,请参阅 MCP 迁移指南

启用/禁用模型自动配置

以前用于启用/禁用模型自动配置的配置属性已移除

  • spring.ai.<provider>.chat.enabled

  • spring.ai.<provider>.embedding.enabled

  • spring.ai.<provider>.image.enabled

  • spring.ai.<provider>.moderation.enabled

默认情况下,如果在类路径中找到模型提供商(例如,OpenAI、Ollama),则其相应模型类型(聊天、嵌入等)的自动配置将启用。如果存在同一模型类型的多个提供商(例如,spring-ai-openai-spring-boot-starterspring-ai-ollama-spring-boot-starter),您可以使用以下属性来选择哪个提供商的自动配置应处于活动状态,从而有效地禁用其他提供商的该特定模型类型。

要完全禁用特定模型类型的自动配置,即使只有一个提供商存在,也请将相应属性设置为与类路径上任何提供商都不匹配的值(例如,nonedisabled)。

您可以参考 SpringAIModels 枚举以获取已知提供商值的列表。

  • spring.ai.model.audio.speech=<model-provider|none>

  • spring.ai.model.audio.transcription=<model-provider|none>

  • spring.ai.model.chat=<model-provider|none>

  • spring.ai.model.embedding=<model-provider|none>

  • spring.ai.model.embedding.multimodal=<model-provider|none>

  • spring.ai.model.embedding.text=<model-provider|none>

  • spring.ai.model.image=<model-provider|none>

  • spring.ai.model.moderation=<model-provider|none>

使用 AI 自动化升级

您可以使用 Claude Code CLI 工具和提供的提示自动化升级到 1.0.0-M7 的过程

  1. 下载 Claude Code CLI 工具

  2. update-to-m7.txt 文件复制提示

  3. 将提示粘贴到 Claude Code CLI 中

  4. AI 将分析您的项目并进行必要的更改

自动化升级提示目前处理 artifact ID 更改、包重定位和模块结构更改,但尚不包括升级到 MCP 0.9.0 的自动更改。如果您正在使用 MCP,则需要按照 MCP Java SDK 升级 部分的指导手动更新代码。

跨版本的通用更改

Artifact ID 更改

Spring AI 启动器 artifact 的命名模式已更改。您需要根据以下模式更新您的依赖项

  • 模型启动器:spring-ai-{model}-spring-boot-starterspring-ai-starter-model-{model}

  • 向量存储启动器:spring-ai-{store}-store-spring-boot-starterspring-ai-starter-vector-store-{store}

  • MCP 启动器:spring-ai-mcp-{type}-spring-boot-starterspring-ai-starter-mcp-{type}

示例

  • Maven

  • Gradle

<!-- BEFORE -->
<dependency>
    <groupId>org.springframework.ai</groupId>
    <artifactId>spring-ai-openai-spring-boot-starter</artifactId>
</dependency>

<!-- AFTER -->
<dependency>
    <groupId>org.springframework.ai</groupId>
    <artifactId>spring-ai-starter-model-openai</artifactId>
</dependency>
// BEFORE
implementation 'org.springframework.ai:spring-ai-openai-spring-boot-starter'
implementation 'org.springframework.ai:spring-ai-redis-store-spring-boot-starter'

// AFTER
implementation 'org.springframework.ai:spring-ai-starter-model-openai'
implementation 'org.springframework.ai:spring-ai-starter-vector-store-redis'

Spring AI 自动配置 Artifact 的更改

Spring AI 自动配置已从单个整体 artifact 更改为每个模型、向量存储和其他组件的单独自动配置 artifact。进行此更改是为了最大程度地减少不同版本的依赖库冲突的影响,例如 Google Protocol Buffers、Google RPC 等。通过将自动配置分离到特定于组件的 artifact 中,您可以避免引入不必要的依赖项并降低应用程序中版本冲突的风险。

原始的整体 artifact 不再可用

<!-- NO LONGER AVAILABLE -->
<dependency>
    <groupId>org.springframework.ai</groupId>
    <artifactId>spring-ai-spring-boot-autoconfigure</artifactId>
    <version>${project.version}</version>
</dependency>

相反,每个组件现在都有自己的自动配置 artifact,遵循以下模式

  • 模型自动配置:spring-ai-autoconfigure-model-{model}

  • 向量存储自动配置:spring-ai-autoconfigure-vector-store-{store}

  • MCP 自动配置:spring-ai-autoconfigure-mcp-{type}

新自动配置 Artifact 的示例

  • 模型

  • 向量存储

  • MCP

<dependency>
    <groupId>org.springframework.ai</groupId>
    <artifactId>spring-ai-autoconfigure-model-openai</artifactId>
</dependency>

<dependency>
    <groupId>org.springframework.ai</groupId>
    <artifactId>spring-ai-autoconfigure-model-anthropic</artifactId>
</dependency>

<dependency>
    <groupId>org.springframework.ai</groupId>
    <artifactId>spring-ai-autoconfigure-model-vertex-ai</artifactId>
</dependency>
<dependency>
    <groupId>org.springframework.ai</groupId>
    <artifactId>spring-ai-autoconfigure-vector-store-redis</artifactId>
</dependency>

<dependency>
    <groupId>org.springframework.ai</groupId>
    <artifactId>spring-ai-autoconfigure-vector-store-pgvector</artifactId>
</dependency>

<dependency>
    <groupId>org.springframework.ai</groupId>
    <artifactId>spring-ai-autoconfigure-vector-store-chroma</artifactId>
</dependency>
<dependency>
    <groupId>org.springframework.ai</groupId>
    <artifactId>spring-ai-autoconfigure-mcp-client</artifactId>
</dependency>

<dependency>
    <groupId>org.springframework.ai</groupId>
    <artifactId>spring-ai-autoconfigure-mcp-server</artifactId>
</dependency>
在大多数情况下,您不需要显式添加这些自动配置依赖项。它们在使用相应的启动器依赖项时会传递性地包含。

包名更改

您的 IDE 应该帮助重构到新的包位置。

  • KeywordMetadataEnricherSummaryMetadataEnricher 已从 org.springframework.ai.transformer 移动到 org.springframework.ai.chat.transformer

  • ContentMediaContentMedia 已从 org.springframework.ai.model 移动到 org.springframework.ai.content

模块结构

项目对其模块和 artifact 结构进行了重大更改。以前,spring-ai-core 包含所有中心接口,但现在已将其拆分为专门的领域模块,以减少应用程序中不必要的依赖项。

Spring AI Dependencies

spring-ai-commons

基本模块,不依赖于其他 Spring AI 模块。包含: - 核心领域模型(DocumentTextSplitter) - JSON 工具和资源处理 - 结构化日志记录和可观察性支持

spring-ai-model

提供 AI 功能抽象: - ChatModelEmbeddingModelImageModel 等接口 - 消息类型和提示模板 - 函数调用框架(ToolDefinitionToolCallback) - 内容过滤和观察支持

spring-ai-vector-store

统一向量数据库抽象: - 用于相似性搜索的 VectorStore 接口 - 具有 SQL 样表达式的高级过滤 - 用于内存使用的 SimpleVectorStore - 嵌入的批量处理支持

spring-ai-client-chat

高级对话 AI API: - ChatClient 接口 - 通过 ChatMemory 进行对话持久化 - 使用 OutputConverter 进行响应转换 - 基于顾问的拦截 - 同步和响应式流支持

spring-ai-advisors-vector-store

将聊天与向量存储桥接以用于 RAG: - QuestionAnswerAdvisor:将上下文注入提示 - VectorStoreChatMemoryAdvisor:存储/检索对话历史记录

spring-ai-model-chat-memory-cassandra

Apache Cassandra 对 ChatMemory 的持久化: - CassandraChatMemory 实现 - 使用 Cassandra 的 QueryBuilder 进行类型安全的 CQL ==== spring-ai-model-chat-memory-neo4j

Neo4j 图数据库用于聊天对话的持久化。

spring-ai-rag

用于检索增强生成 (Retrieval Augmented Generation) 的综合框架: - RAG 管道的模块化架构 - RetrievalAugmentationAdvisor 作为主要入口点 - 具有可组合组件的函数式编程原则

依赖结构

依赖层次结构可概括为

  • spring-ai-commons (基础)

  • spring-ai-model (依赖于 commons)

  • spring-ai-vector-storespring-ai-client-chat (都依赖于 model)

  • spring-ai-advisors-vector-storespring-ai-rag (依赖于 client-chat 和 vector-store)

  • spring-ai-model-chat-memory-* 模块 (依赖于 client-chat)

ToolContext 更改

ToolContext 类已增强以支持显式和隐式工具解析。工具现在可以

  1. 显式包含:在提示中显式请求并包含在模型调用中的工具。

  2. 隐式可用:可用于运行时动态解析的工具,但除非显式请求,否则永远不会包含在任何模型调用中。

从 1.0.0-M7 开始,只有当工具在提示中显式请求或在调用中显式包含时,才会将其包含在对模型的调用中。

此外,ToolContext 类现在已被标记为 final,并且不能再被扩展。它从来不应该被子类化。您可以在实例化 ToolContext 时以 Map<String, Object> 的形式添加所有需要的上下文数据。有关更多信息,请查看 [文档](docs.spring.io/spring-ai/reference/api/tools.html#_tool_context)。

升级到 1.0.0-M6

Usage 接口和 DefaultUsage 实现的更改

Usage 接口及其默认实现 DefaultUsage 经历了以下更改

  1. 方法重命名

    • getGenerationTokens() 现在是 getCompletionTokens()

  2. 类型更改

    • DefaultUsage 中的所有令牌计数字段都从 Long 更改为 Integer

      • promptTokens

      • completionTokens (以前是 generationTokens)

      • totalTokens

所需操作

  • 将所有对 getGenerationTokens() 的调用替换为 getCompletionTokens()

  • 更新 DefaultUsage 构造函数调用

// Old (M5)
new DefaultUsage(Long promptTokens, Long generationTokens, Long totalTokens)

// New (M6)
new DefaultUsage(Integer promptTokens, Integer completionTokens, Integer totalTokens)
有关处理 Usage 的更多信息,请参阅 此处

JSON 序列化/反序列化更改

虽然 M6 保持了 generationTokens 字段的 JSON 反序列化向后兼容性,但该字段将在 M7 中移除。任何使用旧字段名的持久化 JSON 文档都应更新为使用 completionTokens

新 JSON 格式的示例

{
  "promptTokens": 100,
  "completionTokens": 50,
  "totalTokens": 150
}

FunctionCallingOptions 用于工具调用的用法更改

每个 ChatModel 实例在构造时接受一个可选的 ChatOptionsFunctionCallingOptions 实例,可用于配置用于调用模型的默认工具。

在 1.0.0-M6 之前

  • 通过默认 FunctionCallingOptions 实例的 functions() 方法传递的任何工具都包含在该 ChatModel 实例对模型的每次调用中,可能会被运行时选项覆盖。

  • 通过默认 FunctionCallingOptions 实例的 functionCallbacks() 方法传递的任何工具仅用于运行时动态解析(参见 工具解析),但除非明确请求,否则不会包含在任何模型调用中。

从 1.0.0-M6 开始

  • 通过默认 FunctionCallingOptions 实例的 functions() 方法或 functionCallbacks() 传递的任何工具现在都以相同的方式处理:它们包含在该 ChatModel 实例对模型的每次调用中,可能会被运行时选项覆盖。这样,工具包含在对模型的调用中的方式就保持了一致性,并防止了由于 functionCallbacks() 与所有其他选项之间的行为差异而造成的混淆。

如果您想让一个工具可用于运行时动态解析,并且仅在明确请求时才将其包含在对模型的聊天请求中,您可以使用 工具解析 中描述的策略之一。

1.0.0-M6 引入了处理工具调用的新 API。除了上述情况外,旧 API 在所有场景中都保持向后兼容性。旧 API 仍然可用,但它们已被弃用,并将在 1.0.0-M7 中移除。

移除已弃用的 Amazon Bedrock 聊天模型

从 1.0.0-M6 开始,Spring AI 转换为使用 Amazon Bedrock 的 Converse API 进行 Spring AI 中的所有聊天对话实现。所有 Amazon Bedrock 聊天模型都已移除,除了 Cohere 和 Titan 的嵌入模型。

有关使用聊天模型的信息,请参阅 Bedrock Converse 文档。

更改为使用 Spring Boot 3.4.2 进行依赖管理

Spring AI 更新为使用 Spring Boot 3.4.2 进行依赖管理。您可以参考 此处 获取 Spring Boot 3.4.2 管理的依赖项。

所需操作

  • 如果您要升级到 Spring Boot 3.4.2,请务必参考 文档,了解配置 REST 客户端所需的更改。值得注意的是,如果类路径上没有 HTTP 客户端库,这可能会导致使用 JdkClientHttpRequestFactory,而以前会使用 SimpleClientHttpRequestFactory。要切换到使用 SimpleClientHttpRequestFactory,您需要设置 spring.http.client.factory=simple

  • 如果您使用的是不同版本的 Spring Boot(例如 Spring Boot 3.3.x)并且需要特定版本的依赖项,您可以在构建配置中覆盖它。

向量存储 API 更改

在 1.0.0-M6 版本中,VectorStore 接口中的 delete 方法已被修改为 void 操作,而不是返回 Optional<Boolean>。如果您的代码以前检查了删除操作的返回值,则需要移除此检查。现在,如果删除失败,该操作将抛出异常,从而提供更直接的错误处理。

1.0.0-M6 之前

Optional<Boolean> result = vectorStore.delete(ids);
if (result.isPresent() && result.get()) {
    // handle successful deletion
}

1.0.0-M6 及之后

vectorStore.delete(ids);
// deletion successful if no exception is thrown

升级到 1.0.0.M5

  • Vector Builders 已重构以保持一致性。

  • 当前 VectorStore 实现构造函数已被弃用,请使用构建器模式。

  • VectorStore 实现包已移动到唯一的包名,避免了跨 artifact 的冲突。例如 org.springframework.ai.vectorstoreorg.springframework.ai.pgvector.vectorstore

升级到 1.0.0.RC3

  • 可移植聊天选项(frequencyPenaltypresencePenaltytemperaturetopP)的类型已从 Float 更改为 Double

升级到 1.0.0.M2

  • Chroma 向量存储的配置前缀已从 spring.ai.vectorstore.chroma.store 更改为 spring.ai.vectorstore.chroma,以与其他向量存储的命名约定保持一致。

  • 能够初始化模式的向量存储上的 initialize-schema 属性的默认值现在设置为 false。这意味着应用程序现在需要显式选择在支持的向量存储上进行模式初始化,如果期望在应用程序启动时创建模式。并非所有向量存储都支持此属性。有关更多详细信息,请参阅相应的向量存储文档。以下是目前不支持 initialize-schema 属性的向量存储。

    1. Hana

    2. Pinecone

    3. Weaviate

  • 在 Bedrock Jurassic 2 中,聊天选项 countPenaltyfrequencyPenaltypresencePenalty 已重命名为 countPenaltyOptionsfrequencyPenaltyOptionspresencePenaltyOptions。此外,聊天选项 stopSequences 的类型已从 String[] 更改为 List<String>

  • 在 Azure OpenAI 中,聊天选项 frequencyPenaltypresencePenalty 的类型已从 Double 更改为 Float,与其他所有实现保持一致。

升级到 1.0.0.M1

在发布 1.0.0 M1 的征程中,我们做了一些重大更改。抱歉,但这是为了更好!

ChatClient 更改

进行了一项重大更改,将“旧”的 ChatClient 功能移动到 ChatModel 中。现在“新”的 ChatClient 接受一个 ChatModel 实例。这样做是为了支持一种流式 API,用于以类似于 Spring 生态系统中其他客户端类(如 RestClientWebClientJdbcClient)的方式创建和执行提示。有关流式 API 的更多信息,请参阅 [JavaDoc](docs.spring.io/spring-ai/docs/api),适当的参考文档即将推出。

我们将“旧”的 ModelClient 重命名为 Model,并重命名了实现类,例如 ImageClient 重命名为 ImageModelModel 实现表示在 Spring AI API 和底层 AI 模型 API 之间转换的可移植性层。

一个新的 model 包,其中包含接口和基类,以支持为任何输入/输出数据类型组合创建 AI 模型客户端。目前,聊天和图像模型包实现了这一点。我们很快就会将嵌入包更新为这个新模型。

一种新的“可移植选项”设计模式。我们希望在不同基于聊天的 AI 模型之间,ModelCall 中尽可能提供可移植性。有一组通用的生成选项,然后是特定于模型提供商的选项。使用了一种“鸭子类型”方法。模型包中的 ModelOptions 是一个标记接口,指示此类的实现将为模型提供选项。请参阅 ImageOptions,这是一个子接口,定义了所有文本→图像 ImageModel 实现的可移植选项。然后 StabilityAiImageOptionsOpenAiImageOptions 提供了特定于每个模型提供商的选项。所有选项类都是通过流式 API 构建器创建的,所有选项都可以传递到可移植的 ImageModel API 中。这些选项数据类型用于 ImageModel 实现的自动配置/配置属性中。

Artifact 名称更改

重命名了 POM artifact 名称: - spring-ai-qdrant → spring-ai-qdrant-store - spring-ai-cassandra → spring-ai-cassandra-store - spring-ai-pinecone → spring-ai-pinecone-store - spring-ai-redis → spring-ai-redis-store - spring-ai-qdrant → spring-ai-qdrant-store - spring-ai-gemfire → spring-ai-gemfire-store - spring-ai-azure-vector-store-spring-boot-starter → spring-ai-azure-store-spring-boot-starter - spring-ai-redis-spring-boot-starter → spring-ai-starter-vector-store-redis

升级到 0.8.1

以前的 spring-ai-vertex-ai 已重命名为 spring-ai-vertex-ai-palm2spring-ai-vertex-ai-spring-boot-starter 已重命名为 spring-ai-vertex-ai-palm2-spring-boot-starter

因此,您需要更改依赖项,从

<dependency>
    <groupId>org.springframework.ai</groupId>
    <artifactId>spring-ai-vertex-ai</artifactId>
</dependency>

<dependency>
    <groupId>org.springframework.ai</groupId>
    <artifactId>spring-ai-vertex-ai-palm2</artifactId>
</dependency>

Palm2 模型的相关 Boot 启动器已从

<dependency>
    <groupId>org.springframework.ai</groupId>
    <artifactId>spring-ai-vertex-ai-spring-boot-starter</artifactId>
</dependency>

<dependency>
    <groupId>org.springframework.ai</groupId>
    <artifactId>spring-ai-vertex-ai-palm2-spring-boot-starter</artifactId>
</dependency>
  • 重命名的类(2024 年 1 月 3 日)

    • VertexAiApi → VertexAiPalm2Api

    • VertexAiClientChat → VertexAiPalm2ChatClient

    • VertexAiEmbeddingClient → VertexAiPalm2EmbeddingClient

    • VertexAiChatOptions → VertexAiPalm2ChatOptions

升级到 0.8.0

2024 年 1 月 24 日更新

  • promptmessages 以及 metadata 包移动到 org.springframework.ai.chat 的子包

  • 新功能是 文本到图像 客户端。类是 OpenAiImageModelStabilityAiImageModel。有关用法,请参阅集成测试,文档即将推出。

  • 一个新的 model 包,其中包含接口和基类,以支持为任何输入/输出数据类型组合创建 AI 模型客户端。目前,聊天和图像模型包实现了这一点。我们很快就会将嵌入包更新为这个新模型。

  • 一种新的“可移植选项”设计模式。我们希望在不同基于聊天的 AI 模型之间,ModelCall 中尽可能提供可移植性。有一组通用的生成选项,然后是特定于模型提供商的选项。使用了一种“鸭子类型”方法。模型包中的 ModelOptions 是一个标记接口,指示此类的实现将为模型提供选项。请参阅 ImageOptions,这是一个子接口,定义了所有文本→图像 ImageModel 实现的可移植选项。然后 StabilityAiImageOptionsOpenAiImageOptions 提供了特定于每个模型提供商的选项。所有选项类都是通过流式 API 构建器创建的,所有选项都可以传递到可移植的 ImageModel API 中。这些选项数据类型用于 ImageModel 实现的自动配置/配置属性中。

2024 年 1 月 13 日更新

以下 OpenAi 自动配置聊天属性已更改

  • spring.ai.openai.modelspring.ai.openai.chat.options.model

  • spring.ai.openai.temperaturespring.ai.openai.chat.options.temperature

查找有关 OpenAi 属性的更新文档:docs.spring.io/spring-ai/reference/api/chat/openai-chat.html

2023 年 12 月 27 日更新

将 SimplePersistentVectorStore 和 InMemoryVectorStore 合并到 SimpleVectorStore * 将 InMemoryVectorStore 替换为 SimpleVectorStore

2023 年 12 月 20 日更新

重构 Ollama 客户端及相关类和包名

  • 将 org.springframework.ai.ollama.client.OllamaClient 替换为 org.springframework.ai.ollama.OllamaModelCall。

  • OllamaChatClient 方法签名已更改。

  • 将 org.springframework.ai.autoconfigure.ollama.OllamaProperties 重命名为 org.springframework.ai.model.ollama.autoconfigure.OllamaChatProperties,并将后缀更改为:spring.ai.ollama.chat。一些属性也已更改。

2023 年 12 月 19 日更新

AiClient 及相关类和包名重命名

  • 将 AiClient 重命名为 ChatClient

  • 将 AiResponse 重命名为 ChatResponse

  • 将 AiStreamClient 重命名为 StreamingChatClient

  • 将包 org.sf.ai.client 重命名为 org.sf.ai.chat

重命名 artifact ID

  • transformers-embeddingspring-ai-transformers

将 Maven 模块从顶层目录和 embedding-clients 子目录移动到单个 models 目录下。

2023 年 12 月 1 日

我们正在转换项目的 Group ID

  • : org.springframework.experimental.ai

  • : org.springframework.ai

Artifact 将仍托管在快照仓库中,如下所示。

主分支将移动到 0.8.0-SNAPSHOT 版本。它将在一两周内不稳定。如果您不想使用最新版本,请使用 0.7.1-SNAPSHOT。

您可以像以前一样访问 0.7.1-SNAPSHOT artifact,并且仍然可以访问 0.7.1-SNAPSHOT 文档

0.7.1-SNAPSHOT 依赖项

  • Azure OpenAI

    <dependency>
        <groupId>org.springframework.experimental.ai</groupId>
        <artifactId>spring-ai-azure-openai-spring-boot-starter</artifactId>
        <version>0.7.1-SNAPSHOT</version>
    </dependency>
  • OpenAI

    <dependency>
        <groupId>org.springframework.experimental.ai</groupId>
        <artifactId>spring-ai-openai-spring-boot-starter</artifactId>
        <version>0.7.1-SNAPSHOT</version>
    </dependency>
© . This site is unofficial and not affiliated with VMware.