Build and run agents you can see, understand and trust.
Python agentchatbotlarge-language-modelsllmllm-agentmcpmulti-agentmulti-modalreact-agentrealtime-agentvoice-agentvoice-assistant
fix(rag): reject a non-positive top_k in search (#3876)
lianbieff14ca38004b
diff --git a/src/agentscope/rag/_knowledge.py b/src/agentscope/rag/_knowledge.pyindex 5618e8fdb..58e2c36f9 100644--- a/src/agentscope/rag/_knowledge.py+++ b/src/agentscope/rag/_knowledge.py@@ -219,7 +219,7 @@ class KnowledgeBase:therefore pass a mixed list without per-KB filtering.top_k (`int`, defaults to ``5``):Maximum number of results returned across all queries- (after dedup).+ (after dedup). Must be at least ``1``.score_threshold (`float | None`, optional):Minimum :attr:`VectorSearchResult.score` for a hit tobe retained. The scale depends on the store's metric —@@ -232,7 +232,14 @@ class KnowledgeBase:At most ``top_k`` deduplicated hits ordered bydescending similarity score. Empty when there are noqueries the bound embedding model can consume.++ Raises:+ `ValueError`:+ If ``top_k`` is not positive."""+ if top_k < 1:+ raise ValueError("top_k must be positive.")+if not queries:return []