From 76bee8ceb2854839f93a6c52876f50bb24219355 Mon Sep 17 00:00:00 2001 From: Ilayaperumal Gopinathan Date: Sun, 4 May 2025 23:10:05 +0100 Subject: [PATCH] Remove deprecations from 1.0.0-M8 Remove deprecated DocumentCompressor/Ranker/Selector - These are replaced by the org.springframework.ai.rag.postretrieval.document.DocumentPostProcessor Remove deprecated Chatclient/DefaultChatClient methods In ChatClient: - Remove defaultTools and tools as these are replaced by defaultToolCallbacks and defaultToolNames respectively. In DefaultChatClient: - Remove tools method implementation - Remove unused DefaultCallPromptResponseSpec and DefaultStreamPromptResponseSpec Remove deprecated addMessage from Prompt Remove deprecated isInternalToolExecutionEnabled() from ToolCallingChatOptions - This is replaced by getInternalToolExecutionEnabled() Signed-off-by: Ilayaperumal Gopinathan --- .../ai/chat/client/ChatClient.java | 9 --- .../ai/chat/client/DefaultChatClient.java | 74 ------------------- .../chat/client/DefaultChatClientBuilder.java | 5 -- .../ai/chat/prompt/Prompt.java | 9 --- .../ai/model/tool/ToolCallingChatOptions.java | 10 --- .../compression/DocumentCompressor.java | 55 -------------- .../compression/package-info.java | 25 ------- .../postretrieval/ranking/DocumentRanker.java | 54 -------------- .../postretrieval/ranking/package-info.java | 25 ------- .../selection/DocumentSelector.java | 55 -------------- .../postretrieval/selection/package-info.java | 25 ------- 11 files changed, 346 deletions(-) delete mode 100644 spring-ai-rag/src/main/java/org/springframework/ai/rag/postretrieval/compression/DocumentCompressor.java delete mode 100644 spring-ai-rag/src/main/java/org/springframework/ai/rag/postretrieval/compression/package-info.java delete mode 100644 spring-ai-rag/src/main/java/org/springframework/ai/rag/postretrieval/ranking/DocumentRanker.java delete mode 100644 spring-ai-rag/src/main/java/org/springframework/ai/rag/postretrieval/ranking/package-info.java delete mode 100644 spring-ai-rag/src/main/java/org/springframework/ai/rag/postretrieval/selection/DocumentSelector.java delete mode 100644 spring-ai-rag/src/main/java/org/springframework/ai/rag/postretrieval/selection/package-info.java diff --git a/spring-ai-client-chat/src/main/java/org/springframework/ai/chat/client/ChatClient.java b/spring-ai-client-chat/src/main/java/org/springframework/ai/chat/client/ChatClient.java index 59d044636..d6fe27574 100644 --- a/spring-ai-client-chat/src/main/java/org/springframework/ai/chat/client/ChatClient.java +++ b/spring-ai-client-chat/src/main/java/org/springframework/ai/chat/client/ChatClient.java @@ -222,12 +222,6 @@ public interface ChatClient { ChatClientRequestSpec toolNames(String... toolNames); - /** - * Use toolNames instead - */ - @Deprecated(forRemoval = true, since = "1.0.0-m8") - ChatClientRequestSpec tools(String... toolNames); - ChatClientRequestSpec tools(Object... toolObjects); ChatClientRequestSpec toolCallbacks(ToolCallback... toolCallbacks); @@ -295,9 +289,6 @@ public interface ChatClient { Builder defaultToolNames(String... toolNames); - @Deprecated - Builder defaultTools(String... tools); - Builder defaultTools(Object... toolObjects); Builder defaultToolCallbacks(ToolCallback... toolCallbacks); diff --git a/spring-ai-client-chat/src/main/java/org/springframework/ai/chat/client/DefaultChatClient.java b/spring-ai-client-chat/src/main/java/org/springframework/ai/chat/client/DefaultChatClient.java index c58bd3620..2b6753281 100644 --- a/spring-ai-client-chat/src/main/java/org/springframework/ai/chat/client/DefaultChatClient.java +++ b/spring-ai-client-chat/src/main/java/org/springframework/ai/chat/client/DefaultChatClient.java @@ -51,7 +51,6 @@ import org.springframework.ai.chat.messages.UserMessage; import org.springframework.ai.chat.model.ChatModel; import org.springframework.ai.chat.model.ChatResponse; import org.springframework.ai.chat.model.Generation; -import org.springframework.ai.chat.model.StreamingChatModel; import org.springframework.ai.chat.prompt.ChatOptions; import org.springframework.ai.chat.prompt.Prompt; import org.springframework.ai.content.Media; @@ -835,11 +834,6 @@ public class DefaultChatClient implements ChatClient { return this; } - @Override - public ChatClientRequestSpec tools(String... toolNames) { - return this.toolNames(toolNames); - } - @Override public ChatClientRequestSpec toolNames(String... toolNames) { Assert.notNull(toolNames, "toolNames cannot be null"); @@ -992,72 +986,4 @@ public class DefaultChatClient implements ChatClient { } - // Prompt - - @Deprecated // never used, to be removed - public static class DefaultCallPromptResponseSpec implements CallPromptResponseSpec { - - private final ChatModel chatModel; - - private final Prompt prompt; - - public DefaultCallPromptResponseSpec(ChatModel chatModel, Prompt prompt) { - Assert.notNull(chatModel, "chatModel cannot be null"); - Assert.notNull(prompt, "prompt cannot be null"); - this.chatModel = chatModel; - this.prompt = prompt; - } - - public String content() { - return doGetChatResponse(this.prompt).getResult().getOutput().getText(); - } - - public List contents() { - return doGetChatResponse(this.prompt).getResults().stream().map(r -> r.getOutput().getText()).toList(); - } - - public ChatResponse chatResponse() { - return doGetChatResponse(this.prompt); - } - - private ChatResponse doGetChatResponse(Prompt prompt) { - return this.chatModel.call(prompt); - } - - } - - @Deprecated // never used, to be removed - public static class DefaultStreamPromptResponseSpec implements StreamPromptResponseSpec { - - private final Prompt prompt; - - private final StreamingChatModel chatModel; - - public DefaultStreamPromptResponseSpec(StreamingChatModel streamingChatModel, Prompt prompt) { - Assert.notNull(streamingChatModel, "streamingChatModel cannot be null"); - Assert.notNull(prompt, "prompt cannot be null"); - this.chatModel = streamingChatModel; - this.prompt = prompt; - } - - public Flux chatResponse() { - return doGetFluxChatResponse(this.prompt); - } - - private Flux doGetFluxChatResponse(Prompt prompt) { - return this.chatModel.stream(prompt); - } - - public Flux content() { - return doGetFluxChatResponse(this.prompt).map(r -> { - if (r.getResult() == null || r.getResult().getOutput() == null - || r.getResult().getOutput().getText() == null) { - return ""; - } - return r.getResult().getOutput().getText(); - }).filter(StringUtils::hasLength); - } - - } - } diff --git a/spring-ai-client-chat/src/main/java/org/springframework/ai/chat/client/DefaultChatClientBuilder.java b/spring-ai-client-chat/src/main/java/org/springframework/ai/chat/client/DefaultChatClientBuilder.java index 5dc5d9853..35e011af4 100644 --- a/spring-ai-client-chat/src/main/java/org/springframework/ai/chat/client/DefaultChatClientBuilder.java +++ b/spring-ai-client-chat/src/main/java/org/springframework/ai/chat/client/DefaultChatClientBuilder.java @@ -150,11 +150,6 @@ public class DefaultChatClientBuilder implements Builder { return this; } - @Override - public Builder defaultTools(String... toolNames) { - return defaultToolNames(toolNames); - } - @Override public Builder defaultToolNames(String... toolNames) { this.defaultRequest.toolNames(toolNames); diff --git a/spring-ai-model/src/main/java/org/springframework/ai/chat/prompt/Prompt.java b/spring-ai-model/src/main/java/org/springframework/ai/chat/prompt/Prompt.java index 89d09fe40..43a043d46 100644 --- a/spring-ai-model/src/main/java/org/springframework/ai/chat/prompt/Prompt.java +++ b/spring-ai-model/src/main/java/org/springframework/ai/chat/prompt/Prompt.java @@ -236,15 +236,6 @@ public class Prompt implements ModelRequest> { return this; } - @Deprecated - public Builder addMessage(Message message) { - if (this.messages == null) { - this.messages = new ArrayList<>(); - } - this.messages.add(message); - return this; - } - public Builder chatOptions(ChatOptions chatOptions) { this.chatOptions = chatOptions; return this; diff --git a/spring-ai-model/src/main/java/org/springframework/ai/model/tool/ToolCallingChatOptions.java b/spring-ai-model/src/main/java/org/springframework/ai/model/tool/ToolCallingChatOptions.java index 17280809a..cba1fd374 100644 --- a/spring-ai-model/src/main/java/org/springframework/ai/model/tool/ToolCallingChatOptions.java +++ b/spring-ai-model/src/main/java/org/springframework/ai/model/tool/ToolCallingChatOptions.java @@ -70,16 +70,6 @@ public interface ToolCallingChatOptions extends ChatOptions { @Nullable Boolean getInternalToolExecutionEnabled(); - /** - * Whether the {@link ChatModel} is responsible for executing the tools requested by - * the model or if the tools should be executed directly by the caller. - */ - @Nullable - @Deprecated - default Boolean isInternalToolExecutionEnabled() { - return getInternalToolExecutionEnabled(); - } - /** * Set whether the {@link ChatModel} is responsible for executing the tools requested * by the model or if the tools should be executed directly by the caller. diff --git a/spring-ai-rag/src/main/java/org/springframework/ai/rag/postretrieval/compression/DocumentCompressor.java b/spring-ai-rag/src/main/java/org/springframework/ai/rag/postretrieval/compression/DocumentCompressor.java deleted file mode 100644 index 52b9d7916..000000000 --- a/spring-ai-rag/src/main/java/org/springframework/ai/rag/postretrieval/compression/DocumentCompressor.java +++ /dev/null @@ -1,55 +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. - */ - -package org.springframework.ai.rag.postretrieval.compression; - -import java.util.List; -import java.util.function.BiFunction; - -import org.springframework.ai.document.Document; -import org.springframework.ai.rag.Query; -import org.springframework.ai.rag.postretrieval.document.DocumentPostProcessor; -import org.springframework.ai.rag.postretrieval.ranking.DocumentRanker; -import org.springframework.ai.rag.postretrieval.selection.DocumentSelector; - -/** - * A component for compressing the content of each document to reduce noise and redundancy - * in the retrieved information, addressing challenges such as "lost-in-the-middle" and - * context length restrictions from the model. - *

- * Unlike {@link DocumentSelector}, this component does not remove entire documents from - * the list, but rather alters the content of the documents. Unlike - * {@link DocumentRanker}, this component does not change the order/score of the documents - * in the list. - * - * @deprecated in favour of {@link DocumentPostProcessor}. - */ -@Deprecated -public interface DocumentCompressor extends BiFunction, List> { - - /** - * Compresses the content of each document. - * @param query the query to compress documents for - * @param documents the list of documents whose content should be compressed - * @return a list of documents with compressed content - */ - List compress(Query query, List documents); - - default List apply(Query query, List documents) { - return compress(query, documents); - } - -} diff --git a/spring-ai-rag/src/main/java/org/springframework/ai/rag/postretrieval/compression/package-info.java b/spring-ai-rag/src/main/java/org/springframework/ai/rag/postretrieval/compression/package-info.java deleted file mode 100644 index c29363101..000000000 --- a/spring-ai-rag/src/main/java/org/springframework/ai/rag/postretrieval/compression/package-info.java +++ /dev/null @@ -1,25 +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 Sub-Module: Document Compression. - */ -@NonNullApi -@NonNullFields -package org.springframework.ai.rag.postretrieval.compression; - -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; diff --git a/spring-ai-rag/src/main/java/org/springframework/ai/rag/postretrieval/ranking/DocumentRanker.java b/spring-ai-rag/src/main/java/org/springframework/ai/rag/postretrieval/ranking/DocumentRanker.java deleted file mode 100644 index 7e8e05004..000000000 --- a/spring-ai-rag/src/main/java/org/springframework/ai/rag/postretrieval/ranking/DocumentRanker.java +++ /dev/null @@ -1,54 +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. - */ - -package org.springframework.ai.rag.postretrieval.ranking; - -import java.util.List; -import java.util.function.BiFunction; - -import org.springframework.ai.document.Document; -import org.springframework.ai.rag.Query; -import org.springframework.ai.rag.postretrieval.compression.DocumentCompressor; -import org.springframework.ai.rag.postretrieval.document.DocumentPostProcessor; -import org.springframework.ai.rag.postretrieval.selection.DocumentSelector; - -/** - * A component for ordering and ranking documents based on their relevance to a query to - * bring the most relevant documents to the top of the list, addressing challenges such as - * "lost-in-the-middle". - *

- * Unlike {@link DocumentSelector}, this component does not remove entire documents from - * the list, but rather changes the order/score of the documents in the list. Unlike - * {@link DocumentCompressor}, this component does not alter the content of the documents. - * - * @deprecated in favour of {@link DocumentPostProcessor}. - */ -@Deprecated -public interface DocumentRanker extends BiFunction, List> { - - /** - * Ranks documents based on their relevance to the given query. - * @param query the query to rank documents for - * @param documents the list of documents to rank - * @return a list of ordered documents based on a ranking algorithm - */ - List rank(Query query, List documents); - - default List apply(Query query, List documents) { - return rank(query, documents); - } - -} diff --git a/spring-ai-rag/src/main/java/org/springframework/ai/rag/postretrieval/ranking/package-info.java b/spring-ai-rag/src/main/java/org/springframework/ai/rag/postretrieval/ranking/package-info.java deleted file mode 100644 index 21838ac03..000000000 --- a/spring-ai-rag/src/main/java/org/springframework/ai/rag/postretrieval/ranking/package-info.java +++ /dev/null @@ -1,25 +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 Sub-Module: Document Ranking. - */ -@NonNullApi -@NonNullFields -package org.springframework.ai.rag.postretrieval.ranking; - -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; diff --git a/spring-ai-rag/src/main/java/org/springframework/ai/rag/postretrieval/selection/DocumentSelector.java b/spring-ai-rag/src/main/java/org/springframework/ai/rag/postretrieval/selection/DocumentSelector.java deleted file mode 100644 index 37cfdd502..000000000 --- a/spring-ai-rag/src/main/java/org/springframework/ai/rag/postretrieval/selection/DocumentSelector.java +++ /dev/null @@ -1,55 +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. - */ - -package org.springframework.ai.rag.postretrieval.selection; - -import java.util.List; -import java.util.function.BiFunction; - -import org.springframework.ai.document.Document; -import org.springframework.ai.rag.Query; -import org.springframework.ai.rag.postretrieval.compression.DocumentCompressor; -import org.springframework.ai.rag.postretrieval.document.DocumentPostProcessor; -import org.springframework.ai.rag.postretrieval.ranking.DocumentRanker; - -/** - * A component for removing irrelevant or redundant documents from a list of retrieved - * documents, addressing challenges such as "lost-in-the-middle" and context length - * restrictions from the model. - *

- * Unlike {@link DocumentRanker}, this component does not change the order/score of the - * documents in the list, but rather removes irrelevant or redundant documents. Unlike - * {@link DocumentCompressor}, this component does not alter the content of the documents, - * but rather removes entire documents. - * - * @deprecated in favour of {@link DocumentPostProcessor}. - */ -@Deprecated -public interface DocumentSelector extends BiFunction, List> { - - /** - * Removes irrelevant or redundant documents from a list of retrieved documents. - * @param query the query to select documents for - * @param documents the list of documents to select from - * @return a list of selected documents - */ - List select(Query query, List documents); - - default List apply(Query query, List documents) { - return select(query, documents); - } - -} diff --git a/spring-ai-rag/src/main/java/org/springframework/ai/rag/postretrieval/selection/package-info.java b/spring-ai-rag/src/main/java/org/springframework/ai/rag/postretrieval/selection/package-info.java deleted file mode 100644 index 8ebc56808..000000000 --- a/spring-ai-rag/src/main/java/org/springframework/ai/rag/postretrieval/selection/package-info.java +++ /dev/null @@ -1,25 +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 Sub-Module: Document Selection. - */ -@NonNullApi -@NonNullFields -package org.springframework.ai.rag.postretrieval.selection; - -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields;