OpenViking icon indicating copy to clipboard operation
OpenViking copied to clipboard

Search API returns empty results when target_uri is viking:// (scope filter uses exact match instead of prefix match)

Open zhumin-zizhu opened this issue 9 months ago • 7 comments

Bug Description

Search API (/api/v1/search/search and /api/v1/search/find) returns empty results when target_uri is "viking://" or any URI without explicit space segment (e.g. "viking://user/memories/"). This affects all requests running as ROOT role, including dev mode (no root_api_key configured).

Root Cause (updated)

After deeper investigation, the primary root cause is in openviking/retrieve/hierarchical_retriever.py, _get_root_uris_for_type() (line 437):

if not ctx or ctx.role == Role.ROOT:
    return []

When the role is ROOT (which includes all dev mode requests), this method returns an empty list. The recursive search then has no valid starting points and returns 0 results.

A secondary issue exists in openviking/storage/viking_vector_index_backend.py, _build_scope_filter() (line 479-482): In("uri", [target_dir]) performs exact match on target_directories, so "viking://" never matches any stored URI. URIs without explicit space segments (e.g. "viking://user/memories/") also fail because stored URIs include the space (e.g. "viking://user/default/memories/...").

Who is affected

  • All dev mode users (no root_api_key configured, localhost binding) — this is the default setup recommended by examples/openclaw-memory-plugin
  • All ROOT role API requests (even with root_api_key, using the root key directly)
  • Non-ROOT roles (ADMIN/USER) are not affected because _get_root_uris_for_type returns correct space-qualified URIs for them

Impact

  • The official OpenClaw memory plugin (examples/openclaw-memory-plugin) defaults to targetUri: "viking://" and runs in dev mode, making auto-recall completely non-functional out of the box
  • Memory writes succeed, but recall silently returns 0 results — no errors in logs
  • The ov find CLI command also returns empty results in dev mode

Environment

  • OpenViking version: v0.2.1 (also confirmed on main branch)
  • Mode: Dev mode (no root_api_key, localhost binding)
  • Role: ROOT (default for dev mode)

Steps to Reproduce

  1. Deploy OpenViking v0.2.1 in dev mode (no root_api_key)
  2. Store memories via session API (create session → add messages → extract)
  3. Search with target_uri: "viking://" → returns empty
  4. Search with target_uri: "viking://user/default/memories/" → returns results

Suggested Fix

  1. In hierarchical_retriever.py: Remove the ROOT early-return in _get_root_uris_for_type() so ROOT users also get space-qualified root URIs as starting points for recursive search.

  2. In viking_vector_index_backend.py: When target_uri is root "viking://", skip the URI filter. For URIs missing space segments, expand them using the current user context (e.g. "viking://user/memories/" → "viking://user/{user_space}/memories/").

Workaround

Add filter: {"account_id": "default"} to search request body. This bypasses the scope filter and returns correct results.

zhumin-zizhu avatar Feb 28 '26 18:02 zhumin-zizhu

和Openclaw的集成也遇到了类似的情况,推断是和viking://的路径有关联,调整后,Openclaw的memory_recall似乎没有报错检索不到了,不过我还在验证中

ZZFFLL avatar Mar 01 '26 07:03 ZZFFLL

和Openclaw的集成也遇到了类似的情况,推断是和viking://的路径有关联,调整后,Openclaw的memory_recall似乎没有报错检索不到了,不过我还在验证中

你的可以了吗?

zhumin-zizhu avatar Mar 01 '26 14:03 zhumin-zizhu

请使用 0.2.1 版测试下

MaojiaSheng avatar Mar 02 '26 00:03 MaojiaSheng

和Openclaw的集成也遇到了类似的情况,推断是和viking://的路径有关联,调整后,Openclaw的memory_recall似乎没有报错检索不到了,不过我还在验证中

你的可以了吗?

Image

我把Openclaw的运行日志和OpenViking集成进openclaw的文档发给了模型,模型答复是viking://指向了根路径,实际上应该是 "targetUri": "viking://user/default/memories"

ZZFFLL avatar Mar 02 '26 01:03 ZZFFLL

https://github.com/volcengine/OpenViking/pull/373 对接openclaw的修复pr已合入,请使用社区最新代码进行验证

wlff123 avatar Mar 02 '26 03:03 wlff123

https://github.com/volcengine/OpenViking/pull/374

MaojiaSheng avatar Mar 02 '26 03:03 MaojiaSheng

https://github.com/volcengine/OpenViking/pull/382

zhoujh01 avatar Mar 02 '26 12:03 zhoujh01