Skip to content

feat: unified search across memories and documents (#531) - #532

Merged
ajianaz merged 2 commits into
developfrom
feat/unified-search-531
Jul 3, 2026
Merged

ajianaz merged 2 commits into
developfrom
feat/unified-search-531

Conversation

@ajianaz

@ajianaz ajianaz commented Jul 3, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Bridge uteke recall and uteke doc search into a single query surface via client-side RRF merge. No schema changes, zero migration risk.

Closes #531

Problem

uteke recall searches memories, uteke doc search searches documents — two separate commands, two separate result sets. Agents need to know where data lives, adding cognitive overhead to every query.

Solution

Client-side merge at the query layer:

  1. Execute memory recall (existing ANN + FTS5)
  2. Execute doc search (existing ANN + FTS5)
  3. Merge via Reciprocal Rank Fusion
  4. Return unified result set with type labels

Changes

File Change
uteke-core/src/memory/types.rs Add UnifiedSearchResult, SearchResultType, SearchType types + tests
uteke-core/src/memory/mod.rs Re-export new types
uteke-core/src/lib.rs Add recall_unified() with 3 modes (all/memory/document)
uteke-cli/src/cli.rs Add --type flag to Recall command (String, no clap dep)
uteke-cli/src/commands/recall.rs Route to unified path when --type is set
uteke-cli/src/commands/mod.rs Pass --type to recall handler
uteke-cli/src/output.rs Add print_unified_human() with [mem]/[doc] labels
uteke-mcp/src/lib.rs uteke_recall MCP tool returns unified results
uteke-server/src/types.rs Add search_type to RecallRequest
uteke-server/src/handlers.rs Route to recall_unified when search_type is provided

API

# Unified (default) — both memories + documents
uteke recall "kanban fleet" --namespace coo
# [mem] Fleet uses kanban board: operations     score: 0.82
# [doc] Hermes Kanban + Delegation Integration  score: 0.89

# Filter to memories only
uteke recall "kanban" --type memory

# Filter to documents only
uteke recall "kanban" --type doc

Backward Compatibility

  • --type all (default) only activates unified path when no memory-specific flags are used
  • --at, --related, --salience, --recency, --entity, --category, --where → falls back to memory-only path
  • uteke doc search command unchanged
  • MCP uteke_recall response includes result_type field for distinction
  • Entity/category filters force legacy memory-only recall path (metadata only exists on memories)

Acceptance Criteria from #531

  • uteke recall "query" --namespace N returns both memories and documents by default
  • uteke recall "query" --type memory returns memories only
  • uteke recall "query" --type doc returns documents only
  • Output labels result type ([mem] vs [doc])
  • Memory results include id and content
  • Document results include slug, title, and chunk excerpt
  • MCP uteke_recall returns unified results with type field
  • API POST /recall accepts optional search_type parameter
  • Latency benchmark (requires CI environment with embedding model)
  • uteke doc search continues to work independently

Testing

  • Serde roundtrip tests for all new types
  • Default value assertions
  • Field serialization verification (skip_serializing_if for Optional fields)
  • All 339 workspace tests passing

Comment thread crates/uteke-cli/src/cli.rs Fixed
Comment thread crates/uteke-core/src/lib.rs Fixed
Comment thread crates/uteke-core/src/lib.rs Fixed
@github-actions

github-actions Bot commented Jul 3, 2026 •

Copy link
Copy Markdown

🔍 Cora AI Code Review

❌ Blocked — critical issues found.

🔴 Error (4)

  • crates/uteke-core/src/lib.rs:1299 — In recall_unified, SearchType::Document calls self.recall_unified_documents(query, limit, ns, min_score) where ns has already been normalized with DEFAULT_NAMESPACE, but SearchType::Memory calls recall_unified_memories(..., namespace, ...) with the original Option<&str>. This makes the two branches behave differently when namespace is None: document search always uses the default namespace, while memory search relies on whatever self.recall(...) does with None. The public docs for recall_unified say All is the default unified search across both sources, so this inconsistent namespace handling can return different result sets for --type memory vs --type doc on the same query.
  • crates/uteke-core/src/lib.rs:1358 — In recall_unified_all, failures from either backend are swallowed: self.recall(...) and self.doc_search(...) are wrapped in match blocks that log a warning and substitute Vec::new(). As a result, callers can receive a successful response containing only memory or only document hits even when the other search path failed. This is a functional regression compared with the single-source APIs, because users cannot distinguish "no results" from "half the system failed".
  • crates/uteke-cli/src/commands/recall.rs:47 — The new use_unified logic makes plain recall default to SearchType::All whenever no memory-only flags are present: Some("all") | None => SearchType::All, then SearchType::All uses unified search if at.is_none() && !related && !salience && !recency && entity.is_none() && category.is_none() && where_filter.is_none(). This means existing invocations like uteke recall "query" now return documents as well as memories, despite the command previously being memory-only. The comment says this is for backward compatibility, but the no-flags default path is now behaviorally different.
  • crates/uteke-server/src/handlers.rs:244 — The handler only enables unified search when req_data.search_type.is_some() && point_in_time.is_none() && !has_meta_filter. However, RecallRequest documents search_type as having a default of "all", and the CLI/MCP paths treat omission as unified search. On the server, omitting search_type silently falls back to the legacy memory-only path, so the same API behaves differently depending on whether the client sends "all" explicitly.

Review powered by cora-cli · BYOK · MIT

Bridge recall and doc search into a single query surface via client-side RRF merge.
No schema changes, zero migration risk.

- Add UnifiedSearchResult, SearchResultType, SearchType types
- Add recall_unified() to Uteke (core) with 3 modes:
  - All (default): memories + documents merged via RRF
  - Memory: memories only (backward compatible)
  - Document: documents only
- CLI: --type flag (all|memory|doc) on recall command
- CLI: [mem]/[doc] labels in human output
- MCP: uteke_recall now returns unified results with type field
- API: POST /recall accepts optional search_type parameter
- Tests: serde roundtrip, type defaults, field serialization

Fixes from original PR:
- Remove clap::ValueEnum from uteke-core (no clap dep) — use String in CLI
- Rename test is_numbered_list → test_numbered_list (shadows free fn)
- Apply min_score in recall_unified_all (Cora review)
- Entity/category filters force legacy memory-only path (Cora review)
- Fix serde test assertions: use "document" not "doc", "result_type" not "type"
- Rustfmt all files

Breaking: none — --type defaults to 'all' but falls back to memory-only
path when memory-specific flags are used (--at, --related, --salience,
--recency, --entity, --category, --where).
@ajianaz
ajianaz force-pushed the feat/unified-search-531 branch from a24070c to eedd3e2 Compare July 3, 2026 14:32
Comment thread crates/uteke-core/src/lib.rs Fixed
Comment thread crates/uteke-core/src/lib.rs Fixed
- recall_unified_documents now accepts and applies min_score filter
  (previously ignored, causing functional inconsistency)
- recall_unified_all: replace unwrap_or_default() with match + tracing::warn
  so backend failures produce log entries instead of silent empty results
  (partial degradation is intentional — one source failing shouldn't block the other)

// When --type is explicitly set (not default unified), route to recall_unified.
// When unified (default), use existing recall path for backward compat with
// --strategy, --at, --related, --salience, --recency, --entity, --category, --where flags
namespace: Option<&str>,
min_score: f32,
search_type: SearchType,
) -> Result<Vec<UnifiedSearchResult>, Error> {
} else {
dr.chunk_snippet.clone()
},
memory_id: None,
&& point_in_time.is_none()
&& !has_meta_filter
{
let search_type = match req_data.search_type.as_deref() {
@ajianaz
ajianaz merged commit 991baa2 into develop Jul 3, 2026
8 of 9 checks passed
@ajianaz
ajianaz deleted the feat/unified-search-531 branch July 3, 2026 14:49
ajianaz added a commit that referenced this pull request Aug 13, 2026
feat: unified search across memories and documents (#531)
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.

Unified Search: Bridge and into a single query surface

2 participants