Add knowledge retrieval configuration to Assistant model and related components

- Introduce new fields for knowledge retrieval configuration in AssistantConfig and Assistant models, including mode, top_n, and score_threshold.
- Implement KnowledgeRetrievalConfig schema with validation for top_n.
- Update backend services and routes to handle knowledge retrieval settings.
- Enhance frontend components to support knowledge retrieval configuration, including a new dialog for advanced settings.
- Add tests for knowledge retrieval configuration validation and description generation.
This commit is contained in:
Xin Wang
2026-07-12 18:57:56 +08:00
parent 7ee3e22152
commit 7c9a18c806
13 changed files with 465 additions and 47 deletions

View File

@@ -1,5 +1,8 @@
import unittest
from pydantic import ValidationError
from schemas import KnowledgeRetrievalConfig
from services.knowledge import extract_text, split_text
@@ -19,5 +22,22 @@ class KnowledgeTextTest(unittest.TestCase):
extract_text("archive.zip", b"data")
class KnowledgeRetrievalConfigTest(unittest.TestCase):
def test_accepts_unlimited_top_n_with_threshold(self):
config = KnowledgeRetrievalConfig.model_validate(
{"mode": "on_demand", "topN": -1, "scoreThreshold": 0.65}
)
self.assertEqual(config.top_n, -1)
self.assertEqual(
config.model_dump(by_alias=True),
{"mode": "on_demand", "topN": -1, "scoreThreshold": 0.65},
)
def test_rejects_zero_top_n(self):
with self.assertRaises(ValidationError):
KnowledgeRetrievalConfig(top_n=0)
if __name__ == "__main__":
unittest.main()