How to build a RAG API in Node.js 2026: pgvector and cited answers
Build a production RAG API in Node.js using pgvector: text ingestion, chunked embeddings, vector search, and source-cited answers in under 80 lines.
Tag · rag
Build a production RAG API in Node.js using pgvector: text ingestion, chunked embeddings, vector search, and source-cited answers in under 80 lines.
Embedding 1M docs costs $10 with text-embedding-3-small or $67 with the large model. BGE-M3 self-hosted breaks even at 27B tokens per month. The math.
Embeddings convert text into vectors that capture meaning. Here's how cosine similarity works and how to pick the right model for your RAG pipeline.
We ran 4 models through 6 RAG-specific prompts testing faithfulness, citation accuracy, and I-don't-know honesty. Opus 4.8 takes 15 of 18 head-to-heads.
RAG has 3 moving parts: ingestion, retrieval, and generation. Here's what each does, when RAG beats fine-tuning, and when to skip it entirely.