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
+4 -1
View File
@@ -5,6 +5,7 @@ package service
import (
"context"
"errors"
"fmt"
"github.com/Tencent/WeKnora/internal/application/service/retriever"
@@ -107,7 +108,9 @@ func (s *chunkService) GetChunkByID(ctx context.Context, id string) (*types.Chun
func (s *chunkService) GetChunkByIDOnly(ctx context.Context, id string) (*types.Chunk, error) {
chunk, err := s.chunkRepository.GetChunkByIDOnly(ctx, id)
if err != nil {
if err != nil && err.Error() == "chunk not found" {
// errors.Is (not string equality) so the sentinel survives wrapping.
// ErrChunkNotFound aliases the repo sentinel, so this matches directly.
if errors.Is(err, ErrChunkNotFound) {
return nil, ErrChunkNotFound
}
logger.ErrorWithFields(ctx, err, map[string]interface{}{"chunk_id": id})
+5 -2
View File
@@ -26,8 +26,11 @@ var (
ErrInvalidFileType = errors.New("unsupported file type")
// ErrInvalidURL is returned when an invalid URL is provided
ErrInvalidURL = errors.New("invalid URL")
// ErrChunkNotFound is returned when a requested chunk cannot be found
ErrChunkNotFound = errors.New("chunk not found")
// ErrChunkNotFound is returned when a requested chunk cannot be found.
// Aliases the repository sentinel so a chunk-not-found from the repo
// errors.Is-matches at the service and middleware layers (a single
// identity instead of two string-equal-but-distinct errors).
ErrChunkNotFound = repository.ErrChunkNotFound
// ErrDuplicateFile is returned when trying to add a file that already exists
ErrDuplicateFile = errors.New("file already exists")
// ErrDuplicateURL is returned when trying to add a URL that already exists