HerokuAnush DSouzaTutorial
Building AI Search on Heroku
Summary
The reference architecture addresses a common RAG failure: vector search can return semantically similar documentation that does not answer the user's question. Its query pipeline retrieves the top 20 chunks with cosine similarity in Heroku Postgres and pgvector, then sends those candidates to Cohere Rerank 3.5, a cross-encoder reranker, before Claude 3.5 Sonnet generates an answer. The indexing pipeline crawls URLs, filters likely boilerplate, splits documents into 1,000-character chunks with 200-character overlap at natural boundaries, embeds them with Cohere Embed Multilingual, and batch-inserts them. Server-Sent Events stream embedding, search, reranking, sources, and generated text to avoid a blank screen during the multi-step request. The reranking stage can be made optional when lower latency matters more than precision.
Context
Vector search may return documents that are semantically similar to a query but do not actually answer it, creating a gap between a RAG demonstration and a production-grade enterprise search system.
Approach / What changed
The architecture uses separate indexing and query pipelines with Heroku Managed Inference and Agents, Heroku Postgres with pgvector, two-stage retrieval, natural-boundary chunking, batch inserts, and Server-Sent Events for progress and answer streaming.
Takeaways
Two-stage retrieval first selects the top 20 chunks by cosine similarity, then uses Cohere Rerank 3.5 to score query-document relevance and return the top five.
Documents are split into 1,000-character chunks with 200 characters of overlap, prioritizing paragraph or sentence boundaries before embedding and storage.
Server-Sent Events expose embedding, searching, reranking, sources, and generated text while the multi-step RAG request is running; reranking may be disabled when latency matters more than precision.
Source and freshness
- Source
- heroku.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.