Skip to content

Self-evolving Context Database for AI Agents. Unify Agent Memory, Knowledge RAG and Skills.

fix(acl): remove automatic schema migration (#4522)

Qin Haojie4d00feac9328
diff --git a/openviking/storage/collection_schemas.py b/openviking/storage/collection_schemas.py
index 8679227fe..716e8c878 100644
--- a/openviking/storage/collection_schemas.py
+++ b/openviking/storage/collection_schemas.py
@@ -19,7 +19,7 @@ from typing import Any, Dict, List, Optional
from openviking.core.context import ContextType, ResourceContentType
from openviking.models.embedder.base import embed_compat
from openviking.server.identity import RequestContext, Role
-from openviking.storage.acl import ACL_CONTEXT_FIELDS, ACL_GRANT_FIELDS
+from openviking.storage.acl import ACL_GRANT_FIELDS
from openviking.storage.errors import (
CollectionNotFoundError,
EmbeddingConfigurationError,
@@ -319,26 +319,6 @@ async def init_context_collection(storage) -> bool:
"Existing collection metadata is unavailable; cannot validate embedding compatibility"
)
- existing_fields = {field.get("FieldName") for field in existing_meta.get("Fields", [])}
- missing_acl_fields = sorted(ACL_CONTEXT_FIELDS - existing_fields)
- existing_scalar_indexes = set(existing_meta.get("ScalarIndex", []))
- missing_acl_indexes = sorted(ACL_CONTEXT_FIELDS - existing_scalar_indexes)
-
- async def _migrate_acl_schema() -> None:
- if not missing_acl_fields and not missing_acl_indexes:
- return
- if vectordb_cfg.backend not in {"local", "cuvs"}:
- raise EmbeddingConfigurationError(
- "Context collection is missing ACL schema: "
- f"fields={missing_acl_fields}, scalar_indexes={missing_acl_indexes}. "
- "Add them to the remote collection before starting OpenViking."
- )
- if not hasattr(storage, "update_collection_schema"):
- raise EmbeddingConfigurationError(
- "Local context collection does not support automatic schema migration"
- )
- await storage.update_collection_schema(schema["Fields"], schema["ScalarIndex"])
-
base_description, existing_embedding_meta = _decode_collection_description(
existing_meta.get("Description")
)
@@ -357,12 +337,10 @@ async def init_context_collection(storage) -> bool:
)
if _embedding_metadata_compatible(existing_embedding_meta, embedding_meta):
- await _migrate_acl_schema()
return False
existing_count = await storage.count() if hasattr(storage, "count") else 0
if existing_embedding_meta is None and existing_count == 0:
- await _migrate_acl_schema()
if hasattr(storage, "update_collection_description"):
await storage.update_collection_description(
_encode_collection_description(
@@ -373,7 +351,6 @@ async def init_context_collection(storage) -> bool:
return False
if existing_embedding_meta is None:
- await _migrate_acl_schema()
logger.warning(
"Existing collection has %d vector(s) but no embedding metadata "
"(created by an older version). Backfilling with current config and continuing.",
@@ -389,7 +366,6 @@ async def init_context_collection(storage) -> bool:
return False
if existing_count == 0 and hasattr(storage, "update_collection_description"):
- await _migrate_acl_schema()
await storage.update_collection_description(
_encode_collection_description(
base_description or "Unified context collection",
@@ -417,7 +393,6 @@ async def init_context_collection(storage) -> bool:
and not dimension_changed
and hasattr(storage, "update_collection_description")
):
- await _migrate_acl_schema()
logger.warning(
"Embedding metadata changed (provider/model) but dimension is "
"unchanged; embedding.allow_metadata_override=true, so the existing "
diff --git a/openviking/storage/viking_vector_index_backend.py b/openviking/storage/viking_vector_index_backend.py
index 4d8cf1202..0920bf58e 100644
--- a/openviking/storage/viking_vector_index_backend.py
+++ b/openviking/storage/viking_vector_index_backend.py
@@ -129,23 +129,6 @@ class _AsyncVectorAdapter:
lambda: self._adapter.get_collection().update(description=description)
)
- async def update_collection_schema(
- self, fields: List[Dict[str, Any]], scalar_index: List[str], index_name: str
- ) -> None:
- def _update() -> None:
- collection = self._adapter.get_collection()
- collection.update(fields=fields)
- if self._adapter.mode in {"local", "cuvs"}:
- index_meta = collection.get_index_meta_data(index_name)
- index_meta["ScalarIndex"] = scalar_index
- collection.drop_index(index_name)
- collection.create_index(index_name, index_meta)
- else:
- collection.update_index(index_name, scalar_index=scalar_index)
-
- await asyncio.to_thread(_update)
-
-
class _SingleAccountBackend:
"""绑定单个 account 的后端实现(内部类)"""
@@ -339,12 +322,6 @@ class _SingleAccountBackend:
await self._refresh_meta_data_async()
return True
- async def update_collection_schema(
- self, fields: List[Dict[str, Any]], scalar_index: List[str]
- ) -> None:
- await self._async_adapter.update_collection_schema(fields, scalar_index, self._index_name)
- await self._refresh_meta_data_async()
-
# =========================================================================
# Data Operations (with tenant enforcement)
# =========================================================================
@@ -902,15 +879,6 @@ class VikingVectorIndexBackend:
async def update_collection_description(self, description: str) -> bool:
return await self._get_default_backend().update_collection_description(description)
- async def update_collection_schema(
- self, fields: List[Dict[str, Any]], scalar_index: List[str]
- ) -> None:
- default_backend = self._get_default_backend()
- await default_backend.update_collection_schema(fields, scalar_index)
- for backend in [*self._account_backends.values(), self._root_backend]:
- if backend is not None and backend is not default_backend:
- await backend._refresh_meta_data_async()
-
# =========================================================================
# 公开数据操作 API(强制要求 ctx)
# =========================================================================
diff --git a/tests/storage/test_collection_schemas.py b/tests/storage/test_collection_schemas.py
index 4e6355d09..b0a0d09cc 100644
--- a/tests/storage/test_collection_schemas.py
+++ b/tests/storage/test_collection_schemas.py
@@ -13,7 +13,6 @@ import requests
from openviking.models.embedder.base import DenseEmbedderBase, EmbedResult
from openviking.server.identity import RequestContext, Role, UserIdentifier
from openviking.service.resource_service import ResourceService
-from openviking.storage.acl import ACL_CONTEXT_FIELDS, ACL_GRANT_FIELDS
from openviking.storage.collection_schemas import (
CollectionSchemas,
TextEmbeddingHandler,
@@ -185,9 +184,8 @@ async def test_init_context_collection_writes_embedding_metadata(monkeypatch):
@pytest.mark.asyncio
-async def test_init_context_collection_migrates_local_legacy_schema(monkeypatch):
+async def test_init_context_collection_backfills_metadata_for_empty_legacy_collection(monkeypatch):
updates = []
- schema_updates = []
class _FakeStorage:
async def create_collection(self, name, schema):
@@ -195,20 +193,7 @@ async def test_init_context_collection_migrates_local_legacy_schema(monkeypatch)
return False
async def get_collection_meta(self):
- schema = CollectionSchemas.context_collection("context", 2)
- return {
- "Description": "Unified context collection",
- "Fields": [
- field
- for field in schema["Fields"]
- if field["FieldName"] not in ACL_CONTEXT_FIELDS
- ],
- "ScalarIndex": [
- field
- for field in schema["ScalarIndex"]
- if field not in ACL_CONTEXT_FIELDS
- ],
- }
+ return {"Description": "Unified context collection"}
async def count(self):
return 0
@@ -217,10 +202,7 @@ async def test_init_context_collection_migrates_local_legacy_schema(monkeypatch)
updates.append(description)
return True
- async def update_collection_schema(self, fields, scalar_index):
- schema_updates.append((fields, scalar_index))
-
- config = _DummyConfig(_DummyEmbedder(), backend="local")
+ config = _DummyConfig(_DummyEmbedder())
monkeypatch.setattr(
"openviking_cli.utils.config.get_openviking_config",
lambda: config,
@@ -230,13 +212,7 @@ async def test_init_context_collection_migrates_local_legacy_schema(monkeypatch)
assert created is False
assert len(updates) == 1
- assert len(schema_updates) == 1
assert '"provider": "local"' in updates[0]
- fields, scalar_index = schema_updates[0]
- fields_by_name = {field["FieldName"]: field for field in fields}
- assert fields_by_name["acl_enabled"]["FieldType"] == "bool"
- assert all(fields_by_name[field]["FieldType"] == "list<string>" for field in ACL_GRANT_FIELDS)
- assert ACL_CONTEXT_FIELDS <= set(scalar_index)
@pytest.mark.asyncio