RAGAI AccuracyTechnical Deep-Dive
Merlin AI Code Review

How RAG Makes AI Code Review 10x More Accurate

February 18, 2025·8 min read·Merlin AI Code Review Team

A common complaint about AI code review tools is that comments feel generic — good advice in general, but not tuned to your project. Merlin AI Code Review's RAG (Retrieval-Augmented Generation) pipeline solves this by giving the AI deep, searchable knowledge of your specific codebase before every review.

The problem with context-blind AI review

Without RAG, an AI code reviewer sees only the PR diff. It applies general knowledge about programming best practices but knows nothing about:

The result is generic comments that miss project-specific issues, and false positives that flag "violations" of patterns your team intentionally doesn't follow.

How RAG works in Merlin AI Code Review

Merlin AI Code Review's RAG pipeline has two phases:

  1. Index phase — you run merlin rag index . once (and periodically thereafter). Merlin AI Code Review walks your source files, splits them into chunks, embeds each chunk using Ollama's nomic-embed-text model, and stores the embeddings in your chosen vector store.
  2. Retrieval phase — at review time, each diff chunk is embedded and the most semantically similar indexed documents are retrieved. These become additional context in the AI prompt, giving the model knowledge of related existing code.

Getting started with RAG

merlin.toml
toml
[rag]
enabled = true
store = "local" # zero infrastructure required
embed_model = "nomic-embed-text"
top_k = 5 # documents retrieved per diff chunk
min_score = 0.70 # minimum similarity threshold
shell
$ ollama pull nomic-embed-text # one-time setup
$ merlin rag index . # index your codebase
$ merlin review # next review uses RAG context

What improves with RAG enabled

Consistency detection: Merlin AI Code Review sees that your codebase uses a specific error handling pattern and flags when a PR deviates from it — even if the deviation is technically valid in isolation.

Cross-file impact: A PR changes an interface. RAG retrieves the implementations of that interface elsewhere in the codebase. Merlin AI Code Review can then comment that the change breaks three existing implementations not included in the diff.

Reduced false positives: Generic AI review might flag a pattern as unusual. With RAG, Merlin AI Code Review sees that the same pattern is used 40 times in your codebase and is clearly intentional — so it doesn't flag it.

Convention enforcement: Merlin AI Code Review learns your actual naming conventions, import patterns, and structural idioms from the indexed code and enforces them specifically in review.

Vector store options

The local JSONL store is zero-infrastructure and works for most teams. For larger codebases or teams that want persistent shared indexing, Merlin AI Code Review supports Qdrant, ChromaDB, and Pinecone. See the RAG documentation for setup details.