diff --git a/demo-catalog/templates/spring-boot-ai-service/base/catalog-info.yml b/demo-catalog/templates/spring-boot-ai-service/base/catalog-info.yml index 79bc0e7..baa52d1 100644 --- a/demo-catalog/templates/spring-boot-ai-service/base/catalog-info.yml +++ b/demo-catalog/templates/spring-boot-ai-service/base/catalog-info.yml @@ -9,6 +9,7 @@ metadata: backstage.io/techdocs-ref: dir:. endoflife.date/products: spring-boot github.com/project-slug: ${{ values.repoUrl.owner }}/${{ values.repoUrl.repo }} + github.com/workflows: commit-stage.yml sonarqube.org/project-key: ${{ values.repoUrl.owner }}_${{ values.repoUrl.repo }} spec: type: service diff --git a/demo-catalog/templates/spring-boot-ai-service/base/src/main/java/${{values.basePackageDir}}/Application.java b/demo-catalog/templates/spring-boot-ai-service/base/src/main/java/${{values.basePackageDir}}/Application.java index bcc175c..2cef75c 100644 --- a/demo-catalog/templates/spring-boot-ai-service/base/src/main/java/${{values.basePackageDir}}/Application.java +++ b/demo-catalog/templates/spring-boot-ai-service/base/src/main/java/${{values.basePackageDir}}/Application.java @@ -6,7 +6,9 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.ai.chat.client.ChatClient; -import org.springframework.ai.chat.client.advisor.QuestionAnswerAdvisor; +import org.springframework.ai.chat.client.advisor.RetrievalAugmentationAdvisor; +import org.springframework.ai.rag.retrieval.source.DocumentRetriever; +import org.springframework.ai.rag.retrieval.source.VectorStoreDocumentRetriever; import org.springframework.ai.reader.TextReader; import org.springframework.ai.transformer.splitter.TokenTextSplitter; import org.springframework.ai.vectorstore.VectorStore; @@ -16,7 +18,6 @@ import org.springframework.boot.context.event.ApplicationReadyEvent; import org.springframework.context.ApplicationListener; import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; import org.springframework.core.io.Resource; import org.springframework.jdbc.core.simple.JdbcClient; import org.springframework.stereotype.Component; @@ -24,8 +25,6 @@ import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RestController; -import java.time.Duration; - @SpringBootApplication public class Application { @@ -46,18 +45,22 @@ class ChatController { private static final Logger logger = LoggerFactory.getLogger(ChatController.class); private final ChatClient chatClient; - private final VectorStore vectorStore; + private final DocumentRetriever documentRetriever; ChatController(ChatClient.Builder chatClientBuilder, VectorStore vectorStore) { this.chatClient = chatClientBuilder.build(); - this.vectorStore = vectorStore; + this.documentRetriever = VectorStoreDocumentRetriever.builder() + .vectorStore(vectorStore) + .build(); } @PostMapping("/chat") String chatWithDocument(@RequestBody String message) { logger.info("Received user message: {}", message); return chatClient.prompt() - .advisors(new QuestionAnswerAdvisor(vectorStore)) + .advisors(RetrievalAugmentationAdvisor.builder() + .documentRetriever(documentRetriever) + .build()) .user(message) .call() .content();