diff --git a/backend/src/main/java/ch/xxx/aidoclibchat/adapter/repository/DocumentVSRepositoryBean.java b/backend/src/main/java/ch/xxx/aidoclibchat/adapter/repository/DocumentVSRepositoryBean.java index 073d9b2..1a96343 100644 --- a/backend/src/main/java/ch/xxx/aidoclibchat/adapter/repository/DocumentVSRepositoryBean.java +++ b/backend/src/main/java/ch/xxx/aidoclibchat/adapter/repository/DocumentVSRepositoryBean.java @@ -20,7 +20,6 @@ import org.postgresql.util.PGobject; import org.springframework.ai.document.Document; import org.springframework.ai.embedding.EmbeddingModel; -import org.springframework.ai.vectorstore.pgvector.PgVectorStore; import org.springframework.ai.vectorstore.SearchRequest; import org.springframework.ai.vectorstore.VectorStore; import org.springframework.ai.vectorstore.filter.Filter; @@ -28,6 +27,7 @@ import org.springframework.ai.vectorstore.filter.Filter.Key; import org.springframework.ai.vectorstore.filter.Filter.Value; import org.springframework.ai.vectorstore.filter.FilterExpressionConverter; +import org.springframework.ai.vectorstore.pgvector.PgVectorStore; import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.jdbc.core.RowMapper; import org.springframework.stereotype.Repository; @@ -52,7 +52,7 @@ public DocumentVSRepositoryBean(JdbcTemplate jdbcTemplate, EmbeddingModel embedd ObjectMapper objectMapper) { this.jdbcTemplate = jdbcTemplate; this.objectMapper = objectMapper; - this.vectorStore = new PgVectorStore(jdbcTemplate, embeddingClient); + this.vectorStore = PgVectorStore.builder().embeddingModel(embeddingClient).jdbcTemplate(jdbcTemplate).build(); this.filterExpressionConverter = ((PgVectorStore) this.vectorStore).filterExpressionConverter; this.vectorTableName = PgVectorStore.DEFAULT_TABLE_NAME; } diff --git a/backend/src/main/java/ch/xxx/aidoclibchat/adapter/repository/SubjectRepositoryBean.java b/backend/src/main/java/ch/xxx/aidoclibchat/adapter/repository/SubjectRepositoryBean.java index b8a0aae..e36a5b8 100644 --- a/backend/src/main/java/ch/xxx/aidoclibchat/adapter/repository/SubjectRepositoryBean.java +++ b/backend/src/main/java/ch/xxx/aidoclibchat/adapter/repository/SubjectRepositoryBean.java @@ -20,7 +20,6 @@ import ch.xxx.aidoclibchat.domain.model.entity.Subject; import ch.xxx.aidoclibchat.domain.model.entity.SubjectRepository; -import ch.xxx.aidoclibchat.domain.model.entity.Work; @Repository public class SubjectRepositoryBean implements SubjectRepository { diff --git a/backend/src/main/java/ch/xxx/aidoclibchat/usecase/service/CodeGenerationService.java b/backend/src/main/java/ch/xxx/aidoclibchat/usecase/service/CodeGenerationService.java index 751e68a..2cfacdf 100644 --- a/backend/src/main/java/ch/xxx/aidoclibchat/usecase/service/CodeGenerationService.java +++ b/backend/src/main/java/ch/xxx/aidoclibchat/usecase/service/CodeGenerationService.java @@ -113,7 +113,7 @@ public String generateTest(String url, Optional testUrlOpt) { .collect(Collectors.joining(System.getProperty("line.separator"))); LOGGER.debug(new PromptTemplate(this.contextWindowSize >= 16 * 1024 ? this.ollamaPrompt1 : this.ollamaPrompt, Map.of("classToTest", classToTest, "contextClasses", contextClasses, "testExample", testExample)) - .createMessage().getContent()); + .createMessage().getText()); LOGGER.info("Generation started with context window: {}", this.contextWindowSize); var response = chatClient.prompt() .user(u -> u.text(this.contextWindowSize >= 16 * 1024 ? this.ollamaPrompt1 : this.ollamaPrompt) diff --git a/backend/src/main/java/ch/xxx/aidoclibchat/usecase/service/DocumentService.java b/backend/src/main/java/ch/xxx/aidoclibchat/usecase/service/DocumentService.java index b077704..0ea595b 100644 --- a/backend/src/main/java/ch/xxx/aidoclibchat/usecase/service/DocumentService.java +++ b/backend/src/main/java/ch/xxx/aidoclibchat/usecase/service/DocumentService.java @@ -188,7 +188,7 @@ public Long storeDocument(Document document) { record TikaDocumentAndContent(org.springframework.ai.document.Document document, String content) { } var aiDocuments = tikaDocuments.stream() - .flatMap(myDocument1 -> this.splitStringToTokenLimit(myDocument1.getContent(), embeddingTokenLimit) + .flatMap(myDocument1 -> this.splitStringToTokenLimit(myDocument1.getText(), embeddingTokenLimit) .stream().map(myStr -> new TikaDocumentAndContent(myDocument1, myStr))) .map(myTikaRecord -> new org.springframework.ai.document.Document(myTikaRecord.content(), myTikaRecord.document().getMetadata())) @@ -226,10 +226,10 @@ public AiDocumentResult queryDocuments(SearchDto searchDto) { this.getSystemMessage(mostSimilar.stream().toList(), this.documentTokenLimit, searchDto.getSearchString()); default -> this.getSystemMessage(documentChunks, this.documentTokenLimit, searchDto.getSearchString()); }; - UserMessage userMessage = this.activeProfile.contains("ollama") ? new UserMessage(systemMessage.getContent()) + UserMessage userMessage = this.activeProfile.contains("ollama") ? new UserMessage(systemMessage.getText()) : new UserMessage(searchDto.getSearchString()); LocalDateTime start = LocalDateTime.now(); - var response = chatClient.prompt().system(s -> s.text(systemMessage.getContent())) + var response = chatClient.prompt().system(s -> s.text(systemMessage.getText())) .user(u -> u.text(userMessage.getContent())).call().chatResponse(); LOGGER.info("AI response time: {}ms", ZonedDateTime.of(LocalDateTime.now(), ZoneId.systemDefault()).toInstant().toEpochMilli() @@ -251,7 +251,7 @@ public AiDocumentResult queryDocuments(SearchDto searchDto) { private Message getSystemMessage(List similarDocuments, int tokenLimit, String prompt) { String documentStr = this.cutStringToTokenLimit( - similarDocuments.stream().map(entry -> entry.getContent()) + similarDocuments.stream().map(entry -> entry.getText()) .filter(Predicate.not(Objects::isNull)) .filter(Predicate.not(String::isBlank)).collect(Collectors.joining("\n")), tokenLimit); diff --git a/backend/src/main/java/ch/xxx/aidoclibchat/usecase/service/ImageService.java b/backend/src/main/java/ch/xxx/aidoclibchat/usecase/service/ImageService.java index bf0e5d8..13f0918 100644 --- a/backend/src/main/java/ch/xxx/aidoclibchat/usecase/service/ImageService.java +++ b/backend/src/main/java/ch/xxx/aidoclibchat/usecase/service/ImageService.java @@ -57,7 +57,7 @@ public class ImageService { private DocumentVsRepository documentVsRepository; @Value("${image.result-size:20}") private Long resultSize; - private final String systemPrompt = "You are a helpful assistent searching image descriptions."; + //private final String systemPrompt = "You are a helpful assistent searching image descriptions."; private record ResultData(String answer, ImageQueryDto imageQueryDto) { } @@ -97,7 +97,7 @@ public List queryImage(String imageQuery) { .stream().collect(Collectors.toMap(myDoc -> myDoc.getId(), myDoc -> myDoc)); return imageMap.entrySet().stream().map(myEntry -> createImageContainer(aiDocuments, myEntry)) .sorted((containerA, containerB) -> containerA.distance().compareTo(containerB.distance())) - .map(myContainer -> new ImageDto(myContainer.document().getContent(), + .map(myContainer -> new ImageDto(myContainer.document().getText(), Base64.getEncoder().encodeToString(myContainer.image().getImageContent()), myContainer.image().getImageType())) .limit(this.resultSize).toList(); diff --git a/backend/src/main/java/ch/xxx/aidoclibchat/usecase/service/TableService.java b/backend/src/main/java/ch/xxx/aidoclibchat/usecase/service/TableService.java index ce815ff..0281911 100644 --- a/backend/src/main/java/ch/xxx/aidoclibchat/usecase/service/TableService.java +++ b/backend/src/main/java/ch/xxx/aidoclibchat/usecase/service/TableService.java @@ -161,7 +161,7 @@ private Prompt createPrompt(SearchDto searchDto, EmbeddingContainer documentCont joinTable.set(((String) myRowDoc.getMetadata().get(MetaData.TABLE_NAME))); joinColumn.set(((String) myRowDoc.getMetadata().get(MetaData.DATANAME))); tableColumnNames.columnNames().add(((String) myRowDoc.getMetadata().get(MetaData.DATANAME))); - columnValue.set(myRowDoc.getContent()); + columnValue.set(myRowDoc.getText()); this.tableMetadataRepository .findByTableNameIn(List.of(((String) myRowDoc.getMetadata().get(MetaData.TABLE_NAME)))) .stream() @@ -190,7 +190,7 @@ private List createMessages(SearchDto searchDto, final Float minRowDist tableRecords.stream().map(myRecord -> myRecord.schema()).collect(Collectors.joining(";")), "prompt", searchDto.getSearchString(), "joinColumn", joinColumn.get(), "joinTable", joinTable.get(), "columnValue", columnValue.get())); - UserMessage userMessage = this.activeProfile.contains("ollama") ? new UserMessage(systemMessage.getContent()) + UserMessage userMessage = this.activeProfile.contains("ollama") ? new UserMessage(systemMessage.getText()) : new UserMessage(searchDto.getSearchString()); return List.of(systemMessage, userMessage); }