vector store by user
This commit is contained in:
@@ -43,13 +43,18 @@ public class RagAdvisor implements BaseAdvisor {
|
||||
String originalUserQuestion = chatClientRequest.prompt().getUserMessage().getText();
|
||||
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)
|
||||
.topK(searchTopK * rerankFetchMultiplier)
|
||||
.similarityThreshold(similarityThreshold)
|
||||
.build();
|
||||
.similarityThreshold(similarityThreshold);
|
||||
|
||||
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()) {
|
||||
return chatClientRequest.mutate().context("CONTEXT", "EMPTY").build();
|
||||
|
||||
@@ -38,9 +38,9 @@ public class ChatEntryController {
|
||||
boolean onlyContext = request.onlyContext() != null ? request.onlyContext() : ragDefaults.onlyContext();
|
||||
double topP = request.topP() != null ? request.topP() : ragDefaults.topP();
|
||||
|
||||
ChatEntry entry = chatEntryService.addUserEntry(chatId, request.content(), onlyContext, topP);
|
||||
|
||||
Chat chat = chatService.getChat(chatId);
|
||||
ChatEntry entry = chatEntryService.addUserEntry(chatId, request.content(), onlyContext, topP, chat.getIdOwner());
|
||||
|
||||
eventPublisher.publishQuerySent(
|
||||
chat.getIdOwner().toString(),
|
||||
chatId.toString(),
|
||||
|
||||
@@ -8,5 +8,5 @@ public interface ChatEntryService {
|
||||
|
||||
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);
|
||||
}
|
||||
@@ -64,7 +64,9 @@ public class ChatEntryServiceImpl implements ChatEntryService {
|
||||
String response = chatClient.prompt()
|
||||
.system(systemPrompt)
|
||||
.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()
|
||||
.model(ragDefaults.model())
|
||||
.topP(topP)
|
||||
|
||||
Reference in New Issue
Block a user