data
Ingest
PDFs and HTML pages stream into a document worker. Layout-aware chunking (600-token target, 60-token overlap) preserves clause boundaries. Each chunk gets a stable hash so re-ingestion is idempotent.
05 ::: pipeline
How a query travels from a user keystroke to a grounded, streamed answer.
A diagram of the end-to-end pipeline behind the document-intelligence RAG system. Click any node to see what's actually running inside.
flow · click any node
data
processing
model
output
feedback
What's actually running inside each step.
data
PDFs and HTML pages stream into a document worker. Layout-aware chunking (600-token target, 60-token overlap) preserves clause boundaries. Each chunk gets a stable hash so re-ingestion is idempotent.
data
Chunks → text-embedding-3-large (1536 dims). Embeddings stored in Postgres + pgvector with HNSW index. Backfill runs in the same worker — single source of truth for which chunks exist.
processing
Haiku rewrites the user query into 3 variants: literal, hypothetical answer, broader topic. All three search in parallel — recall over precision at this stage.
processing
BM25 (Postgres tsvector) + dense (pgvector) → 50 candidates. Reciprocal rank fusion combines, deduplicates by chunk hash.
model
bge-reranker-v2-m3 scores all 50 candidates against the original query. Top 5 survive — this stage owns most of the precision improvement.
model
Sonnet receives the top 5 chunks + the original query + a system prompt that requires citations by chunk-id. Streams response over SSE.
output
Token deltas arrive at the Next.js edge, forwarded to the browser. Citations resolved client-side: chunk-id → highlighted source PDF link.
feedback
Every query → a trace event in Honeycomb. Thumbs-down + low-confidence answers auto-route into the eval suite review queue. The suite gates every prompt + model change.