QuestionAnswerAdvisor turns retrieval-augmented generation into a ChatClient advisor. Before the model call, it searches a vector store for documents similar to the question and adds them to the prompt as context. section 4.5 section 4.7
Use it incrementally:
- Attach QuestionAnswerAdvisor.builder(vectorStore).build() to a request through advisors(). section 4.5
- Register it with defaultAdvisors() when every ChatClient request should use the same vector store. section 4.5
- Restrict retrieval with FILTER_EXPRESSION when questions must match document metadata such as gameTitle. section 4.5
@Override
public Answer askQuestion(Question question) {
String gameNameMatch = String.format("gameTitle ==
'%s'", question.gameTitle());
return chatClient.prompt()
.system(systemSpec -> systemSpec
.text(promptTemplate)
.param("gameTitle", question.gameTitle()))
.user(question.question())
.advisors(
QuestionAnswerAdvisor.builder(vectorStore).build())
.call()
.entity(Answer.class);
}
A complete askQuestion() call combines a system prompt, user question, QuestionAnswerAdvisor, and typed Answer mapping. section 4.5
