Skip to content

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

feat(vectordb): make default index name configurable (#861)

Jiahui Zhou32374dbf9aea
diff --git a/openviking/service/core.py b/openviking/service/core.py
index 16e1db153..4f58cd5f4 100644
--- a/openviking/service/core.py
+++ b/openviking/service/core.py
@@ -238,15 +238,6 @@ class OpenVikingService:
acquire_data_dir_lock(self._config.storage.workspace)
- # Clean up stale RocksDB LOCK files left by crashed processes.
- # On Windows, these persist after process death and block PersistStore
- # from opening (see https://github.com/volcengine/OpenViking/issues/650).
- from openviking.storage.vectordb.utils.stale_lock import (
- clean_stale_rocksdb_locks,
- )
-
- clean_stale_rocksdb_locks(self._config.storage.workspace)
-
if self._vikingdb_manager is None:
self._init_storage(
self._config.storage,
diff --git a/openviking/storage/vectordb/store/local_store.py b/openviking/storage/vectordb/store/local_store.py
index b1ab54cb5..3b56a5dda 100644
--- a/openviking/storage/vectordb/store/local_store.py
+++ b/openviking/storage/vectordb/store/local_store.py
@@ -4,6 +4,7 @@ from typing import List, Tuple, Union
import openviking.storage.vectordb.engine as engine
from openviking.storage.vectordb.store.store import BatchOp, IMutiTableStore, Op, OpType
+from openviking.storage.vectordb.utils.stale_lock import clean_stale_rocksdb_locks
# Constant for the maximum Unicode character, used for range queries to cover all possible keys
MAX_UNICODE_CHAR = "\U0010ffff"
@@ -19,7 +20,11 @@ def create_store_engine_proxy(path: str = "") -> "StoreEngineProxy":
Returns:
StoreEngineProxy: Proxy instance wrapping the underlying storage engine.
"""
- date_engine = engine.PersistStore(path) if path else engine.VolatileStore()
+ if path:
+ clean_stale_rocksdb_locks(path)
+ date_engine = engine.PersistStore(path)
+ else:
+ date_engine = engine.VolatileStore()
return StoreEngineProxy(date_engine)
diff --git a/openviking/storage/vectordb_adapters/base.py b/openviking/storage/vectordb_adapters/base.py
index 6afbf316f..66ecc799c 100644
--- a/openviking/storage/vectordb_adapters/base.py
+++ b/openviking/storage/vectordb_adapters/base.py
@@ -25,6 +25,7 @@ from openviking.storage.expr import (
from openviking.storage.vectordb.collection.collection import Collection
from openviking.storage.vectordb.collection.result import FetchDataInCollectionResult
from openviking_cli.utils import get_logger
+from openviking_cli.utils.config.vectordb_config import DEFAULT_INDEX_NAME
logger = get_logger(__name__)
@@ -61,14 +62,19 @@ class CollectionAdapter(ABC):
mode: str
_URI_FIELD_NAMES = {"uri", "parent_uri"}
- def __init__(self, collection_name: str):
+ def __init__(self, collection_name: str, index_name: str = DEFAULT_INDEX_NAME):
self._collection_name = collection_name
+ self._index_name = index_name
self._collection: Optional[Collection] = None
@property
def collection_name(self) -> str:
return self._collection_name
+ @property
+ def index_name(self) -> str:
+ return self._index_name
+
@classmethod
@abstractmethod
def from_config(cls, config: Any) -> "CollectionAdapter":
@@ -105,6 +111,7 @@ class CollectionAdapter(ABC):
return False
self._collection_name = name
+ self._index_name = index_name
collection_meta = dict(schema)
scalar_index_fields = collection_meta.pop("ScalarIndex", [])
if "CollectionName" not in collection_meta:
@@ -420,7 +427,7 @@ class CollectionAdapter(ABC):
if query_vector or sparse_query_vector:
result = coll.search_by_vector(
- index_name="default",
+ index_name=self._index_name,
dense_vector=query_vector,
sparse_vector=sparse_query_vector,
limit=limit,
@@ -430,7 +437,7 @@ class CollectionAdapter(ABC):
)
elif order_by:
result = coll.search_by_scalar(
- index_name="default",
+ index_name=self._index_name,
field=order_by,
order="desc" if order_desc else "asc",
limit=limit,
@@ -440,7 +447,7 @@ class CollectionAdapter(ABC):
)
else:
result = coll.search_by_random(
- index_name="default",
+ index_name=self._index_name,
limit=limit,
offset=offset,
filters=vectordb_filter,
@@ -492,7 +499,7 @@ class CollectionAdapter(ABC):
def count(self, filter: Optional[Dict[str, Any] | FilterExpr] = None) -> int:
coll = self.get_collection()
result = coll.aggregate_data(
- index_name="default",
+ index_name=self._index_name,
op="count",
filters=self._compile_filter(filter),
)
diff --git a/openviking/storage/vectordb_adapters/http_adapter.py b/openviking/storage/vectordb_adapters/http_adapter.py
index d33b72435..31082e9a5 100644
--- a/openviking/storage/vectordb_adapters/http_adapter.py
+++ b/openviking/storage/vectordb_adapters/http_adapter.py
@@ -19,8 +19,15 @@ from .base import CollectionAdapter, _normalize_collection_names, _parse_url
class HttpCollectionAdapter(CollectionAdapter):
"""Adapter for remote HTTP vectordb project."""
- def __init__(self, host: str, port: int, project_name: str, collection_name: str):
- super().__init__(collection_name=collection_name)
+ def __init__(
+ self,
+ host: str,
+ port: int,
+ project_name: str,
+ collection_name: str,
+ index_name: str,
+ ):
+ super().__init__(collection_name=collection_name, index_name=index_name)
self.mode = "http"
self._host = host
self._port = port
@@ -36,6 +43,7 @@ class HttpCollectionAdapter(CollectionAdapter):
port=port,
project_name=config.project_name or "default",
collection_name=config.name or "context",
+ index_name=config.index_name or "default",
)
def _meta(self) -> Dict[str, Any]:
diff --git a/openviking/storage/vectordb_adapters/local_adapter.py b/openviking/storage/vectordb_adapters/local_adapter.py
index 29489e448..ef0a3ae08 100644
--- a/openviking/storage/vectordb_adapters/local_adapter.py
+++ b/openviking/storage/vectordb_adapters/local_adapter.py
@@ -19,8 +19,8 @@ class LocalCollectionAdapter(CollectionAdapter):
DEFAULT_LOCAL_PROJECT_NAME = "vectordb"
- def __init__(self, collection_name: str, project_path: str):
- super().__init__(collection_name=collection_name)
+ def __init__(self, collection_name: str, project_path: str, index_name: str):
+ super().__init__(collection_name=collection_name, index_name=index_name)
self.mode = "local"
self._project_path = project_path
@@ -29,7 +29,11 @@ class LocalCollectionAdapter(CollectionAdapter):
project_path = (
str(Path(config.path) / cls.DEFAULT_LOCAL_PROJECT_NAME) if config.path else ""
)
- return cls(collection_name=config.name or "context", project_path=project_path)
+ return cls(
+ collection_name=config.name or "context",
+ project_path=project_path,
+ index_name=config.index_name or "default",
+ )
def _collection_path(self) -> str:
if not self._project_path:
diff --git a/openviking/storage/vectordb_adapters/vikingdb_private_adapter.py b/openviking/storage/vectordb_adapters/vikingdb_private_adapter.py
index bb7ee1964..43c6c9001 100644
--- a/openviking/storage/vectordb_adapters/vikingdb_private_adapter.py
+++ b/openviking/storage/vectordb_adapters/vikingdb_private_adapter.py
@@ -23,8 +23,9 @@ class VikingDBPrivateCollectionAdapter(CollectionAdapter):
headers: Optional[dict[str, str]],
project_name: str,
collection_name: str,
+ index_name: str,
):
- super().__init__(collection_name=collection_name)
+ super().__init__(collection_name=collection_name, index_name=index_name)
self.mode = "vikingdb"
self._host = host
self._headers = headers
@@ -39,6 +40,7 @@ class VikingDBPrivateCollectionAdapter(CollectionAdapter):
headers=config.vikingdb.headers,
project_name=config.project_name or "default",
collection_name=config.name or "context",
+ index_name=config.index_name or "default",
)
def _client(self) -> VikingDBClient:
diff --git a/openviking/storage/vectordb_adapters/volcengine_adapter.py b/openviking/storage/vectordb_adapters/volcengine_adapter.py
index 66ac0d8b6..b9e09cbe8 100644
--- a/openviking/storage/vectordb_adapters/volcengine_adapter.py
+++ b/openviking/storage/vectordb_adapters/volcengine_adapter.py
@@ -26,8 +26,9 @@ class VolcengineCollectionAdapter(CollectionAdapter):
region: str,
project_name: str,
collection_name: str,
+ index_name: str,
):
- super().__init__(collection_name=collection_name)
+ super().__init__(collection_name=collection_name, index_name=index_name)
self.mode = "volcengine"
self._ak = ak
self._sk = sk
@@ -49,6 +50,7 @@ class VolcengineCollectionAdapter(CollectionAdapter):
region=config.volcengine.region,
project_name=config.project_name or "default",
collection_name=config.name or "context",
+ index_name=config.index_name or "default",
)
def _meta(self) -> Dict[str, Any]:
diff --git a/openviking/storage/viking_vector_index_backend.py b/openviking/storage/viking_vector_index_backend.py
index b3f8f09e6..43925ac4d 100644
--- a/openviking/storage/viking_vector_index_backend.py
+++ b/openviking/storage/viking_vector_index_backend.py
@@ -13,7 +13,7 @@ from openviking.storage.vectordb.collection.collection import Collection
from openviking.storage.vectordb.utils.logging_init import init_cpp_logging
from openviking.storage.vectordb_adapters import create_collection_adapter
from openviking_cli.utils import get_logger
-from openviking_cli.utils.config.vectordb_config import VectorDBBackendConfig
+from openviking_cli.utils.config.vectordb_config import DEFAULT_INDEX_NAME, VectorDBBackendConfig
logger = get_logger(__name__)
@@ -47,6 +47,7 @@ class _SingleAccountBackend:
self._distance_metric = "cosine"
self._sparse_weight = 0.0
self._collection_name = "context"
+ self._index_name = config.index_name or DEFAULT_INDEX_NAME
logger.info(
"_SingleAccountBackend initialized (bound_account_id=%s, mode=%s)",
@@ -92,7 +93,7 @@ class _SingleAccountBackend:
schema=collection_meta,
distance=self._distance_metric,
sparse_weight=self._sparse_weight,
- index_name=VikingVectorIndexBackend.DEFAULT_INDEX_NAME,
+ index_name=self._index_name,
)
if not created:
return False
@@ -422,7 +423,6 @@ class _SingleAccountBackend:
class VikingVectorIndexBackend:
"""单例门面,管理 per-account 后端实例"""
- DEFAULT_INDEX_NAME = "default"
ALLOWED_CONTEXT_TYPES = {"resource", "skill", "memory"}
def __init__(self, config: Optional[VectorDBBackendConfig]):
@@ -436,6 +436,7 @@ class VikingVectorIndexBackend:
self.distance_metric = config.distance_metric
self.sparse_weight = config.sparse_weight
self._collection_name = config.name or "context"
+ self._index_name = config.index_name or DEFAULT_INDEX_NAME
self._account_backends: Dict[str, _SingleAccountBackend] = {}
self._root_backend: Optional[_SingleAccountBackend] = None
@@ -466,10 +467,13 @@ 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, shared_adapter=self._shared_adapter)
+ backend = _SingleAccountBackend(
+ self._config, bound_account_id=account_id, shared_adapter=self._shared_adapter
+ )
backend._distance_metric = self.distance_metric
backend._sparse_weight = self.sparse_weight
backend._collection_name = self._collection_name
+ backend._index_name = self._index_name
self._account_backends[account_id] = backend
return self._account_backends[account_id]
@@ -480,10 +484,13 @@ 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, shared_adapter=self._shared_adapter)
+ self._root_backend = _SingleAccountBackend(
+ self._config, bound_account_id=None, shared_adapter=self._shared_adapter
+ )
self._root_backend._distance_metric = self.distance_metric
self._root_backend._sparse_weight = self.sparse_weight
self._root_backend._collection_name = self._collection_name
+ self._root_backend._index_name = self._index_name
return self._root_backend
def _check_root_role(self, ctx: RequestContext) -> None:
diff --git a/openviking_cli/utils/config/vectordb_config.py b/openviking_cli/utils/config/vectordb_config.py
index 6b77747a0..4aadac7d2 100644
--- a/openviking_cli/utils/config/vectordb_config.py
+++ b/openviking_cli/utils/config/vectordb_config.py
@@ -8,6 +8,7 @@ from openviking_cli.utils.logger import get_logger
COLLECTION_NAME = "context"
DEFAULT_PROJECT_NAME = "default"
+DEFAULT_INDEX_NAME = "default"
logger = get_logger(__name__)
@@ -70,6 +71,11 @@ class VectorDBBackendConfig(BaseModel):
default=DEFAULT_PROJECT_NAME, description="project name", alias="project"
)
+ index_name: Optional[str] = Field(
+ default=DEFAULT_INDEX_NAME,
+ description="Default index name for VectorDB operations",
+ )
+
distance_metric: str = Field(
default="cosine",
description="Distance metric for vector similarity search (e.g., 'cosine', 'l2', 'ip')",
diff --git a/tests/misc/test_config_validation.py b/tests/misc/test_config_validation.py
index 1ab715170..89ad5d3ba 100644
--- a/tests/misc/test_config_validation.py
+++ b/tests/misc/test_config_validation.py
@@ -93,6 +93,14 @@ def test_vectordb_validation():
print(f" Fail: {e}")
+def test_vectordb_index_name_defaults_and_overrides():
+ default_config = VectorDBBackendConfig()
+ assert default_config.index_name == "default"
+
+ custom_config = VectorDBBackendConfig(index_name="context_idx")
+ assert custom_config.index_name == "context_idx"
+
+
def test_embedding_validation():
"""Test Embedding config validation"""
print("\n" + "=" * 60)
diff --git a/tests/storage/mock_backend.py b/tests/storage/mock_backend.py
index 38737a1cc..07e28d50f 100644
--- a/tests/storage/mock_backend.py
+++ b/tests/storage/mock_backend.py
@@ -1,10 +1,9 @@
from typing import Any, Dict, List, Optional
-from openviking.storage.vectordb.collection.collection import ICollection
+
+from openviking.storage.vectordb.collection.collection import Collection, ICollection
from openviking.storage.vectordb.collection.result import AggregateResult, SearchResult
from openviking.storage.vectordb.index.index import IIndex
-
from openviking.storage.vectordb_adapters.base import CollectionAdapter
-from openviking.storage.vectordb.collection.collection import Collection
class MockCollectionAdapter(CollectionAdapter):
@@ -13,8 +12,14 @@ class MockCollectionAdapter(CollectionAdapter):
Inherits from CollectionAdapter and wraps MockCollection.
"""
- def __init__(self, collection_name: str, custom_param1: str = "", custom_param2: int = 0):
- super().__init__(collection_name=collection_name)
+ def __init__(
+ self,
+ collection_name: str,
+ index_name: str = "default",
+ custom_param1: str = "",
+ custom_param2: int = 0,
+ ):
+ super().__init__(collection_name=collection_name, index_name=index_name)
self.mode = "mock"
self.custom_param1 = custom_param1
self.custom_param2 = custom_param2
@@ -24,6 +29,7 @@ class MockCollectionAdapter(CollectionAdapter):
custom_params = getattr(config, "custom_params", {})
return cls(
collection_name=config.name or "mock_collection",
+ index_name=config.index_name or "default",
custom_param1=custom_params.get("custom_param1", ""),
custom_param2=custom_params.get("custom_param2", 0),
)
diff --git a/tests/storage/test_vectordb_adaptor.py b/tests/storage/test_vectordb_adaptor.py
index 5313f98d7..ad1b55314 100644
--- a/tests/storage/test_vectordb_adaptor.py
+++ b/tests/storage/test_vectordb_adaptor.py
@@ -1,20 +1,20 @@
# Copyright (c) 2026 Beijing Volcano Engine Technology Co., Ltd.
# SPDX-License-Identifier: Apache-2.0
-import unittest
-from unittest.mock import MagicMock, patch
-import sys
import os
+import sys
+import unittest
# Add paths to sys.path to ensure modules can be found
# sys.path.insert(0, "/cloudide/workspace/viking_python_client")
sys.path.insert(0, "/cloudide/workspace/open_test")
-from openviking.storage.vectordb_adapters.factory import create_collection_adapter
-from openviking_cli.utils.config import get_openviking_config, OpenVikingConfigSingleton
import json
import shutil
import tempfile
+from openviking.storage.vectordb_adapters.factory import create_collection_adapter
+from openviking_cli.utils.config import OpenVikingConfigSingleton, get_openviking_config
+
class TestAdapterLoading(unittest.TestCase):
def setUp(self):
@@ -27,6 +27,7 @@ class TestAdapterLoading(unittest.TestCase):
"vectordb": {
"backend": "tests.storage.mock_backend.MockCollectionAdapter",
"name": "mock_test_collection",
+ "index_name": "mock_test_index",
"custom_params": {"custom_param1": "val1", "custom_param2": 123},
}
},
@@ -69,6 +70,7 @@ class TestAdapterLoading(unittest.TestCase):
self.assertEqual(adapter.__class__.__name__, "MockCollectionAdapter")
self.assertEqual(adapter.mode, "mock")
self.assertEqual(adapter.collection_name, "mock_test_collection")
+ self.assertEqual(adapter.index_name, "mock_test_index")
self.assertEqual(adapter.custom_param1, "val1")
self.assertEqual(adapter.custom_param2, 123)