fix(app): prevent UTF-8 truncation in summary fallback
When LLM summary generation fails, the fallback logic truncates the first chunk content to 500 characters. Previously used byte-based slicing (summary[:500]) which could cut multi-byte UTF-8 characters in half, causing PostgreSQL to reject invalid byte sequences. Changed to rune-based truncation to ensure valid UTF-8 after truncation. Fixes: Documents stuck in "Generating summary" status when containing Chinese/emoji characters and summary generation fails.
This commit is contained in:
@@ -2082,7 +2082,11 @@ func (s *knowledgeService) ProcessSummaryGeneration(ctx context.Context, t *asyn
|
||||
if len(textChunks) > 0 {
|
||||
summary = textChunks[0].Content
|
||||
if len(summary) > 500 {
|
||||
summary = summary[:500]
|
||||
// Use rune-based truncation to avoid cutting UTF-8 multi-byte characters
|
||||
runes := []rune(summary)
|
||||
if len(runes) > 500 {
|
||||
summary = string(runes[:500])
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user