Skip to content

Retrieval Pipeline

Mnemo uses a 10-stage retrieval pipeline that combines multiple search strategies.

Architecture

Query → Preprocessing → Embedding → Triple-Path Search → Fusion → Decay → Rerank → MMR → Filter → Results

Stage 1: Preprocessing

Query expansion, date format normalization (supports Chinese and English date formats).

Stage 2: Embedding

Query text → vector using the configured embedding model.

Three independent search paths run in parallel:

PathMethodStrength
VectorCosine similarity searchSemantic understanding
BM25Full-text keyword searchExact term matching
GraphGraphiti knowledge graphEntity relationships

Stage 4: Reciprocal Rank Fusion (RRF)

Results from all three paths are fused using RRF, which combines rankings without requiring score normalization.

Stage 5: Weibull Decay

Each result's score is adjusted by the Weibull decay function based on memory age and tier:

score × exp(-(t/λ)^β)
TierβBehavior
Core0.8Slow initial decay, then rapid
Working1.0Exponential (standard)
Peripheral1.3Fast initial decay

Stage 6: Cross-Encoder Rerank

Optional high-precision reranking using a cross-encoder model. Supports Jina, Voyage, SiliconFlow, Pinecone, or local Ollama.

Stage 7: MMR (Maximal Marginal Relevance)

Reduces redundancy by penalizing results that are too similar to already-selected results.

Stage 8: Scope Filtering

Filters results to only include memories from the requested scopes.

Stage 9: Noise Filtering

Removes low-quality fragments using an embedding-based noise bank.

Stage 10: Context Assembly

Final results are assembled with metadata for injection into the LLM context.

Configuration

typescript
const mnemo = await createMnemo({
  embedding: { /* ... */ },
  dbPath: './db',
  retrieval: {
    candidatePoolSize: 20,        // candidates before reranking
    rerank: 'cross-encoder',      // enable reranking
    rerankProvider: 'jina',
    rerankApiKey: process.env.JINA_API_KEY,
    rerankModel: 'jina-reranker-v2-base-multilingual',
  },
});

Released under the MIT License.