Self-correcting RAG code assistant
A local assistant that answers programming questions from a code corpus, reviews its own answers and retries when they fall short.
Problem
Answering questions about code with a small local model, without sending anything to an external API. Small models hallucinate readily, so retrieval quality and answer checking matter more than model size.
Approach
- Retrieval. MiniLM sentence embeddings, fine-tuned on the CoSQA code-search dataset, stored in a Qdrant vector database.
- Generation with self-correction. Phi-3 running locally through Ollama drafts an answer, critiques it against the retrieved code, and revises it when the critique fails. The loop is orchestrated with LangChain.
- Evaluation. An LLM-as-judge harness scores correctness and faithfulness to the retrieved sources. Every run is tracked in MLflow.
Findings
I benchmarked the pipeline against agentic variants in which a 3B model chooses its own tools. The simpler self-correcting pipeline won clearly: 83% against 33% correctness. At this scale the agents often ran out of steps before producing an answer.
The project is now growing into a full agentic coding assistant, with tools for semantic search, file reading and grep. The original pipeline stays in place as the baseline any new version has to beat.



