Skip to main content

Overview

When the agent calls memory_recall, MemU performs a multi-stage search that combines full-text matching with semantic similarity to find the most relevant memories.

Search Pipeline

The query is run against the FTS5 index. This finds memories that contain matching terms:
FTS5 provides a relevance rank based on term frequency, position, and document length.

Stage 2: Embedding Similarity

The query is embedded into a vector and compared against stored memory embeddings using cosine similarity:
This catches semantically related memories that may not share exact words with the query. For example, “computer setup” would match a memory about “infrastructure specs.”

Stage 3: Score Fusion

FTS5 scores and embedding similarity scores are combined:
Key details:
  • Similarity is squared (sim²) to amplify strong matches and suppress weak ones
  • Significance adds a boost based on the memory’s importance score
  • Memory recall queries get a +0.25 score boost for model routing (ensures at least Haiku tier)

Stage 4: Reranking

Results are reranked with additional signals:
  • Recency: More recent memories get a slight boost
  • Reinforcement: Memories that have been recalled frequently (log2 reinforcement) rank higher
  • Entity matching: Memories mentioning entities in the query get a boost
If the reranker encounters errors, it falls back safely to the fusion score ordering.

Query Optimization

Best Practices

FTS5 Syntax

Result Format

Search results are returned to the agent as a structured list: