This PR is to provide the feature https://github.com/spring-projects/spring-ai/issues/880
Change: 1) New class QueryTransformerQuestionAnswerAdvisor extends QuestionAnswerAdvisor 2) Call the AI model to transfer the query before call the vector search
Thank you for taking time to contribute this pull request! You might have already read the [contributor guide][1], but as a reminder, please make sure to:
- Sign the contributor license agreement Done
- Rebase your changes on the latest
main
branch and squash your commits Done - Add/Update unit tests as needed Done
- Run a build and make sure all tests pass prior to submission Done
Comment From: markpollack
Hi. Thanks for you contribution. I feel that features such as checking for preconditions on the user text should be done in their own advisor and not to extend the QuestionAnswerAdvisor
. The reasoning is that checking for some precondition on the user text doesn't involve using a vector store - at least in the current implementation you propose - and that we have a chain of advisors that get executed one after another. This allows for flexibility in combining different advisor functionality.
Comment From: showpune
Hi @markpollack thanks for your response.
I extend the QuestionAnwserAdvisor because I just want to optimize the vector store query by refine the query using model according to customer input. I even can ask model to "generate 3 different query from different perspective but still keep the same meaning" to optimize my search in vector store.
I don't want to put a preadvisor because I don't want to change the orignal customer input. In my example, if the customer ask in Chinese, I just want to using the query in English to query the vector store, and I still want to use the orignal customer input in Chinese to talke with model and model will return in Chinese. If we use preadvisor to translate the customer input into English, the return will be in English
In summary, I want to use the model to optimize my query for vector query, but not just translate the talk
Comment From: markpollack
Thanks for the explanation, I understand the issue better now. I want to do a bit of research into this area of more advanced RAG techniques, certainly something we need to support. The technique you have here looks to be in the category of 'query rewriting' and then, as you mention, asking multiple questions and taking the 'best' response from them. I want to see how well the advisor chain itself can be setup to perform this in sequential steps - including keeping the original query - or if it needs to be encapsulated into a single advisor. I think some modularity should be possible with advisors that are known to work well together and data sharing between advisor's occuring with the shared context each advisor is given.
Comment From: ThomasVitale
This use case is now supported by the TranslationQueryTransformer
component of the new (experimental) Modular RAG features. More info in the documentation: https://docs.spring.io/spring-ai/reference/api/retrieval-augmented-generation.html#_translationquerytransformer
I even can ask model to "generate 3 different query from different perspective but still keep the same meaning" to optimize my search in vector store.
That use case is supported by the MultiQueryExpander
component. More info in the documentation: https://docs.spring.io/spring-ai/reference/api/retrieval-augmented-generation.html#_multiqueryexpander