Skip to content

Unified Search: Bridge and into a single query surface #531

Closed

Description

@ajianaz

Problem

uteke recall and uteke doc search are two separate search surfaces backed by two separate SQLite tables (memories and document_chunks), each with their own usearch vector index. There is no bridge between them:

Command Searches Table Use Case
uteke recall Short-form memories memories + memories_fts Facts, decisions, preferences, procedure snippets
uteke doc search Long-form documents document_chunks + documents_fts Deep research, specs, blueprints, multi-section analyses

When an agent or user searches for a topic like "kanban multi-agent fleet", they currently need to run two separate commands and manually merge results. The two stores cannot find each other:

uteke recall "kanban fleet" --namespace coo        # → memories only
uteke doc search "kanban fleet" --namespace coo   # → documents only

This means:

  1. Agents need to know where data lives — but they shouldn't have to. A search should return everything relevant, regardless of storage backend.
  2. Documents and memories naturally complement each other — a query about "kanban" should return both the deep-dive research doc AND the quick fact "fleet uses kanban board: operations".
  3. Cognitive overhead on every query — two commands, two result sets, manual merge. This adds latency to agent reasoning loops that use Uteke as a knowledge backend.
  4. MCP tool fragmentation — the uteke_recall MCP tool only hits memories. Document search has no MCP exposure yet. A unified surface would naturally extend to MCP with one tool instead of two.

Proposed Solution

Unify search into a single surface via merged query with type-aware ranking:

Default Behavior (Unified)

# Single query returns results from BOTH memories and documents, merged and re-ranked
uteke recall "kanban multi-agent fleet" --namespace coo

# Expected output:
# Results from memories + documents, merged and re-ranked by relevance
#
# [doc] Hermes Kanban + Delegation Integration        score: 0.89  type: document  source: hermes-kanban-delegation-integration
#       ↳ 4. Integration: Kanban + Delegation Combo
# [mem] Fleet uses kanban board: operations              score: 0.82  type: memory    id: abc-123
# [mem] CTO assigned as kanban worker for engineering     score: 0.78  type: memory    id: def-456

Filter Flags (Optional, Backward Compatible)

# Only memories (legacy behavior, backward compatible)
uteke recall "kanban" --type memory --namespace coo

# Only documents
uteke recall "kanban" --type doc --namespace coo

# Both (default, new unified behavior)
uteke recall "kanban" --namespace coo

Implementation Approach

The simplest viable path — no schema changes, no index changes — is a client-side merge at the query layer:

┌──────────────────────────────────────┐
│  uteke recall "query" (unified)      │
│                                     │
│  1. Execute memory recall (existing) │──→ memories usearch + FTS5 ──→ scored results A
│  2. Execute doc search (existing)    │──→ doc_chunks usearch + FTS5 ──→ scored results B
│  3. Merge A + B                     │
│  4. Re-rank via RRF                 │
│  5. Apply type-aware boost (opt)    │
│  6. Return unified result set       │
└──────────────────────────────────────┘

Why this works:

  • Both backends already use the same embedding model (EmbeddingGemma) with the same dimensions (768d) — scores are directly comparable.
  • Both already use RRF (Reciprocal Rank Fusion) for hybrid vector+FTS — we just add a third RRF round to merge the two result sets.
  • No migration needed — the existing memories and document_chunks tables stay untouched.
  • The --type flag maps directly to existing code paths: --type memory = current recall behavior, --type doc = current doc search behavior.

Scoring Strategy

Default (no flag): Merge via RRF with equal weight to both sources.

Type-aware boost (optional enhancement):

  • Detect query intent by length/structure:
    • Short factoid queries ("what is X?", single term) → boost memories (+10%)
    • Long analytical queries ("how does kanban compare to delegation for fleet coordination?") → boost documents (+10%)
  • Or let the user control: --boost-docs 1.2 / --boost-memories 1.2

MCP Impact

Currently, uteke_recall MCP tool only searches memories. With unified search:

  • uteke_recall naturally returns both memories and documents.
  • One MCP tool covers all knowledge retrieval.
  • The response can include a type field so MCP consumers can distinguish: {"type": "document", "slug": "...", "title": "...", "score": 0.89} vs {"type": "memory", "id": "...", "content": "...", "score": 0.82}.

API Impact (uteke-serve)

The existing POST /recall endpoint would gain the unified behavior. The existing POST /doc/search stays unchanged for explicit document-only queries.

// POST /recall (unified, default)
{
  "query": "kanban fleet",
  "namespace": "coo"
  // no "type" field = unified
}

// POST /recall (filtered)
{
  "query": "kanban fleet",
  "namespace": "coo",
  "type": "memory"  // or "doc"
}

Alternatives Considered

Alt 1: Keep Separate (Status Quo)

  • Pro: No code changes, no risk of noise.
  • Con: Agents/users must always run two commands. Increasing fragmentation as more storage types are added (rooms, graphs, etc.).
  • Verdict: Reject — the cognitive overhead grows with every new storage type.

Alt 2: Single Table (Merge memories + documents into one table)

  • Pro: True single index, simplest query path.
  • Con: Massive schema change, migration complexity, memories and documents have different lifecycles (memories age/prune/dream, documents version/persist). Would break existing tooling.
  • Verdict: Reject — too disruptive, different lifecycle semantics make this infeasible.

Alt 3: Cross-Table FTS Index

  • Pro: Full-text search works across both tables natively.
  • Con: Only covers FTS, not vector search. Doesn't solve the semantic recall gap. Adds index maintenance burden.
  • Verdict: Not sufficient alone — vector search is the primary recall path.

Alt 4: Client-Side Merge (Proposed)

  • Pro: Zero schema changes, backward compatible, leverages existing RRF implementation, extensible (future storage types just add another source).
  • Con: Two ANN searches per query (~10ms extra latency). Type-aware ranking requires tuning.
  • Verdict: Accept — simplest path, lowest risk, fast enough (total < 50ms).

Acceptance Criteria

  • uteke recall "query" --namespace N returns results from both memories and documents by default
  • uteke recall "query" --type memory --namespace N returns memories only (backward compatible)
  • uteke recall "query" --type doc --namespace N returns documents only
  • Output clearly labels result type ([doc] vs [mem])
  • Document results include slug, title, and relevant chunk excerpt
  • Memory results include id, content excerpt, and metadata
  • MCP uteke_recall tool returns unified results with type field
  • API POST /recall endpoint accepts optional type parameter
  • Total query latency remains under 100ms for a single namespace
  • Existing uteke doc search command continues to work independently (no breaking change)

Open Questions

  1. RRF merge strategy: Equal weight for both sources, or configurable? Default equal seems reasonable for v1.
  2. Result count: Should the unified result cap be the sum of both sources (e.g., 10 memories + 10 docs = 20 total, re-ranked to top 10)? Or should each source get a proportional quota?
  3. Chunk dedup: If a document has 3 chunks matching the query, should we show all 3 or consolidate to 1 document-level result with multiple chunk excerpts?
  4. Namespace scoping: doc search currently requires --namespace. Should unified recall default to the same namespace for both, or allow cross-namespace for one source? (Suggest: same namespace for both, consistent with current behavior.)
  5. Future extensibility: The merge pattern should be designed to accommodate future storage types (e.g., graph nodes, room summaries) without structural changes. A Vec<dyn SearchSource> trait pattern would work.

Testing Strategy

  • Unit tests: Mock both backends, verify merge logic returns correct ranking
  • Integration tests: Insert known memories + documents, query, verify both appear in results
  • Performance tests: Benchmark single-source vs unified query latency (< 100ms target)
  • Backward compat tests: Verify --type memory returns identical results to current recall behavior
  • MCP tests: Verify uteke_recall response includes both types with correct schema

Related

Activity

  1. added 2 commits that reference this issue on Jul 3, 2026
  2. added 2 commits that reference this issue on Aug 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions