66import org .slf4j .Logger ;
77import org .slf4j .LoggerFactory ;
88import org .springframework .ai .chat .client .ChatClient ;
9- import org .springframework .ai .chat .client .advisor .QuestionAnswerAdvisor ;
9+ import org .springframework .ai .chat .client .advisor .RetrievalAugmentationAdvisor ;
10+ import org .springframework .ai .rag .retrieval .source .DocumentRetriever ;
11+ import org .springframework .ai .rag .retrieval .source .VectorStoreDocumentRetriever ;
1012import org .springframework .ai .reader .TextReader ;
1113import org .springframework .ai .transformer .splitter .TokenTextSplitter ;
1214import org .springframework .ai .vectorstore .VectorStore ;
1618import org .springframework .boot .context .event .ApplicationReadyEvent ;
1719import org .springframework .context .ApplicationListener ;
1820import org .springframework .context .annotation .Bean ;
19- import org .springframework .context .annotation .Configuration ;
2021import org .springframework .core .io .Resource ;
2122import org .springframework .jdbc .core .simple .JdbcClient ;
2223import org .springframework .stereotype .Component ;
2324import org .springframework .web .bind .annotation .PostMapping ;
2425import org .springframework .web .bind .annotation .RequestBody ;
2526import org .springframework .web .bind .annotation .RestController ;
2627
27- import java .time .Duration ;
28-
2928@ SpringBootApplication
3029public class Application {
3130
@@ -46,18 +45,22 @@ class ChatController {
4645 private static final Logger logger = LoggerFactory .getLogger (ChatController .class );
4746
4847 private final ChatClient chatClient ;
49- private final VectorStore vectorStore ;
48+ private final DocumentRetriever documentRetriever ;
5049
5150 ChatController (ChatClient .Builder chatClientBuilder , VectorStore vectorStore ) {
5251 this .chatClient = chatClientBuilder .build ();
53- this .vectorStore = vectorStore ;
52+ this .documentRetriever = VectorStoreDocumentRetriever .builder ()
53+ .vectorStore (vectorStore )
54+ .build ();
5455 }
5556
5657 @ PostMapping ("/chat" )
5758 String chatWithDocument (@ RequestBody String message ) {
5859 logger .info ("Received user message: {}" , message );
5960 return chatClient .prompt ()
60- .advisors (new QuestionAnswerAdvisor (vectorStore ))
61+ .advisors (RetrievalAugmentationAdvisor .builder ()
62+ .documentRetriever (documentRetriever )
63+ .build ())
6164 .user (message )
6265 .call ()
6366 .content ();
0 commit comments