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(benchmark): enforce configured search concurrency (#3091)
Yuanqing ZHAOd61d802fd047
diff --git a/benchmark/vectordb_perf/async_utils.py b/benchmark/vectordb_perf/async_utils.pynew file mode 100644index 000000000..7e2b3a1b8--- /dev/null+++ b/benchmark/vectordb_perf/async_utils.py@@ -0,0 +1,38 @@+# Copyright (c) 2026 Beijing Volcano Engine Technology Co., Ltd.+# SPDX-License-Identifier: AGPL-3.0+"""Dependency-light async helpers for the VectorDB benchmark."""++from __future__ import annotations++import asyncio+from collections.abc import AsyncIterator, Awaitable, Callable, Iterable+from typing import TypeVar+++_T = TypeVar("_T")+_R = TypeVar("_R")+++async def map_bounded_as_completed(+ items: Iterable[_T],+ fn: Callable[[_T], Awaitable[_R]],+ concurrency: int,+) -> AsyncIterator[_R]:+ """Run ``fn`` with bounded in-flight calls and yield results as they finish."""++ semaphore = asyncio.Semaphore(max(1, concurrency))++ async def bounded(item: _T) -> _R:+ async with semaphore:+ return await fn(item)++ tasks = [asyncio.create_task(bounded(item)) for item in items]+ try:+ for future in asyncio.as_completed(tasks):+ yield await future+ finally:+ for task in tasks:+ if not task.done():+ task.cancel()+ if tasks:+ await asyncio.gather(*tasks, return_exceptions=True)diff --git a/benchmark/vectordb_perf/run.py b/benchmark/vectordb_perf/run.pyindex 6440bcc39..d7ae7aebd 100644--- a/benchmark/vectordb_perf/run.py+++ b/benchmark/vectordb_perf/run.py@@ -29,6 +29,8 @@ from datetime import UTC, datetimefrom pathlib import Pathfrom typing import Any, Callable, Iterable, Iterator, Optional, Sequence+from benchmark.vectordb_perf.async_utils import map_bounded_as_completed+from openviking.storage.expr import PathScopefrom openviking.server.identity import RequestContext, Rolefrom openviking.storage.collection_schemas import CollectionSchemas@@ -787,9 +789,9 @@ async def run_search_phase(event, rows = await one_query(query)return query, event, rows- pending = [asyncio.create_task(tagged_query(query)) for query in queries]- for future in asyncio.as_completed(pending):- query, event, rows = await future+ async for query, event, rows in map_bounded_as_completed(+ queries, tagged_query, workers+ ):events.append(event)results.append((query, rows or []))done += 1diff --git a/tests/benchmark/test_vectordb_perf_async_utils.py b/tests/benchmark/test_vectordb_perf_async_utils.pynew file mode 100644index 000000000..4efacb8f8--- /dev/null+++ b/tests/benchmark/test_vectordb_perf_async_utils.py@@ -0,0 +1,52 @@+# Copyright (c) 2026 Beijing Volcano Engine Technology Co., Ltd.+# SPDX-License-Identifier: AGPL-3.0++import asyncio++import pytest++from benchmark.vectordb_perf.async_utils import map_bounded_as_completed+++async def test_map_bounded_as_completed_limits_peak_in_flight_calls():+ active = 0+ peak_active = 0++ async def worker(value: int) -> int:+ nonlocal active, peak_active+ active += 1+ peak_active = max(peak_active, active)+ await asyncio.sleep(0.001)+ active -= 1+ return value++ results = [+ result+ async for result in map_bounded_as_completed(range(20), worker, concurrency=4)+ ]++ assert sorted(results) == list(range(20))+ assert peak_active == 4+++async def test_map_bounded_as_completed_treats_non_positive_concurrency_as_one():+ active = 0+ peak_active = 0++ async def worker(value: int) -> int:+ nonlocal active, peak_active+ active += 1+ peak_active = max(peak_active, active)+ await asyncio.sleep(0)+ active -= 1+ return value++ results = [+ result+ async for result in map_bounded_as_completed(range(3), worker, concurrency=0)+ ]++ assert sorted(results) == [0, 1, 2]+ assert peak_active == 1