feat: implement chat history and retrieval settings
- Added new API endpoints for managing chat history configuration and retrieval settings, allowing tenants to enable message indexing and configure search parameters. - Introduced new Vue components for ChatHistorySettings and RetrievalSettings, providing a user-friendly interface for managing these configurations. - Updated localization files to include new settings descriptions and labels in multiple languages. - Enhanced the KnowledgeSearch view to support searching across both knowledge bases and chat history, improving the overall search functionality. These changes significantly enhance the application's capabilities in managing and retrieving chat history, contributing to a more robust user experience.
This commit is contained in:
@@ -171,7 +171,7 @@ func (h *Handler) setupStopEventHandler(
|
||||
assistantMessage.Content = "用户停止了本次对话"
|
||||
// Use session's tenant for message update (ctx may have effectiveTenantID when using shared agent)
|
||||
updateCtx := context.WithValue(ctx, types.TenantIDContextKey, sessionTenantID)
|
||||
h.completeAssistantMessage(updateCtx, assistantMessage)
|
||||
h.completeAssistantMessage(updateCtx, assistantMessage, "") // empty query: stopped conversations are not indexed
|
||||
return nil
|
||||
})
|
||||
}
|
||||
|
||||
@@ -420,7 +420,7 @@ func (h *Handler) executeNormalModeQA(reqCtx *qaRequestContext, generateTitle bo
|
||||
// Content already contains <think>...</think> tags from chat_completion_stream.go
|
||||
// Use session's tenant for message update (asyncCtx may have effectiveTenantID when using shared agent)
|
||||
updateCtx := context.WithValue(streamCtx.asyncCtx, types.TenantIDContextKey, reqCtx.session.TenantID)
|
||||
h.completeAssistantMessage(updateCtx, streamCtx.assistantMessage)
|
||||
h.completeAssistantMessage(updateCtx, streamCtx.assistantMessage, reqCtx.query)
|
||||
// Emit EventAgentComplete - this will trigger handleComplete which sends the SSE complete event
|
||||
// Note: Don't cancel context here, let the SSE handler close naturally after receiving the complete event
|
||||
streamCtx.eventBus.Emit(streamCtx.asyncCtx, event.Event{
|
||||
@@ -527,7 +527,7 @@ func (h *Handler) executeAgentModeQA(reqCtx *qaRequestContext) {
|
||||
}
|
||||
// Use session's tenant for message update (session belongs to session.TenantID; asyncCtx may have effectiveTenantID when using shared agent)
|
||||
updateCtx := context.WithValue(streamCtx.asyncCtx, types.TenantIDContextKey, reqCtx.session.TenantID)
|
||||
h.completeAssistantMessage(updateCtx, streamCtx.assistantMessage)
|
||||
h.completeAssistantMessage(updateCtx, streamCtx.assistantMessage, reqCtx.query)
|
||||
logger.Infof(streamCtx.asyncCtx, "Agent QA service completed for session: %s", sessionID)
|
||||
}()
|
||||
|
||||
@@ -561,9 +561,15 @@ func (h *Handler) executeAgentModeQA(reqCtx *qaRequestContext) {
|
||||
reqCtx.requestID, streamCtx.eventBus, reqCtx.session.Title == "")
|
||||
}
|
||||
|
||||
// completeAssistantMessage marks an assistant message as complete and updates it
|
||||
func (h *Handler) completeAssistantMessage(ctx context.Context, assistantMessage *types.Message) {
|
||||
// completeAssistantMessage marks an assistant message as complete, updates it,
|
||||
// and asynchronously indexes the Q&A pair into the chat history knowledge base.
|
||||
func (h *Handler) completeAssistantMessage(ctx context.Context, assistantMessage *types.Message, userQuery string) {
|
||||
assistantMessage.UpdatedAt = time.Now()
|
||||
assistantMessage.IsCompleted = true
|
||||
_ = h.messageService.UpdateMessage(ctx, assistantMessage)
|
||||
|
||||
// Asynchronously index the Q&A pair into the chat history knowledge base for vector search.
|
||||
// Use WithoutCancel so the goroutine survives after the HTTP request context is done.
|
||||
bgCtx := context.WithoutCancel(ctx)
|
||||
go h.messageService.IndexMessageToKB(bgCtx, userQuery, assistantMessage.Content, assistantMessage.ID, assistantMessage.SessionID)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user