Skip to content

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

fix(observer): pass RequestContext through vikingdb observer for tenant-scoped vector count (#807)

Qin Haojie7be9514ed7f5
diff --git a/docs/en/api/07-system.md b/docs/en/api/07-system.md
index 79ad55588..adad373ec 100644
--- a/docs/en/api/07-system.md
+++ b/docs/en/api/07-system.md
@@ -49,7 +49,7 @@ Get system status including initialization state and user info.
**Python SDK (Embedded / HTTP)**
```python
-print(client.observer.system)
+print(client.observer.system())
```
**HTTP API**
@@ -204,16 +204,16 @@ Get VikingDB status (collections, indexes, vector counts).
**Python SDK (Embedded / HTTP)**
```python
-print(client.observer.vikingdb)
+print(client.observer.vikingdb())
# Output:
# [vikingdb] (healthy)
# Collection Index Count Vector Count Status
# context 1 55 OK
# TOTAL 1 55
-# Access specific properties
-print(client.observer.vikingdb.is_healthy) # True
-print(client.observer.vikingdb.status) # Status table string
+# Access specific attributes
+print(client.observer.vikingdb().is_healthy) # True
+print(client.observer.vikingdb().status) # Status table string
```
**HTTP API**
@@ -306,7 +306,7 @@ Get overall system status including all components.
**Python SDK (Embedded / HTTP)**
```python
-print(client.observer.system)
+print(client.observer.system())
# Output:
# [queue] (healthy)
# ...
@@ -382,7 +382,7 @@ Quick health check for the entire system.
if client.observer.is_healthy():
print("System OK")
else:
- print(client.observer.system)
+ print(client.observer.system())
```
**HTTP API**
diff --git a/docs/zh/api/07-system.md b/docs/zh/api/07-system.md
index 8f7442722..d146f66b0 100644
--- a/docs/zh/api/07-system.md
+++ b/docs/zh/api/07-system.md
@@ -49,7 +49,7 @@ openviking health
**Python SDK (Embedded / HTTP)**
```python
-print(client.observer.system)
+print(client.observer.system())
```
**HTTP API**
@@ -204,7 +204,7 @@ openviking observer queue
**Python SDK (Embedded / HTTP)**
```python
-print(client.observer.vikingdb)
+print(client.observer.vikingdb())
# Output:
# [vikingdb] (healthy)
# Collection Index Count Vector Count Status
@@ -212,8 +212,8 @@ print(client.observer.vikingdb)
# TOTAL 1 55
# 访问特定属性
-print(client.observer.vikingdb.is_healthy) # True
-print(client.observer.vikingdb.status) # Status table string
+print(client.observer.vikingdb().is_healthy) # True
+print(client.observer.vikingdb().status) # Status table string
```
**HTTP API**
@@ -306,7 +306,7 @@ openviking observer vlm
**Python SDK (Embedded / HTTP)**
```python
-print(client.observer.system)
+print(client.observer.system())
# Output:
# [queue] (healthy)
# ...
@@ -382,7 +382,7 @@ openviking observer system
if client.observer.is_healthy():
print("System OK")
else:
- print(client.observer.system)
+ print(client.observer.system())
```
**HTTP API**
diff --git a/openviking/client/local.py b/openviking/client/local.py
index 0c9183198..1760f85d7 100644
--- a/openviking/client/local.py
+++ b/openviking/client/local.py
@@ -449,7 +449,7 @@ class LocalClient(BaseClient):
Returns:
SystemStatus containing health status of all components.
"""
- return self._service.debug.observer.system
+ return self._service.debug.observer.system()
def is_healthy(self) -> bool:
"""Quick health check (synchronous).
diff --git a/openviking/server/routers/observer.py b/openviking/server/routers/observer.py
index e1910596a..8f29f5478 100644
--- a/openviking/server/routers/observer.py
+++ b/openviking/server/routers/observer.py
@@ -54,11 +54,11 @@ async def observer_queue(
@router.get("/vikingdb")
async def observer_vikingdb(
- _ctx: RequestContext = Depends(get_request_context),
+ ctx: RequestContext = Depends(get_request_context),
):
"""Get VikingDB status."""
service = get_service()
- component = service.debug.observer.vikingdb
+ component = service.debug.observer.vikingdb(ctx=ctx)
return Response(status="ok", result=_component_to_dict(component))
@@ -94,9 +94,9 @@ async def observer_retrieval(
@router.get("/system")
async def observer_system(
- _ctx: RequestContext = Depends(get_request_context),
+ ctx: RequestContext = Depends(get_request_context),
):
"""Get system overall status (includes all components)."""
service = get_service()
- status = service.debug.observer.system
+ status = service.debug.observer.system(ctx=ctx)
return Response(status="ok", result=_system_to_dict(status))
diff --git a/openviking/service/debug_service.py b/openviking/service/debug_service.py
index b99b4e73c..2718a67dd 100644
--- a/openviking/service/debug_service.py
+++ b/openviking/service/debug_service.py
@@ -7,6 +7,7 @@ Debug Service - provides system status query and health check.
from dataclasses import dataclass
from typing import Dict, List, Optional
+from openviking.server.identity import RequestContext
from openviking.storage import VikingDBManager
from openviking.storage.observers import (
LockObserver,
@@ -99,8 +100,7 @@ class ObserverService:
status=observer.get_status_table(),
)
- @property
- def vikingdb(self) -> ComponentStatus:
+ def vikingdb(self, ctx: Optional[RequestContext] = None) -> ComponentStatus:
"""Get VikingDB status."""
if self._vikingdb is None:
return ComponentStatus(
@@ -114,7 +114,7 @@ class ObserverService:
name="vikingdb",
is_healthy=observer.is_healthy(),
has_errors=observer.has_errors(),
- status=observer.get_status_table(),
+ status=observer.get_status_table(ctx=ctx),
)
@property
@@ -166,12 +166,11 @@ class ObserverService:
status=observer.get_status_table(),
)
- @property
- def system(self) -> SystemStatus:
+ def system(self, ctx: Optional[RequestContext] = None) -> SystemStatus:
"""Get system overall status."""
components = {
"queue": self.queue,
- "vikingdb": self.vikingdb,
+ "vikingdb": self.vikingdb(ctx=ctx),
"vlm": self.vlm,
"lock": self.lock,
"retrieval": self.retrieval,
@@ -187,7 +186,7 @@ class ObserverService:
"""Quick health check."""
if not self._dependencies_ready:
return False
- return self.system.is_healthy
+ return self.system().is_healthy
class DebugService:
diff --git a/openviking/storage/observers/README.md b/openviking/storage/observers/README.md
index 071bbacff..97fa240ab 100644
--- a/openviking/storage/observers/README.md
+++ b/openviking/storage/observers/README.md
@@ -58,7 +58,7 @@ Monitors VikingDB collection status (index count and vector count per collection
import openviking as ov
client = ov.OpenViking(path="./data")
-print(client.observer.vikingdb)
+print(client.observer.vikingdb())
# Output:
# Collection Index Count Vector Count Status
# context 1 69 OK
diff --git a/openviking/storage/observers/vikingdb_observer.py b/openviking/storage/observers/vikingdb_observer.py
index 9e6eeab7a..aac577c42 100644
--- a/openviking/storage/observers/vikingdb_observer.py
+++ b/openviking/storage/observers/vikingdb_observer.py
@@ -6,8 +6,9 @@ VikingDBObserver: VikingDB storage observability tool.
Provides methods to observe and report VikingDB collection status.
"""
-from typing import Dict
+from typing import Dict, Optional
+from openviking.server.identity import RequestContext
from openviking.storage.observers.base_observer import BaseObserver
from openviking.storage.vikingdb_manager import VikingDBManager
from openviking_cli.utils import run_async
@@ -26,23 +27,27 @@ class VikingDBObserver(BaseObserver):
def __init__(self, vikingdb_manager: VikingDBManager):
self._vikingdb_manager = vikingdb_manager
- async def get_status_table_async(self) -> str:
+ async def get_status_table_async(self, ctx: Optional[RequestContext] = None) -> str:
if not self._vikingdb_manager:
return "VikingDB manager not initialized."
if not await self._vikingdb_manager.collection_exists():
return "No collections found."
- statuses = await self._get_collection_statuses([self._vikingdb_manager.collection_name])
+ statuses = await self._get_collection_statuses(
+ [self._vikingdb_manager.collection_name], ctx=ctx
+ )
return self._format_status_as_table(statuses)
- def get_status_table(self) -> str:
- return run_async(self.get_status_table_async())
+ def get_status_table(self, ctx: Optional[RequestContext] = None) -> str:
+ return run_async(self.get_status_table_async(ctx=ctx))
def __str__(self) -> str:
return self.get_status_table()
- async def _get_collection_statuses(self, collection_names: list) -> Dict[str, Dict]:
+ async def _get_collection_statuses(
+ self, collection_names: list, *, ctx: Optional[RequestContext] = None
+ ) -> Dict[str, Dict]:
statuses = {}
for name in collection_names:
@@ -52,7 +57,7 @@ class VikingDBObserver(BaseObserver):
# Current OpenViking flow uses one managed default index per collection.
index_count = 1
- vector_count = await self._vikingdb_manager.count()
+ vector_count = await self._vikingdb_manager.count(ctx=ctx)
statuses[name] = {
"index_count": index_count,
diff --git a/tests/misc/test_debug_service.py b/tests/misc/test_debug_service.py
index 36245e107..120d2e76b 100644
--- a/tests/misc/test_debug_service.py
+++ b/tests/misc/test_debug_service.py
@@ -166,7 +166,7 @@ class TestObserverService:
mock_observer_cls.return_value = mock_observer
service = ObserverService(vikingdb=mock_vikingdb)
- status = service.vikingdb
+ status = service.vikingdb()
assert isinstance(status, ComponentStatus)
assert status.name == "vikingdb"
@@ -216,7 +216,7 @@ class TestObserverService:
mock_config = MagicMock()
service = ObserverService(vikingdb=MagicMock(), config=mock_config)
- status = service.system
+ status = service.system()
assert isinstance(status, SystemStatus)
for name in ("queue", "vikingdb", "vlm"):
@@ -255,7 +255,7 @@ class TestObserverService:
mock_config = MagicMock()
service = ObserverService(vikingdb=MagicMock(), config=mock_config)
- status = service.system
+ status = service.system()
assert isinstance(status, SystemStatus)
assert status.is_healthy is False
@@ -281,7 +281,7 @@ class TestObserverService:
mock_config = MagicMock()
service = ObserverService(vikingdb=MagicMock(), config=mock_config)
- status = service.system
+ status = service.system()
assert all(c.is_healthy for name, c in status.components.items() if name != "transaction")
def test_is_healthy_without_dependencies(self):
@@ -292,7 +292,7 @@ class TestObserverService:
def test_vikingdb_property_without_dependency(self):
"""Test vikingdb property returns unhealthy ComponentStatus when vikingdb is None."""
service = ObserverService()
- status = service.vikingdb
+ status = service.vikingdb()
assert isinstance(status, ComponentStatus)
assert status.name == "vikingdb"
assert status.is_healthy is False
@@ -312,7 +312,7 @@ class TestObserverService:
def test_system_property_without_dependencies(self):
"""Test system property returns unhealthy SystemStatus when dependencies not set."""
service = ObserverService()
- status = service.system
+ status = service.system()
assert isinstance(status, SystemStatus)
assert status.is_healthy is False
diff --git a/tests/misc/test_vikingdb_observer.py b/tests/misc/test_vikingdb_observer.py
index 3dc3cfaf6..4792892d4 100644
--- a/tests/misc/test_vikingdb_observer.py
+++ b/tests/misc/test_vikingdb_observer.py
@@ -42,7 +42,7 @@ async def test_vikingdb_observer():
# Test VikingDBObserver
print("\n4. Test VikingDBObserver:")
- vikingdb_status = client.observer.vikingdb
+ vikingdb_status = client.observer.vikingdb()
print(f"Type: {type(vikingdb_status)}")
print(f"Is healthy: {vikingdb_status.is_healthy}")
print(f"Has errors: {vikingdb_status.has_errors}")
@@ -58,7 +58,7 @@ async def test_vikingdb_observer():
# Test system status
print("\n7. Test system status:")
- system_status = client.observer.system
+ system_status = client.observer.system()
print(f"System is_healthy: {system_status.is_healthy}")
for name, component in system_status.components.items():
print(f"\n{name}:")
@@ -102,7 +102,7 @@ async def test_sync_client():
# Test VikingDBObserver
print("\nVikingDBObserver status:")
- print(client.observer.vikingdb)
+ print(client.observer.vikingdb())
print("\n=== Sync client test completed ===")