Repository navigation
Description
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 onlyThis means:
- Agents need to know where data lives — but they shouldn't have to. A search should return everything relevant, regardless of storage backend.
- 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".
- 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.
- MCP tool fragmentation — the
uteke_recallMCP 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-456Filter 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 cooImplementation 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
memoriesanddocument_chunkstables stay untouched. - The
--typeflag maps directly to existing code paths:--type memory= currentrecallbehavior,--type doc= currentdoc searchbehavior.
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_recallnaturally returns both memories and documents.- One MCP tool covers all knowledge retrieval.
- The response can include a
typefield 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 Nreturns results from both memories and documents by default -
uteke recall "query" --type memory --namespace Nreturns memories only (backward compatible) -
uteke recall "query" --type doc --namespace Nreturns 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_recalltool returns unified results withtypefield - API
POST /recallendpoint accepts optionaltypeparameter - Total query latency remains under 100ms for a single namespace
- Existing
uteke doc searchcommand continues to work independently (no breaking change)
Open Questions
- RRF merge strategy: Equal weight for both sources, or configurable? Default equal seems reasonable for v1.
- 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?
- 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?
- Namespace scoping:
doc searchcurrently requires--namespace. Should unifiedrecalldefault to the same namespace for both, or allow cross-namespace for one source? (Suggest: same namespace for both, consistent with current behavior.) - 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 memoryreturns identical results to currentrecallbehavior - MCP tests: Verify
uteke_recallresponse includes both types with correct schema
Related
- feat(#286): room-based collaborative memory for multi-agent discussions #300 Room-based collaborative memory
- feat: document engine — documents + document_chunks tables (wiki/knowledge base) #406 Document Engine
- feat: add document API endpoints to uteke-serve #441 Doc API endpoints
- Skill discussion: Hermes Agent COO fleet — agents need unified knowledge retrieval across both short-term memories and long-form documents without managing two separate query paths
Activity
feat: unified search across memories and documents (#531)
Merge pull request #532 from codecoradev/feat/unified-search-531
feat: unified search across memories and documents (#531)
Merge pull request #532 from codecoradev/feat/unified-search-531