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(vectordb): share single adapter across account backends to prevent RocksDB lock contention (#777)
Ahmed Hesham Abdelkader337e51f57693
diff --git a/openviking/storage/viking_vector_index_backend.py b/openviking/storage/viking_vector_index_backend.pyindex 5a8b06e8b..b3f8f09e6 100644--- a/openviking/storage/viking_vector_index_backend.py+++ b/openviking/storage/viking_vector_index_backend.py@@ -21,16 +21,26 @@ logger = get_logger(__name__)class _SingleAccountBackend:"""绑定单个 account 的后端实现(内部类)"""- def __init__(self, config: VectorDBBackendConfig, bound_account_id: Optional[str]):+ def __init__(+ self,+ config: VectorDBBackendConfig,+ bound_account_id: Optional[str],+ shared_adapter=None,+ ):"""初始化单 account 后端。Args:config: VectorDB 配置bound_account_id: 绑定的 account_id,None 表示 root 特权模式+ shared_adapter: Optional pre-created adapter to share across backends.+ If provided, reuses the existing adapter (and its underlying+ PersistStore) instead of creating a new one. This avoids+ RocksDB LOCK contention when multiple account backends point+ to the same storage path."""self._bound_account_id = bound_account_id- self._adapter = create_collection_adapter(config)+ self._adapter = shared_adapter or create_collection_adapter(config)self._collection_config: Dict[str, Any] = {}self._meta_data_cache: Dict[str, Any] = {}self._mode = self._adapter.mode@@ -429,6 +439,9 @@ class VikingVectorIndexBackend:self._account_backends: Dict[str, _SingleAccountBackend] = {}self._root_backend: Optional[_SingleAccountBackend] = None+ # Share a single adapter (and its underlying PersistStore/RocksDB instance)+ # across all account backends to avoid LOCK contention.+ self._shared_adapter = create_collection_adapter(config)logger.info("VikingVectorIndexBackend facade initialized",@@ -453,7 +466,7 @@ class VikingVectorIndexBackend:def _get_backend_for_account(self, account_id: str) -> _SingleAccountBackend:"""获取指定 account 的 backend,懒创建"""if account_id not in self._account_backends:- backend = _SingleAccountBackend(self._config, bound_account_id=account_id)+ backend = _SingleAccountBackend(self._config, bound_account_id=account_id, shared_adapter=self._shared_adapter)backend._distance_metric = self.distance_metricbackend._sparse_weight = self.sparse_weightbackend._collection_name = self._collection_name@@ -467,7 +480,7 @@ class VikingVectorIndexBackend:def _get_root_backend(self) -> _SingleAccountBackend:"""获取 root 特权 backend"""if not self._root_backend:- self._root_backend = _SingleAccountBackend(self._config, bound_account_id=None)+ self._root_backend = _SingleAccountBackend(self._config, bound_account_id=None, shared_adapter=self._shared_adapter)self._root_backend._distance_metric = self.distance_metricself._root_backend._sparse_weight = self.sparse_weightself._root_backend._collection_name = self._collection_name