|
| 1 | +/* |
| 2 | + * Copyright 2023-2025 the original author or authors. |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * https://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | + |
| 17 | +package org.springframework.ai.rag.postretrieval.document; |
| 18 | + |
| 19 | +import org.springframework.ai.document.Document; |
| 20 | +import org.springframework.ai.rag.Query; |
| 21 | + |
| 22 | +import java.util.List; |
| 23 | +import java.util.function.BiFunction; |
| 24 | + |
| 25 | +/** |
| 26 | + * A component for post-processing retrieved documents based on a query, addressing |
| 27 | + * challenges such as "lost-in-the-middle", context length restrictions from the model, |
| 28 | + * and the need to reduce noise and redundancy in the retrieved information. |
| 29 | + * <p> |
| 30 | + * For example, it could rank documents based on their relevance to the query, remove |
| 31 | + * irrelevant or redundant documents, or compress the content of each document to reduce |
| 32 | + * noise and redundancy. |
| 33 | + * |
| 34 | + * @author Thomas Vitale |
| 35 | + * @since 1.0.0 |
| 36 | + */ |
| 37 | +public interface DocumentPostProcessor extends BiFunction<Query, List<Document>, List<Document>> { |
| 38 | + |
| 39 | + List<Document> process(Query query, List<Document> documents); |
| 40 | + |
| 41 | + default List<Document> apply(Query query, List<Document> documents) { |
| 42 | + return process(query, documents); |
| 43 | + } |
| 44 | + |
| 45 | +} |
0 commit comments