MongoDBProblem & solution
The Cheapest Token You Never Send: Agentic AI Search on MongoDB + Voyage AI
Summary
The post reframes cost, latency, and answer quality in agentic AI search as a single retrieval precision problem. Its pipeline embeds with flexible Voyage AI dimensionality and automatic quantization in MongoDB index, with binary reducing RAM by roughly 24x. Hybrid search via $rankFusion combines vector and full-text search with metadata filters in one server-side query, eliminating separate systems. A Voyage reranker then reorders the broad candidate set by true relevance, allowing the LLM to receive only the top few high-signal chunks and drastically shrinking input context. The agentic loop over consolidated Atlas where data, vectors, embeddings, and reranking coexist minimizes network hops per iteration, and an illustrative example shows an 80% reduction in retrieved-context input tokens.
Context
Production agentic AI applications face hidden input token costs and latency from retrieved context, which also dilutes answer quality. This post presents a pipeline incorporating embedding quantization, hybrid search with $rankFusion, reranking with Voyage AI, and an agentic loop over a consolidated MongoDB Atlas platform.
Approach / What changed
The post describes a four-stage pipeline: (1) embed with Voyage AI models using flexible dimensionality and enable automatic int8 or binary quantization in MongoDB to reduce storage cost; (2) retrieve using hybrid search via $rankFusion that combines vector and full-text search with metadata filters in one server-side query; (3) rerank the broad candidate set with a Voyage reranker (rerank-2.5) to reorder by true relevance and keep only top chunks; (4) implement an agentic loop where an agent iteratively decides to retrieve, evaluates results, and generates, all over consolidated Atlas to minimize hops.
Takeaways
Automatic quantization in MongoDB Vector Search (int8 or binary) reduces RAM usage by roughly 3.75x or 24x respectively, lowering cost and speeding up search.
Hybrid search via $rankFusion combines vector and full-text search in one server-side query with metadata filters, reducing network hops and avoiding irrelevant data processing.
Using a Voyage reranker after broad retrieval allows sending only the top few high-relevance chunks to the LLM, achieving an 80% reduction in retrieved-context input tokens in an illustrative example.
FAQ
How does automatic quantization work in MongoDB Vector Search?
MongoDB Vector Search automatically quantizes float embeddings to compact int8 or binary representations directly in the index. You declare the quantization type, and both stored and query vectors are quantized at query time with no code changes. Scalar quantization reduces RAM roughly 3.75x, binary 24x.
What is the benefit of using $rankFusion for hybrid search?
$rankFusion implements Reciprocal Rank Fusion natively, combining a $vectorSearch pipeline and a full-text $search pipeline in a single server-side query. This avoids two separate systems and client-side merge, reducing latency and enabling metadata filters so you never retrieve irrelevant data.
Why should I use a reranker before sending context to the LLM?
A reranker reorders a broad candidate set by true relevance to the query using a cross-encoder model, allowing you to send only the top few high-signal chunks to the LLM. This dramatically shrinks input context, reducing token cost and latency while improving answer quality by removing noise.
Source and freshness
- Source
- mongodb.com
- Published
- Added to Yomu
Summaries are generated from the original by a language model. Check the original before relying on it.
Keep reading
Related reading
The Good Stuff
Paid picks we use ourselves. Links carry a referral code — a subscription through one earns us a commission at no extra cost to you.
The best engineering reads, once a week
One useful email. Unsubscribe anytime.