Self-evolving Context Database for AI Agents. Unify Agent Memory, Knowledge RAG and Skills.
Python agent-contextagent-memoryagent-pluginsagentic-ragcontext-databasedsh-pluginknowledge-basememorymemory-managementself-evolvingvector-database
fix(search): reject non-positive retrieval limits at the API boundary (#5926)
bot-of-qin-ctx50ca28dc2cd6
diff --git a/openviking/server/routers/search.py b/openviking/server/routers/search.pyindex 6f292907c..26e4fe9d6 100644--- a/openviking/server/routers/search.py+++ b/openviking/server/routers/search.py@@ -130,8 +130,8 @@ class FindRequest(BaseModel):image_url: Optional[str] = Nonetarget_uri: Union[str, List[str]] = ""context_type: Optional[Union[str, List[str]]] = None- limit: int = DEFAULT_LIMIT- node_limit: Optional[int] = None+ limit: int = Field(default=DEFAULT_LIMIT, ge=1)+ node_limit: Optional[int] = Field(default=None, ge=1)score_threshold: Optional[float] = Nonefilter: Optional[Dict[str, Any]] = Noneinclude_provenance: bool = False@@ -224,8 +224,8 @@ class SearchRequest(BaseModel):target_uri: Union[str, List[str]] = ""context_type: Optional[Union[str, List[str]]] = Nonesession_id: Optional[str] = None- limit: int = DEFAULT_LIMIT- node_limit: Optional[int] = None+ limit: int = Field(default=DEFAULT_LIMIT, ge=1)+ node_limit: Optional[int] = Field(default=None, ge=1)score_threshold: Optional[float] = Nonefilter: Optional[Dict[str, Any]] = Noneinclude_provenance: bool = Falsediff --git a/tests/server/test_api_search.py b/tests/server/test_api_search.pyindex bbbe5d292..db59f9966 100644--- a/tests/server/test_api_search.py+++ b/tests/server/test_api_search.py@@ -859,10 +859,22 @@ async def test_find_with_invalid_time_returns_invalid_argument(client: httpx.Asyassert body["error"]["message"]-async def test_find_with_invalid_time_field_returns_invalid_argument(client: httpx.AsyncClient):[email protected]("endpoint", ["/api/v1/search/find", "/api/v1/search/search"])+ "fields",+ [+ {"time_field": "published_at", "since": "2h"},+ {"limit": 0},+ {"limit": -1},+ {"node_limit": 0},+ {"node_limit": -1},+ {"limit": 0, "node_limit": 5},+ ],+)+async def test_search_rejects_invalid_request_fields(client: httpx.AsyncClient, endpoint, fields):resp = await client.post(- "/api/v1/search/find",- json={"query": "sample", "time_field": "published_at", "since": "2h"},+ endpoint,+ json={"query": "sample", **fields},)assert resp.status_code == 400@@ -870,6 +882,7 @@ async def test_find_with_invalid_time_field_returns_invalid_argument(client: httassert body["status"] == "error"assert body["error"]["code"] == "INVALID_ARGUMENT"assert body["error"]["message"]+ assert body["error"]["details"]["validation_errors"]async def test_find_with_inverted_mixed_time_range_returns_invalid_argument(