Skip to content

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

@Zhumin-lv-wn

Description

@Zhumin-lv-wn

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Status

    Backlog

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions