RAGFlow is an agent-native database: a Retrieval-Augmented Generation (RAG) engine that grew into context infrastructure.
Go agent-harnessagent-native-databaseagentic-aiagentic-retrievalagentic-searchaiai-agentscontext-enginecontext-engineeringcontext-managementharness-engineeringknowledge-compilationragretrieval-augmented-generationretrieval-harnesssearch-harness
Fix: append attachment content to last user prompt (#19691)
Wang Qid7223f2eba03
diff --git a/internal/service/chat_pipeline.go b/internal/service/chat_pipeline.goindex 7e9ce5a271..b4cdc81bf5 100644--- a/internal/service/chat_pipeline.go+++ b/internal/service/chat_pipeline.go@@ -332,7 +332,7 @@ func (s *ChatPipelineService) AsyncChat(// Whether the message carried image attachments before the// vision gate (read by the empty-response fallback below).var hasImageAttachments bool- // Joined text attachments (appended to system prompt).+ // Joined text attachments (appended to the last user message).var attachments string// When files are file dicts, splitFileAttachments fetches blobs// from storage. When plain strings, falls back to string splitting;@@ -956,7 +956,7 @@ func (s *ChatPipelineService) AsyncChat(// must reach a vision model instead of being swallowed by the// canned response. In that case we skip the early return and fall// through to the normal LLM call where attachments are appended to- // the system prompt.+ // the last user message.//// Two results are yielded (mirroring Python dialog_service.py):// 1. Final=false — carries the answer text so streaming consumers@@ -992,7 +992,7 @@ func (s *ChatPipelineService) AsyncChat(}systemPrompt = ""if sp, ok := promptConfig["system"].(string); ok {- systemPrompt = s.formatPrompt(sp, kwargs) + attachments+ systemPrompt = s.formatPrompt(sp, kwargs)// If knowledge was retrieved but the template has no {knowledge}// placeholder, auto-append it so the LLM still sees the context.if len(knowledges) > 0 && !strings.Contains(sp, "{knowledge}") {@@ -1053,6 +1053,11 @@ func (s *ChatPipelineService) AsyncChat(llmMessage["content"] = contentllmMessages = append(llmMessages, llmMessage)}+ if attachments != "" && len(llmMessages) > 0 {+ if lastContent, ok := llmMessages[len(llmMessages)-1]["content"].(string); ok {+ llmMessages[len(llmMessages)-1]["content"] = lastContent + attachments+ }+ }// Fit messages within token budget.usedTokenCount, llmMessages := s.messageFitIn(llmMessages, int(float64(modelMaxTokens)*0.95))diff --git a/internal/service/file/file_content.go b/internal/service/file/file_content.goindex 012b4d4e46..0abb3a6929 100644--- a/internal/service/file/file_content.go+++ b/internal/service/file/file_content.go@@ -146,7 +146,8 @@ func (s *FileService) GetFileContents(ctx context.Context, uid string, fileDicts}images = append(images, "data:"+mediaType+";base64,"+base64.StdEncoding.EncodeToString(data))} else {- texts = append(texts, parseFileContent(ctx, name, data))+ content := parseFileContent(ctx, name, data)+ texts = append(texts, fmt.Sprintf("\n -----------------\nFile: %s\nContent as following: \n%s", name, content))}}return texts, images, nildiff --git a/internal/service/file/file_test.go b/internal/service/file/file_test.goindex 3bd4239252..a2b3fa66de 100644--- a/internal/service/file/file_test.go+++ b/internal/service/file/file_test.go@@ -185,8 +185,9 @@ func TestFileService_GetFileContents_Accessible(t *testing.T) {if len(images) != 0 {t.Fatalf("expected no images, got %v", images)}- if len(texts) != 1 || !strings.Contains(texts[0], "allowed content") {- t.Fatalf("unexpected texts: %v", texts)+ want := "\n -----------------\nFile: doc.txt\nContent as following: \nallowed content"+ if len(texts) != 1 || texts[0] != want {+ t.Fatalf("texts = %v, want %q", texts, want)}}