Skip to content
← Home

05 ::: pipeline

Pipeline Visualizer

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

8 edges
  • ingest embed
  • embed retrieve
  • query retrieve
  • retrieve rerank
  • rerank synthesize
  • synthesize stream
  • stream log
  • log query

All nodes

What's actually running inside each step.

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.

data

Embed

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

Query rewrite

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

Hybrid retrieve

BM25 (Postgres tsvector) + dense (pgvector) → 50 candidates. Reciprocal rank fusion combines, deduplicates by chunk hash.

model

Cross-encoder rerank

bge-reranker-v2-m3 scores all 50 candidates against the original query. Top 5 survive — this stage owns most of the precision improvement.

model

Synthesize

Sonnet receives the top 5 chunks + the original query + a system prompt that requires citations by chunk-id. Streams response over SSE.

output

Stream to client

Token deltas arrive at the Next.js edge, forwarded to the browser. Citations resolved client-side: chunk-id → highlighted source PDF link.

feedback

Log + eval 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.