|
10 | 10 | import dev.langchain4j.model.embedding.EmbeddingModel;
|
11 | 11 | import dev.langchain4j.model.output.Response;
|
12 | 12 | import dev.langchain4j.store.embedding.EmbeddingMatch;
|
| 13 | +import dev.langchain4j.store.embedding.EmbeddingSearchRequest; |
| 14 | +import dev.langchain4j.store.embedding.EmbeddingSearchResult; |
13 | 15 | import dev.langchain4j.store.embedding.EmbeddingStore;
|
14 | 16 | import jakarta.inject.Inject;
|
15 | 17 | import jakarta.ws.rs.*;
|
@@ -62,15 +64,17 @@ public ChatResponse chat(ChatRequest chatRequest) {
|
62 | 64 |
|
63 | 65 | // Find relevant embeddings from Qdrant based on the user's question
|
64 | 66 | log.info("### Find relevant embeddings from Qdrant based on the question");
|
65 |
| - List<EmbeddingMatch<TextSegment>> relevant = embeddingStore.findRelevant(embeddedQuestion, 3); |
| 67 | + EmbeddingSearchResult<TextSegment> relevant = embeddingStore.search(EmbeddingSearchRequest.builder() |
| 68 | + .queryEmbedding(embeddedQuestion) |
| 69 | + .build()); |
66 | 70 |
|
67 | 71 | // Builds chat history using the relevant embeddings
|
68 | 72 | log.info("### Builds chat history using the relevant embeddings");
|
69 | 73 | List<ChatMessage> chatMessages = new ArrayList<>();
|
70 | 74 | chatMessages.add(SystemMessage.from(SYSTEM_MESSAGE_PROMPT));
|
71 | 75 | String userMessage = question + "\n\nSources:\n";
|
72 |
| - for (EmbeddingMatch<TextSegment> textSegmentEmbeddingMatch : relevant) { |
73 |
| - userMessage += textSegmentEmbeddingMatch.embedded().metadata("filename") + ": " + textSegmentEmbeddingMatch.embedded().text() + "\n"; |
| 76 | + for (EmbeddingMatch<TextSegment> textSegmentEmbeddingMatch : relevant.matches()) { |
| 77 | + userMessage += textSegmentEmbeddingMatch.embedded().metadata().getString("filename") + ": " + textSegmentEmbeddingMatch.embedded().text() + "\n"; |
74 | 78 | }
|
75 | 79 | chatMessages.add(UserMessage.from(userMessage));
|
76 | 80 |
|
|
0 commit comments