fix(server): case-insensitive doc keyword search + not-found classification

Make document keyword search case-insensitive (LOWER(...) LIKE LOWER(?)) in the
list filter and SearchKnowledge / SearchKnowledgeInScopes paths so a query and
its differently-cased variant return the same results.

Classify not-found consistently as HTTP 404 (not 500) so clients read a
permanent resource.not_found instead of a retryable 5xx: map the document /
chunk not-found sentinels in the KB-access middleware (typed ErrChunkNotFound
via errors.Is), and return 404 for a missing message on the continue-stream and
message-delete endpoints.
This commit is contained in:
nullkey
2026-06-26 20:40:59 +08:00
committed by lyingbug
parent 8f36ea2229
commit 445a4330fa
8 changed files with 77 additions and 20 deletions
+11
View File
@@ -14,6 +14,7 @@ import (
"github.com/Tencent/WeKnora/internal/types/interfaces"
secutils "github.com/Tencent/WeKnora/internal/utils"
"github.com/gin-gonic/gin"
"gorm.io/gorm"
)
// ContinueStream godoc
@@ -77,6 +78,16 @@ func (h *Handler) ContinueStream(c *gin.Context) {
c.Error(errors.NewNotFoundError(err.Error()))
return
}
if stderrors.Is(err, gorm.ErrRecordNotFound) {
// The message_id doesn't exist (e.g. a wrong / non-persisted id, or an
// expired replay buffer). That is a client error, not a server fault:
// return 404 so callers read resource.not_found (a permanent condition
// they must not retry) instead of a retryable 5xx. Mirrors the
// ErrSessionNotFound branch above and the kb/doc/chunk not-found fix.
logger.Warnf(ctx, "Message not found, session ID: %s, message ID: %s", sessionID, messageID)
c.Error(errors.NewNotFoundError(err.Error()))
return
}
logger.ErrorWithFields(ctx, err, nil)
c.Error(errors.NewInternalServerError(err.Error()))
return