Refact AdvisedRequest to avoid userText rendering #2020
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Hello.
While implementing RAG using spring-ai, I encountered an error during rendering with PromptTemplate when the
userText
contained curly braces ({}
).Configuration
Spring Boot : 3.4.1
jdk : 17
spring-ai : 1.0.0-M5
Looking through the history, I found many related issues concerning StringTemplate. #355
When I implemented it using custom templates without the RetrievalAugmentationAdvisor, the error did not occur. However, the error started appearing after using RetrievalAugmentationAdvisor.
After investigating the cause, I discovered that the Advisor was treating userText as if it were a template and rendering it.
Therefore, I propose a solution to manage the text generated by the Advisor separately as a variable called
advisorText
instead of replacing theuserText
.userText
should provide the rendered string only when direct rendering is required, such as inDocumentRetrieval
orChatMemory
.I envisioned a scenario where the actual rendering of
userText
happens in thetoPrompt()
method ofCallAroundAdvisor
, which is created by default inDefaultChatClientRequestSpec
.