vector store by user

This commit is contained in:
2026-02-22 02:52:44 +01:00
parent 878dc21242
commit 3b9f80b46c
4 changed files with 15 additions and 8 deletions

View File

@@ -43,13 +43,18 @@ public class RagAdvisor implements BaseAdvisor {
String originalUserQuestion = chatClientRequest.prompt().getUserMessage().getText(); String originalUserQuestion = chatClientRequest.prompt().getUserMessage().getText();
String queryToRag = chatClientRequest.context().getOrDefault(ENRICHED_QUESTION, originalUserQuestion).toString(); String queryToRag = chatClientRequest.context().getOrDefault(ENRICHED_QUESTION, originalUserQuestion).toString();
SearchRequest searchRequest = SearchRequest.builder() Object userIdObj = chatClientRequest.context().get("USER_ID");
SearchRequest.Builder searchBuilder = SearchRequest.builder()
.query(queryToRag) .query(queryToRag)
.topK(searchTopK * rerankFetchMultiplier) .topK(searchTopK * rerankFetchMultiplier)
.similarityThreshold(similarityThreshold) .similarityThreshold(similarityThreshold);
.build();
List<Document> documents = vectorStore.similaritySearch(searchRequest); if (userIdObj != null) {
searchBuilder.filterExpression("user_id == " + userIdObj);
}
List<Document> documents = vectorStore.similaritySearch(searchBuilder.build());
if (documents == null || documents.isEmpty()) { if (documents == null || documents.isEmpty()) {
return chatClientRequest.mutate().context("CONTEXT", "EMPTY").build(); return chatClientRequest.mutate().context("CONTEXT", "EMPTY").build();

View File

@@ -38,9 +38,9 @@ public class ChatEntryController {
boolean onlyContext = request.onlyContext() != null ? request.onlyContext() : ragDefaults.onlyContext(); boolean onlyContext = request.onlyContext() != null ? request.onlyContext() : ragDefaults.onlyContext();
double topP = request.topP() != null ? request.topP() : ragDefaults.topP(); double topP = request.topP() != null ? request.topP() : ragDefaults.topP();
ChatEntry entry = chatEntryService.addUserEntry(chatId, request.content(), onlyContext, topP);
Chat chat = chatService.getChat(chatId); Chat chat = chatService.getChat(chatId);
ChatEntry entry = chatEntryService.addUserEntry(chatId, request.content(), onlyContext, topP, chat.getIdOwner());
eventPublisher.publishQuerySent( eventPublisher.publishQuerySent(
chat.getIdOwner().toString(), chat.getIdOwner().toString(),
chatId.toString(), chatId.toString(),

View File

@@ -8,5 +8,5 @@ public interface ChatEntryService {
List<ChatEntry> getEntriesByChatId(Long chatId); List<ChatEntry> getEntriesByChatId(Long chatId);
ChatEntry addUserEntry(Long chatId, String content, boolean onlyContext, double topP); ChatEntry addUserEntry(Long chatId, String content, boolean onlyContext, double topP, Long userId);
} }

View File

@@ -64,7 +64,9 @@ public class ChatEntryServiceImpl implements ChatEntryService {
String response = chatClient.prompt() String response = chatClient.prompt()
.system(systemPrompt) .system(systemPrompt)
.user(content) .user(content)
.advisors(a -> a.param(ChatMemory.CONVERSATION_ID, String.valueOf(chatId))) .advisors(a -> a
.param(ChatMemory.CONVERSATION_ID, String.valueOf(chatId))
.param("USER_ID", userId))
.options(OpenAiChatOptions.builder() .options(OpenAiChatOptions.builder()
.model(ragDefaults.model()) .model(ragDefaults.model())
.topP(topP) .topP(topP)