How do I use RAG in my daily coding and vibe coding?
Your coding agent already uses RAG when it searches your code. Add today’s docs, a rules file and your tickets. Setup, pitfalls and 2026 numbers.
You already use RAG every time your coding agent searches your code before it writes. To get more from it, give the agent three more places to look: today’s library docs, one short file with your team’s rules, and your tickets and wiki. Then check which page it used.
RAG (retrieval-augmented generation) in one line: the AI looks things up first, then answers from what it found. If that is new, my one-minute video What is RAG? shows it with a shelf of files. This article is about the shelf a developer has.
Your coding agent already searches your code
When I ask an agent to fix a booking bug, the first thing it does is not write. It runs searches: file names, the error text, the function that throws it. Then it opens three or four files and reads them. That is retrieval. The answer comes from your code.
There are two ways a tool can do this, and the tools have been moving between them.
Index
- Code cut into chunks
- Each chunk becomes a vector
- Search by meaning
Agent search
- grepThe agent types a search
- openReads a file
- grepSearches again
- Answer
Search, read, search again, as many times as it needs
An index. The tool cuts your code into chunks and stores each one as a vector, a list of numbers for its meaning (my video What is a vector database? shows how). A question finds code that means the same thing, even with different words. GitHub Copilot still works this way: its #codebase tool “is always semantic”.
Agent search. The agent uses grep and file reads, the same tools you use, and decides what to search next. Boris Cherny, who created Claude Code, wrote in February 2026: “Early versions of Claude Code used RAG + a local vector db, but we found pretty quickly that agentic search generally works better” (Boris Cherny on X). Codex is told to prefer rg (ripgrep, a fast grep). In July 2026 Cursor stopped storing embeddings of your code for search and moved to a local grep index. In November 2025 Cursor had published a 12.5% accuracy gain from semantic search. Eight months later, Cursor’s team wrote on its forum that models had become so good at grep that the index was no longer helping much.
The research is not settled. A May 2026 paper that tested Claude Code, Codex and Gemini CLI on a memory benchmark found grep “generally” more accurate than vector search. An August 2026 paper on questions about real repositories found the opposite: semantic search 65.2% right, deep agent search 46.2%. My rule of thumb:
| Your situation | What works better |
|---|---|
| You know a name: a function, an error text, a config key | Agent search. Exact words, always current. |
| You know the idea but not the words (“where do we charge the card?”) | An index, or ask the agent to try several words |
| A very large repo, or many repos | An index or a search subagent. Grep gets slow; Cursor saw grep calls over 15 seconds in big repos |
| Code that changed five minutes ago | Agent search. An index can be stale; Anthropic says grep and glob avoid “the issues of stale indexing” |
You do not need to pick. Use the tool you have, and when the answer is wrong, first ask: did it look in the right file?
Give the AI today’s library docs, not its memory
A model knows a library as it was on its training cutoff day. Claude Sonnet 4.6 stops in August 2025 (Anthropic). Next.js 16 came out on 21 October 2025 and renamed middleware.ts to proxy.ts. A model trained before that date cannot know it, so it writes the old file name.
This is common. A study at ICSE 2025 found that models used deprecated APIs in 25% to 38% of completions in its tests, and bigger models used them more often. Another, at USENIX Security 2025, found that 19.7% of the packages models suggested did not exist at all. Newer models invent fewer: about 5% to 6% in a 2026 re-test. Fewer is still not zero.
The fix is a docs server: an MCP tool that fetches the current docs for the exact version you use. (MCP, the Model Context Protocol, is the standard plug that connects tools to an AI.) Context7 is the most starred (about 63,000 GitHub stars in October 2026); Microsoft Learn and GitMCP do the same for their docs.
# set up once
npx ctx7 setup
# then in a prompt
Add the auth check from the old middleware to proxy.ts for Next.js 16. use context7
# any GitHub repo's docs as an MCP server
github.com/owner/repo -> gitmcp.io/owner/repo
A docs server also puts outside text into your agent, and that is a risk. In August 2026 a flaw in Context7 up to version 2.1.2 let poisoned instructions tell agents to send out keys from .env files. Keep it updated, and never run an agent with production keys in its folder.
Put your team’s rules in one short file the agent reads first
Some knowledge is not in the code. “We never edit migrations by hand.” “Dates are Sydney time.” “That folder is dead, ignore it.” Agents read a rules file before they start: AGENTS.md (used by over 60,000 open-source projects and read by Codex, Cursor, Copilot’s agent, Gemini CLI and others), CLAUDE.md for Claude Code, or .cursor/rules.
This is the cheapest retrieval you can set up. A short one looks like this:
# AGENTS.md
## Project
Booking app for a renovation company. Next.js 16, Postgres.
## Commands
- Test: npm test
- Lint: npm run lint
## Rules
- Dates in Australian format, Sydney time.
- Never edit files in /migrations by hand. Ask first.
- Every new API route gets a test that tries to read another user's data.
## Where things are
- Bookings: src/bookings/
- Decisions and the reasons: docs/decisions/
Keep it short. Anthropic’s advice is “under 200 lines” per file, because “longer files consume more context and reduce adherence”. Put long how-tos in their own files and link them. The agent opens them only when it needs them. That is the idea behind Agent Skills.
Add the docs/decisions/ line even if the folder is small. A short note per decision, with the reason, stops the agent from “fixing” something your team chose on purpose.
Connect tickets and the wiki, read-only first
The why behind a change sits in Jira, Linear, Confluence, Notion or GitHub issues. All of them now have official MCP servers. With one connected, the agent can read the ticket and the acceptance criteria before it plans.
Ticket
Let customers cancel a bookingAcceptance criteria
Wiki page
Booking rulesStart with read access only. In May 2025 researchers showed that a planted GitHub issue could make an agent copy private repo data into a public pull request. Whatever the agent reads can carry instructions. Read-only access and a person who approves every write keep that small.
Ask your codebase before you change it
Half of developers in Stack Overflow’s 2026 survey (49.7%) already use AI to understand or onboard to a codebase. Three questions that work well in a repo you do not know:
Where is a booking created, from the button to the database row? List the files in order.
If I change the price field from a number to a decimal type, what breaks? Search first, then list each place.
Which tests cover cancellation? Which paths have no test?
Ask for file names and line numbers in every answer. You can open them and check in seconds. In the same survey, 93% of developers named “source attribution” as something that makes them trust an AI answer. A file path is the simplest source.
When RAG makes the answer worse
| Problem | What you see | Fix |
|---|---|---|
| Stale index | The agent edits a function you renamed this morning | Re-index, or let it grep |
| Too much context | Answers get vaguer as you paste more | Give less. Chroma’s tests on 18 models: quality drops as input grows, and “even a single distractor reduces performance” |
| Secrets in reach | Keys show up in a prompt or a log | Ignore files for .env; Cursor warns that terminal and MCP tools “may still be able to read ignored files” |
| Poisoned text | The agent follows an order hidden in a doc or an issue | Read-only tools, updated servers, a person approves writes (CVE-2026-75130, Invariant Labs) |
| Wrong page | A confident answer from an old doc or a similar function | Ask for the source, open it |
Does the app I am building need RAG?
Sometimes the app itself needs to look things up: a support bot over your help pages, a search over a client’s contracts. Two facts help you decide. If all the text is under about 500 pages, Anthropic’s advice is to put it all in the prompt and skip retrieval. Above that, mix keyword search with vector search and add a reranker. In Anthropic’s tests, that mix with their contextual method cut failed lookups by 67%. In Menlo Ventures’ 2024 enterprise survey, 51% of companies used RAG, up from 31% a year before.
When a client app needs this, it is one of the things my team builds, with tests for the answers it gives. Checking those answers works like checking any code AI writes.
The numbers, by year
Developers who use AI coding agents or assistants2025 to 2027. The 2027 bar is a guess.
Sources: Stack Overflow Developer Survey 2025 and 2026 (different survey questions); JetBrains, August 2026.
- 2025. Stack Overflow: about 31% used AI agents; 46% did not trust AI accuracy (Stack Overflow 2025). Among agent users at work, 34.4% used MCP servers.
- 2026. Stack Overflow: 66% use coding assistants or agents, 73% of them daily (Stack Overflow 2026). JetBrains, August 2026: 90% use AI coding agents at work every week. MCP SDKs: close to 500 million downloads a month, up from 97 million in December 2025.
- 2027 (my guess). Gartner expects 90% of enterprise engineers to use AI code assistants by 2028. My guess for 2027: developers stop choosing how the tool searches and spend that effort on what the agent reads: rules files, docs servers and decision notes.
Start this afternoon
- 1. Ask your agent one “where is” question in your repo. Check the files it names.
- 2. Write a 30-line
AGENTS.md(orCLAUDE.md): commands, five rules, where things are. - 3. Add a docs server and use it for the next library question.
- 4. Add
.envand key files to your ignore file. - 5. Connect your ticket tool, read-only.
- 6. For one week, ask for the source in every answer. Note when it was wrong and why.
Questions people ask
Do I need a vector database to use RAG for coding?
No. Most coding agents now search with grep and file reads. A vector index helps in very large repos or when you search by idea, not name.
Is RAG the same as giving the AI my whole codebase?
No. RAG brings in only the pieces that match. Giving everything costs more and often makes answers worse.
Does vibe coding need any of this?
Yes, more than normal coding. If you do not read every line, the agent must read the right docs and rules for you. A rules file and a docs server are the two cheapest steps. If your app is already stuck, see how to finish a vibe-coded app stuck at 80%.
Is my code sent to the cloud when the tool searches it?
It depends on the tool. Cursor’s grep index stays on your machine, but files the agent opens still go to the model. Copilot’s index is not used for training. Check your tool’s data page.
If you want help setting this up for your team, or a RAG feature in an app you are building, tell me about it.
Have an app idea, a stuck app, or a daily job you want an AI agent to do?
Write three lines. I reply within one working day with a plain answer.
Sources. Anthropic: Effective context engineering for AI agents (29 Sep 2025); Contextual Retrieval (19 Sep 2024); Claude Code memory docs; Agent Skills (16 Oct 2025); Claude training data dates. Boris Cherny on X (1 Feb 2026). Cursor: Improving agent with semantic search (6 Nov 2025); Fast regex search (23 Mar 2026); Search and ignore-file docs; Cursor forum (Jul 2026). VS Code docs: How Copilot understands your workspace. GitHub Docs: repository indexing; GitHub MCP server. OpenAI Codex repo. agents.md. Next.js 16 release (21 Oct 2025). Context7 README; CVE-2026-75130. Wang et al., ICSE 2025. Spracklen et al., USENIX Security 2025. Churilov 2026. Invariant Labs (26 May 2025). Chroma: Context Rot (14 Jul 2025). arXiv 2605.15184 and 2608.01507. Stack Overflow Developer Survey 2025 and 2026. JetBrains (Aug 2026). MCP blog (28 Jul 2026). Menlo Ventures (2024). Gartner via GitHub (22 Sep 2025).


