惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

有赞技术团队
有赞技术团队
G
Google Developers Blog
T
Tailwind CSS Blog
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
人人都是产品经理
人人都是产品经理
J
Java Code Geeks
P
Proofpoint News Feed
V
Visual Studio Blog
爱范儿
爱范儿
The Cloudflare Blog
博客园 - 叶小钗
V
V2EX
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
M
MIT News - Artificial intelligence
Microsoft Security Blog
Microsoft Security Blog
博客园 - 聂微东
H
Help Net Security
B
Blog
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
博客园 - 【当耐特】
量子位
宝玉的分享
宝玉的分享
WordPress大学
WordPress大学
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知

DEV Community

Authentication Security Deep Dive: From Brute Force to Salted Hashing (With Java Examples) Why AI Systems Don’t Fail — They Drift Spilling beans for how i learn for exam😁"Reinforcement Learning Cheat Sheet" I Replaced Chrome with Safari for AI Browser Automation. Here's What Broke (and What Finally Worked) How Python Borrows Other People's Work The $40 Architecture: Processing 1 Billion API Requests with 99.99% Uptime Vibe Coding: A Workflow Guide (From Zero to SaaS) Most webhook security guides protect the wrong side. The scary part is delivery. Headless CMS for TanStack Start: Build a Blog with Cosmic EU Age Verification App "Hacked in 2 Minutes" — What Actually Happened Comfy Cloud’s delete function does not actually remove files Running AI Models on GPU Cloud Servers: A Beginner Guide Event-driven media intelligence with AWS Step Functions and Bedrock I scored 500 AI prompts across 8 quality dimensions — here's what broke How to Call Google Gemini API from Next.js (Free Tier, No Backend Needed) The Portal Protocol: Reclaiming Human Connection in the Age of AI How to Fix Your Team's Scattered Knowledge Problem With a Self-Hosted Forum Intro to tc Cloud Functors: A Graph-First Mental Model for the Modern Cloud Designing Multi-Tenant Backends With Both Ownership and Team Access I Built a Neumorphic CSS Library with 77+ Components — Here's What I Learned PostgreSQL Performance Optimization: Why Connection Pooling Is Critical at Scale Cómo construí un SaaS multi-rubro para gestionar expensas en Argentina con FastAPI + Vue 3 🚀 I Built an Ethical Hacking Scanner Tool – Open Source Project I Replaced /usage and /context in Claude Code With a Single Statusline A Pythonic Way to Handle Emails (IMAP/SMTP) with Auto-Discovery and AI-Ready Design I Collected 8.9 Million Polymarket Price Points — Here's What I Found About How Markets Really Move EcoTrack AI — Carbon Footprint Tracker & Dashboard Everyone's Using AI. No One Agrees How. 5 self-hosted ebook managers worth trying in 2026 Building Your First AI Agent with LangChain: From Chatbot to Autonomous Assistant
RAG Explained: Retrieve, Then Answer (the Prompt That Kil...
Devanshu Biswas · 2026-06-14 · via DEV Community

Devanshu Biswas

An LLM only knows what it saw in training. It doesn't know your company wiki, last week's news, or the PDF you just uploaded. Ask it anyway and it either refuses or — worse — confidently makes something up.

RAG (Retrieval-Augmented Generation) fixes that, and it's far simpler than the name suggests. This is Day 5 of my PromptFromZero series.

RAG in one sentence

Fetch the relevant facts at question time, and hand them to the model to read.

You're not asking the model to remember. You're giving it the page to read.

The three moves

1. Retrieve

Embed the question, find the closest document chunks (vector search), grab the top few:

const hits = await search(question, { k: 3 }); // the 3 most relevant chunks

(The retrieval half is its own topic — embeddings + a vector database. I built exactly that in TechFromZero Day 45 with Postgres + pgvector.)

2. Augment — the prompt that does the heavy lifting

This template is 80% of RAG quality:

const prompt = `Answer using ONLY the context below.
If the answer isn't there, say "I don't know."

Context:
${hits.map(h => "- " + h.text).join("\n")}

Question: ${question}`;

The words "ONLY the context" matter. Without them, the model blends its own (possibly wrong) memory back in. With them, it sticks to the source you gave it.

3. Generate

Send that prompt to the LLM. Done. The answer is now grounded in your documents.

The two knobs

  • top-k: too small (k=1) and you miss the answer; too big (k=20) and you bury it in noise and pay for tokens. Start at k=3.
  • chunk size: too big and irrelevant text rides along; too small and meaning is lost. ~300 tokens is a good default.

Make it refuse and cite

Hallucinations mostly happen when the context doesn't contain the answer but the model answers anyway. Two instructions turn a guesser into a librarian:

  • "If the context lacks the answer, reply exactly: I don't know."
  • "Quote the chunk you used."

That's it. Retrieve → Augment → Generate. Pair this prompt half with a vector store (pgvector, Pinecone, Chroma...) and you've built "chat with your docs."

📎 Try the interactive RAG playground — watch retrieval + the prompt + the answer: https://dev48v.infy.uk/prompt/day5-rag-basic.html

Day 5 of PromptFromZero. One prompting technique a day, explained for beginners.