Skip to content

Open-source LLM knowledge platform: turn raw documents into a queryable RAG, an autonomous reasoning agent, and a self-maintaining Wiki.

fix(faq): actually clean FAQ entry payloads before validation and storage

Victor Maznyuk5bf2ae1cc27a
diff --git a/internal/application/service/knowledge_faq.go b/internal/application/service/knowledge_faq.go
index 01e288fe8..49aa52ec4 100644
--- a/internal/application/service/knowledge_faq.go
+++ b/internal/application/service/knowledge_faq.go
@@ -1862,7 +1862,7 @@ func sanitizeFAQEntryPayload(payload *types.FAQEntryPayload) (*types.FAQChunkMet
Version: 1,
Source: "faq",
}
- meta.Normalize()
+ meta.Sanitize()
if meta.StandardQuestion == "" {
return nil, werrors.NewBadRequestError("标准问不能为空")
}
diff --git a/internal/application/service/knowledge_faq_sanitize_test.go b/internal/application/service/knowledge_faq_sanitize_test.go
new file mode 100644
index 000000000..8357d3543
--- /dev/null
+++ b/internal/application/service/knowledge_faq_sanitize_test.go
@@ -0,0 +1,44 @@
+package service
+
+import (
+ "testing"
+
+ "github.com/Tencent/WeKnora/internal/types"
+ "github.com/stretchr/testify/require"
+)
+
+func TestSanitizeFAQEntryPayloadCleansQuestionLists(t *testing.T) {
+ meta, err := sanitizeFAQEntryPayload(&types.FAQEntryPayload{
+ StandardQuestion: " How do I reset my password? ",
+ SimilarQuestions: []string{"", " Forgot password ", "Forgot password", " "},
+ NegativeQuestions: []string{" ", "Reset username", " Reset username "},
+ Answers: []string{" Use the reset link. ", "", "Use the reset link."},
+ })
+ require.NoError(t, err)
+ require.Equal(t, "How do I reset my password?", meta.StandardQuestion)
+ require.Equal(t, []string{"Forgot password"}, meta.SimilarQuestions)
+ require.Equal(t, []string{"Reset username"}, meta.NegativeQuestions)
+ require.Equal(t, []string{"Use the reset link."}, meta.Answers)
+}
+
+func TestSanitizeFAQEntryPayloadKeepsOriginalText(t *testing.T) {
+ // Storage keeps what the user wrote: only whitespace and duplicates are
+ // dropped, no lower-casing or punctuation stripping (that is Normalize,
+ // which is for hashing and indexing).
+ meta, err := sanitizeFAQEntryPayload(&types.FAQEntryPayload{
+ StandardQuestion: "What is WeKnora?",
+ SimilarQuestions: []string{"Tell me about WeKnora!"},
+ Answers: []string{"A RAG framework."},
+ })
+ require.NoError(t, err)
+ require.Equal(t, "What is WeKnora?", meta.StandardQuestion)
+ require.Equal(t, []string{"Tell me about WeKnora!"}, meta.SimilarQuestions)
+}
+
+func TestSanitizeFAQEntryPayloadRejectsBlankAnswers(t *testing.T) {
+ _, err := sanitizeFAQEntryPayload(&types.FAQEntryPayload{
+ StandardQuestion: "How do I reset my password?",
+ Answers: []string{" ", ""},
+ })
+ require.Error(t, err)
+}