How MemoryFirst retrieves: dense + BM25 + graph + reranking
Engineering7 min

How MemoryFirst retrieves: dense + BM25 + graph + reranking

A good answer starts with good retrieval. Here's how we combine semantic, lexical and graph search, fuse them with RRF and rerank with a cross-encoder — and why each piece matters.

The glamorous part of an AI system is generation. The part that decides whether the answer is good or garbage is retrieval. Feed the model the wrong passages and no amount of prompt engineering saves it. Here's how ours is built.

One query opens three searches in parallel; they're fused, reranked, and the answer arrives with its citation.
One query opens three searches in parallel; they're fused, reranked, and the answer arrives with its citation.

Three retrievers, not one

No single search method always wins. So we run three in parallel:

  • Dense (embeddings): captures meaning. "When does the contract expire?" finds "the term ends on December 31" even with no shared words.
  • BM25 (lexical): captures the exact. Codes, proper nouns, case numbers — where meaning isn't enough and the literal string matters.
  • Graph: captures relationships. Facts connected by entity, not just by text similarity.

Fusion: Reciprocal Rank Fusion

Three candidate lists must be combined without one artificially dominating. We use RRF, which scores each document by its rank in each list instead of by scores that aren't comparable across systems. It's simple, robust and needs no hand-tuned weights.

Cross-encoder reranking

Fusion gives you a good set; fine ordering is decided by a cross-encoder that looks at the query and each passage together (not separately, like embeddings). It's more expensive, so it only reranks the top of the pool — enough to lift precision where it counts, without paying the cost over hundreds of candidates.

And the piece that makes it reliable: degradation

If the synthesis layer is unavailable, the query returns the raw retrieved passages instead of failing. Your agent still gets useful context even when the generator has a bad day.

A good answer starts with retrieving the right thing. Generation only polishes what retrieval found.

This whole pipeline sits behind a single call to the API or the MCP server. You ask; we handle the rest.

Give your agents a memory.

The memory layer for AI: OpenAI-compatible API + MCP, with citations and EU data.

Start free