Building AI Search on Heroku
A reference RAG architecture on Heroku pairs pgvector cosine-similarity search (top 20 chunks) with a cross-encoder reranker (Cohere Rerank 3.5, top 5), so answers come from documents that actually address the query rather than ones that are merely semantically close. Indexing crawls sites using a junk-content heuristic, splits text into 1000-character chunks with 200-character overlap at paragraph or sentence boundaries, and batch-inserts embeddings with Postgres unnest. Generation uses Claude 3.5 Sonnet, and Server-Sent Events stream pipeline progress and sources to the client. Reranking can be switched off when latency matters more than precision.
Related posts
- Building Data-Aware AI Applications with Heroku AI and LlamaIndex
Heroku Engineering mediumAdeptA RAG stack on Heroku pairs LlamaIndex for ingestion, indexing and retrieval with Heroku Managed Inference (Claude 4 Sonnet via an OpenAI-compatible API), Cohere Embed Multilingual for embeddings, and Heroku Postgres with pgvector as the vector store. The walkthrough provisions the add-ons via the Heroku CLI. It then shows Python code that points LlamaIndex's OpenAILikeEmbedding at Heroku's embedding endpoint, stores 1024-dimension vectors in PGVectorStore, and queries documents through a query engine. Example use cases include financial report analysis, insurance claim agents and support chatbots.
- Build an end-to-end RAG pipeline entirely in psql using pgrag and DeepSeek
Neon mediumAdept
pgrag, Neon's open-source Postgres extension, lets you build a complete RAG pipeline inside psql. It provides SQL functions for PDF/DOCX/HTML text extraction, character- or token-based chunking, local CPU embeddings (bge-small-en-v1.5) and reranking (jina-reranker-v1-tiny), plus API calls to OpenAI, Voyage, Anthropic and Fireworks. Paired with pgvector HNSW indexes, a worked example indexes PGConf EU 2023 slides. A single query then retrieves the top 10 chunks, reranks them to 5, and prompts DeepSeek V3, which correctly declines out-of-scope questions. The local models ship as separate ~100MB extensions, and on Neon they need around 2GB RAM of compute.
- Storing OpenAI embeddings in Postgres with pgvector
Supabase mediumAdeptpgvector adds a vector data type and distance operators (Euclidean <->, negative inner product <#>, cosine <=>) to Postgres, so OpenAI text-embedding-ada-002 embeddings (1536 dimensions) can be stored and queried for similarity directly in the database. The walkthrough creates a documents table, a match_documents SQL function that filters by a cosine-similarity threshold, and an IVFFlat index sized at roughly 4 * sqrt(rows) lists. It then generates embeddings in JavaScript and builds Deno Edge Functions for semantic search and for retrieval-augmented answers with text-davinci-003, keeping injected context under about 1500 tokens to fit the 4000-token limit.
- Run Embedding Models and Unlock Semantic Search with Docker Model Runner
Docker mediumAdeptDocker Model Runner can serve embedding models locally, so semantic search and RAG pipelines run without sending private data to a hosted API and without per-call costs. Embeddings map text and code to vectors where semantically related items cluster, and cosine similarity ranks documents against a query. Getting started takes two steps: pull a model such as ai/qwen3-embedding, then call the OpenAI-style /engines/v1/embeddings endpoint on localhost. A sketched code-search workflow chunks a codebase, embeds the chunks, stores the vectors (a file in the demo, a vector database like Milvus, Qdrant or pgvector in practice) and ranks them by cosine similarity.
- Neon Docs search is now built on Neon
Neon mediumAdept
Neon's docs search now runs entirely on its own stack: Lakebase Postgres with the lakebase_vector (pgvector-compatible ANN) and lakebase_text (BM25) extensions, a Hono API on Neon Functions, and Neon AI Gateway for embeddings and reranking. Pages are ingested as markdown via a GitHub Action, chunked by heading, embedded and stored with tsvectors in one table. To fit search-as-you-type latency budgets, full hybrid results (ANN plus BM25 merged with reciprocal rank fusion, then an LLM rerank) are precomputed for common queries and cached, while unseen queries fall back to BM25 only. Cache hits take 1.9 ms and BM25 misses 8.6 ms at p50 on the server, and top-5 hit rate rose from 80% to 94% on 171 real queries.