- Add new QueryAugmentor API, a component for augmenting a user query with contextual data.
- Implement ContextualQueryAugmentor that combines the content of each document and add it to the original user prompt, with support for the scenario where the context is empty.
- Extend RetrievalAugmentationAdvisor to use the new augmentation building block.
- Introduce utility to assist in validating arguments for prompt-related operations.
Relates to gh-#1603
It also makes possible the customization reported in https://github.com/spring-projects/spring-ai/issues/1294
Comment From: tzolov
Thanks @ThomasVitale
Changes look good.
- It reminded me that we need to make the Builder methods consistent. Some use with
prefix other don't. But it seems the Spring's convention is not to have prefix (https://github.com/spring-projects/spring-ai/issues/1592#issuecomment-2453389119)
- After we merge this PR, we can refactor the QuedstionAnswerAdvisor as a wrapper around the RetrieverAugmentor one. Not sure if we should mark it as deprecated though.
Comment From: tzolov
Rebased and merged at bc50d28f2db64e8738a7f8b7470f4c053e6de56e
Comment From: ThomasVitale
@tzolov thanks for the review! For the builder naming convention, I followed what was used already for ChatClient
, but indeed both strategies are used throughout the project. It would be nice to converge towards one single naming strategy. I like the Spring convention of not having the prefix.
Comment From: ThomasVitale
About the QuestionAnswerAdvisor
, it's used a lot by developers. To protect the users from breaking changes, I would suggest keeping it as-is, mark it as deprecated, and document how to migrate to RetrievalAugmentationAdvisor
. We could even provide a simple OpenRewrite recipe to automate the migration.
Comment From: tzolov
Makes sense. Have not used the OpenRewrite yet and curious to see how it looks like :)