Overview
When the agent callsmemory_recall, MemU performs a multi-stage search that combines full-text matching with semantic similarity to find the most relevant memories.
Search Pipeline
Stage 1: FTS5 Full-Text Search
The query is run against the FTS5 index. This finds memories that contain matching terms:Stage 2: Embedding Similarity
The query is embedded into a vector and compared against stored memory embeddings using cosine similarity:Stage 3: Score Fusion
FTS5 scores and embedding similarity scores are combined:- 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
| Syntax | Example | Meaning |
|---|---|---|
word | infrastructure | Match this term |
word1 word2 | Jason preferences | Match both terms (AND) |
word1 OR word2 | telegram OR discord | Match either term |
"phrase" | "model router" | Match exact phrase |
word* | config* | Prefix match |
