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): surface native store mutation failures (#5803)
Zheng Haoranf75b6141dc47
diff --git a/openviking/storage/vectordb/store/local_store.py b/openviking/storage/vectordb/store/local_store.pyindex c8213ebb8..cb9030544 100644--- a/openviking/storage/vectordb/store/local_store.py+++ b/openviking/storage/vectordb/store/local_store.py@@ -49,6 +49,12 @@ class StoreEngineProxy(IMutiTableStore):super().__init__()self.storage_engine = storage_engine+ @staticmethod+ def _check_mutation_status(status: int, operation: str) -> None:+ """Raise when a native mutation reports a failure."""+ if status != 0:+ raise RuntimeError(f"Native VectorDB {operation} failed with status {status}")+def read(self, keys: List[str], table_name: str) -> List[bytes]:"""Read values for multiple keys from a table.@@ -74,7 +80,7 @@ class StoreEngineProxy(IMutiTableStore):table_name (str): Table name prefix."""keys = [table_name + key for key in keys]- self.storage_engine.put_data(keys, values)+ self._check_mutation_status(self.storage_engine.put_data(keys, values), "put_data")def delete(self, keys: List[str], table_name: str):"""Delete multiple keys from a table.@@ -84,11 +90,11 @@ class StoreEngineProxy(IMutiTableStore):table_name (str): Table name prefix."""keys = [table_name + key for key in keys]- self.storage_engine.delete_data(keys)+ self._check_mutation_status(self.storage_engine.delete_data(keys), "delete_data")def clear(self):"""Clear all data from the storage engine."""- self.storage_engine.clear_data()+ self._check_mutation_status(self.storage_engine.clear_data(), "clear_data")def read_all(self, table_name: str) -> List[Tuple[str, bytes]]:"""Read all key-value pairs from a table.@@ -278,7 +284,7 @@ class StoreEngineProxy(IMutiTableStore):engine_op.key = table_name + operation.keyengine_op_list.append(engine_op)- self.storage_engine.exec_op(engine_op_list)+ self._check_mutation_status(self.storage_engine.exec_op(engine_op_list), "exec_op")def exec_sequence_batch_op(self, batch_op_list: List[BatchOp]):"""Execute a batch of operations across multiple tables.@@ -308,4 +314,4 @@ class StoreEngineProxy(IMutiTableStore):# Safety check for data_listengine_op.value = batch_op.data_list[i] if i < len(batch_op.data_list) else ""engine_op_list.append(engine_op)- self.storage_engine.exec_op(engine_op_list)+ self._check_mutation_status(self.storage_engine.exec_op(engine_op_list), "exec_op")diff --git a/tests/vectordb/test_cuvs_collection.py b/tests/vectordb/test_cuvs_collection.pyindex e32939e3c..96ed231a2 100644--- a/tests/vectordb/test_cuvs_collection.py+++ b/tests/vectordb/test_cuvs_collection.py@@ -115,6 +115,39 @@ def _delete_without_persisting_index(path, ready, hold):raise+def test_collection_upsert_rejects_native_store_failure(tmp_path, monkeypatch):+ collection = get_or_create_local_collection(+ meta_data={+ "CollectionName": "failed_write",+ "Fields": [+ {"FieldName": "id", "FieldType": "string", "IsPrimaryKey": True},+ {"FieldName": "vector", "FieldType": "vector", "Dim": 4},+ ],+ },+ path=str(tmp_path / "collection"),+ )+ try:+ collection.create_index(+ "default",+ {"IndexName": "default", "VectorIndex": {"IndexType": "flat", "Distance": "ip"}},+ )+ assert collection.upsert_data([{"id": "seed", "vector": [1, 0, 0, 0]}]).ids == ["seed"]+ local = collection._Collection__collection+ index = local.indexes.get("default")+ labels_before = index.search([1, 0, 0, 0], limit=10)[0]+ assert len(labels_before) == 1+ with monkeypatch.context() as failure:+ failure.setattr(local.store_mgr.storage.storage_engine, "exec_op", lambda _ops: -1)+ with pytest.raises(RuntimeError, match="exec_op.*-1"):+ collection.upsert_data([{"id": "lost", "vector": [0, 1, 0, 0]}])+ assert collection.fetch_data(["lost"]).ids_not_exist == ["lost"]+ assert index.search([1, 0, 0, 0], limit=10)[0] == labels_before+ result = collection.search_by_vector("default", dense_vector=[0, 1, 0, 0], limit=10)+ assert [item.id for item in result.data] == ["seed"]+ finally:+ collection.close()++def test_local_collection_routes_dense_search_to_cuvs(monkeypatch):patch_cuvs_runtime(monkeypatch)collection = get_or_create_local_collection(diff --git a/tests/vectordb/test_store_streaming.py b/tests/vectordb/test_store_streaming.pyindex 7add1d426..387f37903 100644--- a/tests/vectordb/test_store_streaming.py+++ b/tests/vectordb/test_store_streaming.py@@ -12,6 +12,7 @@ from openviking.storage.vectordb.store.local_store import (STORE_SCAN_PAGE_SIZE,StoreEngineProxy,)+from openviking.storage.vectordb.store.store import BatchOp, Op, OpTypefrom openviking.storage.vectordb.store.store_manager import StoreManager@@ -197,6 +198,37 @@ def test_closing_store_stream_releases_the_current_encoded_page():assert not any(page_ref() is not None for page_ref in storage_engine.page_refs)+ ("operation", "native_method"),+ [+ ("write", "put_data"),+ ("delete", "delete_data"),+ ("clear", "clear_data"),+ ("exec_sequence", "exec_op"),+ ("exec_sequence_batch_op", "exec_op"),+ ],+)[email protected]("status", [0, -1])+def test_store_proxy_checks_native_mutation_status(operation, native_method, status, monkeypatch):+ native = engine.VolatileStore()+ monkeypatch.setattr(native, native_method, lambda *_args: status)+ store = StoreEngineProxy(native)+ calls = {+ "write": lambda: store.write(["key"], [b"value"], "test:"),+ "delete": lambda: store.delete(["key"], "test:"),+ "clear": store.clear,+ "exec_sequence": lambda: store.exec_sequence([Op(OpType.PUT, "key", b"value")], "test:"),+ "exec_sequence_batch_op": lambda: store.exec_sequence_batch_op(+ [BatchOp("test:", OpType.PUT, ["key"], [b"value"])]+ ),+ }+ if status:+ with pytest.raises(RuntimeError, match=f"{native_method}.*{status}"):+ calls[operation]()+ else:+ assert calls[operation]() is None++def test_native_volatile_store_paged_scan_abi():if engine.ENGINE_VARIANT == "unavailable":pytest.skip("No native VectorDB engine is packaged in this test environment")