Skip to content

fix(search): explain empty results in metadata - #647

Merged
jinliyl merged 5 commits into
agentscope-ai:mainfrom
flyl1u:fix/search-empty-answer
Oct 23, 2026
Merged

jinliyl merged 5 commits into
agentscope-ai:mainfrom
flyl1u:fix/search-empty-answer

Conversation

@flyl1u

@flyl1u flyl1u commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Preserve answer="" and success=true for successful empty default searches, and explain the outcome in optional metadata.empty_result: no_results when retrieval or score filtering leaves no eligible chunks, and all_returned when all eligible chunks were already returned in the same tool context. The accompanying message reuses the existing notices. Normal hits omit this field and keep their existing rendering.

The reason is determined after score filtering and before deduplication, so earlier search history cannot turn a new no-match query into all_returned. Clear the field before each invocation to avoid carrying an empty-result explanation into a later hit or error.

The net diff is limited to SearchStep, focused regressions, and the English/Chinese Memory Search guides. Existing agent consumers and the answer-only MCP transport retain their behavior. CLI users can display the explanation with the existing show_metadata=true option.

Related issue

Related to #379 (the default search path).

Contract and data impact

  • No public configuration, schema, CLI, endpoint, streaming, or workspace-layout contract changes
  • No user-owned memory files are deleted or rewritten
  • Derived indexes, catalogs, graphs, caches, and metadata remain rebuildable

The only contract addition is optional metadata.empty_result = {reason, message}. Existing results, counts, link_expansion, and optional deduplication metadata keep their shapes. No configuration change or migration is required. Separate BM25/vector search answers remain unchanged.

Validation

  • Focused tests pass

  • Unit tests pass, or omitted tests are explained below

  • pre-commit run --all-files passes, or omitted checks are explained below

  • Frontend checks were run when reme_studio/ changed

  • Windows: search, score-threshold, link-expansion, HTTP-client and CLI tests — 120 passed, including 20 focused empty-result cases.

  • Linux, Python 3.12.3: python -m coverage run -m pytest tests/unit plugins/auto-fin plugins/daily_paper plugins/lme plugins/beam -q --tb=short — 2358 passed, 3 skipped, 0 failed; coverage reporting passes. The skips are optional pillow_heif and aiodocker cases, with no manual test exclusions.

  • Linux, Node 24.16.0, from github-pages: npm test — 19 passed; npm run build — passed, verifying 40 documentation build artifacts.

  • pre-commit run --all-files and git diff --check — passed.

  • Actual SearchStep responses for no-match, score-filtered, all-returned, and normal-hit scenarios pass through the unchanged Codex explicit search (English/Chinese), Codex/Claude auto-recall, Hermes recall/status, and OpenClaw context formatter with retrieval and transport boundaries mocked. Empty results are not injected as memory; normal hits remain usable.

No live model-provider or external-agent tests were run. The PR has no Studio frontend changes.

Checklist

  • I reviewed the diff for unrelated changes and sensitive data
  • Tests cover intentional behavior changes
  • Defaults, schemas, and concise documentation were updated together when required
  • Long-lived clients, tasks, services, and executors follow the application lifecycle

No default configuration, typed schema, or resource-lifecycle changes are needed.

@CLAassistant

CLAassistant commented Oct 20, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@jinliyl

jinliyl commented Oct 21, 2026

Copy link
Copy Markdown
Member

Thank you for the focused fix and the detailed validation notes! Distinguishing “no eligible results” from “content already returned” is useful, and the change in SearchStep is small and clear.

I reviewed commit f9e7f7c79b55633636285fef406538d4caffc35c and found one downstream compatibility issue to address before merging, plus an optional test simplification.

[P2] Update Codex consumers when empty search answers become non-empty notices

The new fallback in search.py makes an empty successful search return a non-empty string. However, the existing Codex integration still uses the truthiness of answer to decide whether memory was found:

  • Explicit search logs search_found and bypasses its localized empty-result message.
  • Automatic recall logs recall_found and wraps the no-results notice in a <reme-context source="auto-recall"> historical-evidence block.

I reproduced this by passing the actual empty SearchStep response through the Codex explicit-search handler and recall hook, with retrieval and transport boundaries mocked. Comparing the parent commit with this PR:

Empty search behavior (counts.returned == 0) Parent commit This PR
Explicit-search event search_empty search_found
Automatic-recall event recall_empty recall_found
Historical-memory block injected No Yes
Explicit-search reply with language=zh 没有找到相关记忆。 English NO_RESULTS_MESSAGE

Could you please update these consumers to distinguish a no-results notice from retrieved memory, preserve their empty-result handling, and add regression coverage using the new response? The same classification should handle the all-returned notice where applicable.

One detail to keep in mind: the current MCP job wrapper returns only response.answer, so simply reading metadata.counts.returned in these MCP consumers would not work with the existing transport.

Optional simplification

The runtime change already adds only four lines and reuses the existing notice constants; I would keep it this small rather than introduce another shared helper.

In the new regression file, test_search_no_matches_has_explicit_answer and test_search_score_filter_has_no_results_answer share most of their setup and empty-response assertions. They could be consolidated into one parameterized test with explicit retrieval/threshold cases and expected counts. This is optional, not a merge blocker. Please retain the distinct tests for state shared across fresh Step instances, context isolation, partial deduplication, and distinguishing prior history from a new query with no eligible candidates.

Local validation

  • 149 related tests passed: search/score/link expansion (95), Codex MCP and Hermes integration unit tests (51), and Claude Code auto-memory tests (3). External boundaries were mocked.
  • Pre-commit checks passed for the four changed files, including Black, Flake8, Pylint, and Pyroma; git diff --check also passed.
  • Documentation tests: 15 passed. The standard documentation build passed and verified 40 artifacts.
  • I did not run the full unit suite or live service/model-provider integration tests. GitHub currently reports no check results for this PR.

Thanks again for the contribution! Apart from the downstream empty-result handling above, I did not find a defect in the core search change.

@jinliyl

jinliyl commented Oct 22, 2026

Copy link
Copy Markdown
Member

Thank you for the updates and for addressing the earlier integration feedback! I reviewed e09de918; the Codex notice handling, the structured-result checks in the other integrations, and the parameterized search tests address the points we discussed.

After checking another downstream consumer, QwenPaw, I would like to recommend preserving the existing empty-answer behavior and adding the explanation to metadata instead. This revises my earlier suggestion to adapt individual consumers: preserving the response behavior would avoid requiring each existing agent integration to recognize new notice strings.

There is a reproducible P2 compatibility issue outside the integrations changed here. In the local QwenPaw checkout at 73fe3f76, ReMeLightMemoryManager.memory_search() converts only an empty answer to its existing empty-result marker, and BaseMemoryManager._is_empty_memory_search_result() recognizes only the existing markers. I passed actual SearchStep responses through these methods, with retrieval and job transport mocked. With the currently installed ReMe, no-match and score-filtered searches skip automatic recall. With this PR, both return zero results but inject the new notice as recalled memory. Normal hits remain unchanged. QwenPaw is still pinned to an earlier ReMe commit, so this would surface when upgrading.

Given ReMe's emphasis on CLI and embedded usage, could we use this additive contract for the default search job?

  • Keep answer="" and success=true for successful searches with no returned results.
  • Preserve the existing results, counts, link_expansion, and optional deduplication metadata.
  • Add an optional metadata field for empty results, for example:
{
  "empty_result": {
    "reason": "no_results",
    "message": "No relevant information was found for the given query."
  }
}

The other reason would be all_returned when all eligible chunks were already returned in the same tool context. Normal hits would keep their current answer and omit this field. Consumers can use the stable reason rather than match English prose.

Both the HTTP-backed CLI and the one-shot CLI already support optional metadata display. For normal service usage, reme search query="..." show_metadata=true can expose the explanation while default output stays compatible. The current MCP answer-only behavior can remain unchanged in this PR; it does not need to determine the default search contract.

This should also simplify the PR: the integration changes introduced to accommodate non-empty notices would no longer be needed, leaving the default SearchStep, focused regression tests, and the English/Chinese search docs. The existing answer behavior of the separate BM25/vector search steps should remain unchanged.

For validation, please retain the distinct no-match, score-filtered, all-returned, normal-hit, and shared-context cases, but assert the unchanged answer plus the new metadata. Locally, the 91 related QwenPaw tests and 19 ReMe CLI/client tests pass; the existing QwenPaw tests do not cover these new notices. I also checked both CLI formatters with the proposed metadata shape. No live model-provider tests were run.

Thanks again for the careful fixes and regression coverage. Keeping this additive would make the change easier for existing consumers to adopt.

@flyl1u flyl1u changed the title fix(search): explain empty search results fix(search): explain empty results in metadata Oct 23, 2026
@flyl1u

flyl1u commented Oct 23, 2026

Copy link
Copy Markdown
Contributor Author

Updated in c2e0c965 following the revised metadata approach.

  • Successful empty default searches keep answer="" and success=true. metadata.empty_result distinguishes no_results from all_returned, with the existing notice text in message; normal hits omit the field.
  • The integration-specific notice handling and its tests have been removed. The net diff now contains only SearchStep, focused regressions, and the English/Chinese Memory Search guides. Separate BM25/vector search answers and the MCP answer-only transport are unchanged.
  • Merged the current main with a normal merge and resolved the import conflict while retaining the new shared tool-context implementation.

Validation: 120 focused/related tests passed; the full Linux Python 3.12 suite and plugin tests passed with 2358 passed and 3 optional-dependency skips. Pre-commit and diff checks passed. Documentation tests passed (19), and the standard Linux documentation build verified 40 artifacts. Actual search responses also pass the unchanged Codex explicit search (English/Chinese), Codex/Claude auto-recall, Hermes recall/status, and OpenClaw formatter checks with retrieval and transport mocked.

The new head's GitHub Actions currently require maintainer approval to run. No live model-provider or external-agent tests were run.

@jinliyl jinliyl left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@jinliyl
jinliyl merged commit c773fa7 into agentscope-ai:main Oct 23, 2026
16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants