diff --git a/chatmodel-springai/src/main/java/com/example/ai/controller/ChatController.java b/chatmodel-springai/src/main/java/com/example/ai/controller/ChatController.java index 32bbbe2..369675a 100644 --- a/chatmodel-springai/src/main/java/com/example/ai/controller/ChatController.java +++ b/chatmodel-springai/src/main/java/com/example/ai/controller/ChatController.java @@ -43,11 +43,11 @@ AIChatResponse sentimentAnalyzer(@RequestBody AIChatRequest aiChatRequest) { return chatService.analyzeSentiment(aiChatRequest.query()); } - // @PostMapping("/emebedding-client-conversion") - // AIChatResponse chatWithEmbeddingClient(@RequestBody AIChatRequest aiChatRequest) { - // return chatService.getEmbeddings(aiChatRequest.query()); - // } - // + @PostMapping("/emebedding-client-conversion") + AIChatResponse chatWithEmbeddingClient(@RequestBody AIChatRequest aiChatRequest) { + return chatService.getEmbeddings(aiChatRequest.query()); + } + @GetMapping("/output") public ActorsFilms generate(@RequestParam(value = "actor", defaultValue = "Jr NTR") String actor) { return chatService.generateAsBean(actor); diff --git a/chatmodel-springai/src/main/java/com/example/ai/service/ChatService.java b/chatmodel-springai/src/main/java/com/example/ai/service/ChatService.java index ca95e7f..9d7b46a 100644 --- a/chatmodel-springai/src/main/java/com/example/ai/service/ChatService.java +++ b/chatmodel-springai/src/main/java/com/example/ai/service/ChatService.java @@ -2,6 +2,7 @@ import com.example.ai.model.response.AIChatResponse; import com.example.ai.model.response.ActorsFilms; +import java.util.Arrays; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -75,11 +76,11 @@ public AIChatResponse analyzeSentiment(String query) { return new AIChatResponse(answer); } - // public AIChatResponse getEmbeddings(String query) { - // List embed = embeddingClient.embed(query); - // return new AIChatResponse(embed.toString()); - // } - // + public AIChatResponse getEmbeddings(String query) { + float[] embedded = embeddingModel.embed(query); + return new AIChatResponse(Arrays.toString(embedded)); + } + public ActorsFilms generateAsBean(String actor) { BeanOutputConverter outputParser = new BeanOutputConverter<>(ActorsFilms.class); diff --git a/embeddingstores/neo4j-springai/docker/docker-compose.yml b/embeddingstores/neo4j-springai/docker/docker-compose.yml index 4385615..3590660 100644 --- a/embeddingstores/neo4j-springai/docker/docker-compose.yml +++ b/embeddingstores/neo4j-springai/docker/docker-compose.yml @@ -3,8 +3,8 @@ services: container_name: neo4j image: neo4j:latest ports: - - 7474:7474 - - 7687:7687 + - "7474:7474" + - "7687:7687" environment: - NEO4J_AUTH=neo4j/password - NEO4J_apoc_export_file_enabled=true diff --git a/embeddingstores/neo4j-springai/pom.xml b/embeddingstores/neo4j-springai/pom.xml index 7be9e36..98e4a92 100644 --- a/embeddingstores/neo4j-springai/pom.xml +++ b/embeddingstores/neo4j-springai/pom.xml @@ -98,7 +98,7 @@ - 2.47.0 + 2.50.0 diff --git a/embeddingstores/neo4j-springai/src/main/java/com/learning/ai/service/Neo4jVectorStoreService.java b/embeddingstores/neo4j-springai/src/main/java/com/learning/ai/service/Neo4jVectorStoreService.java index 542ead0..189c460 100644 --- a/embeddingstores/neo4j-springai/src/main/java/com/learning/ai/service/Neo4jVectorStoreService.java +++ b/embeddingstores/neo4j-springai/src/main/java/com/learning/ai/service/Neo4jVectorStoreService.java @@ -32,7 +32,8 @@ public void storeEmbeddings() { public AIChatResponse queryEmbeddingStore(String question) { try { // Retrieve embeddings - SearchRequest query = SearchRequest.query(question).withTopK(1); + SearchRequest query = + SearchRequest.builder().query(question).topK(1).build(); List similarDocuments = vectorStore.similaritySearch(query); if (similarDocuments.isEmpty()) { diff --git a/embeddingstores/pgvector-springai/src/main/java/com/learning/ai/service/PgVectorStoreService.java b/embeddingstores/pgvector-springai/src/main/java/com/learning/ai/service/PgVectorStoreService.java index 444b403..4b971b0 100644 --- a/embeddingstores/pgvector-springai/src/main/java/com/learning/ai/service/PgVectorStoreService.java +++ b/embeddingstores/pgvector-springai/src/main/java/com/learning/ai/service/PgVectorStoreService.java @@ -33,13 +33,13 @@ public void storeEmbeddings() { public AIChatResponse queryEmbeddingStore(String question, Integer userId) { // Retrieve embeddings - SearchRequest query = SearchRequest.query(question).withTopK(1); + var queryBuilder = SearchRequest.builder().query(question).topK(1); if (userId != null) { - query.withFilterExpression("userId == " + userId); + queryBuilder.filterExpression("userId == " + userId); } - List similarDocuments = vectorStore.similaritySearch(query); + List similarDocuments = vectorStore.similaritySearch(queryBuilder.build()); String relevantData = - similarDocuments.stream().map(Document::getContent).collect(Collectors.joining(System.lineSeparator())); + similarDocuments.stream().map(Document::getText).collect(Collectors.joining(System.lineSeparator())); LOGGER.info("response from vectorStore : {} ", relevantData); return new AIChatResponse(relevantData);