Applied AI / LLM

Generative Unit Testing

RAGLangChainPineconeEmbeddingsLLMPython

A retrieval-augmented system that writes unit tests for a codebase. It indexes source files into a vector store, retrieves the most relevant context for a given target, and has an LLM draft tests grounded in how the surrounding code actually behaves — rather than guessing from a function signature alone. I led the prototype during a data-engineering internship in early 2024, when retrieval-augmented generation was still an emerging technique for grounding LLMs in private context.

RAG unit-test generation pipeline Indexing path: source code is parsed and chunked, embedded, and stored in a vector database. Generation path: a target function retrieves similar context from the vector store, an LLM reads it, and emits unit tests. INDEXING GENERATION Source code repository files Parse & chunk split into documents Embed embedding model Vector store Pinecone index Target code function under test Retrieve top-k context LLM drafts tests Unit tests generated suite similarity search
Two paths over one vector store: index the codebase once, then retrieve grounded context whenever tests are generated.

Design

Why RAG

Test quality depends on context. Feeding a model only the function under test produces shallow, often wrong assertions. Retrieving the surrounding code — callers, helpers, related types — gives the model the behaviour it needs to assert against, which is what makes the generated tests useful.

Where it fits now

The core problem is the same one today's coding assistants solve: give the model enough of the surrounding code to be correct, not just a signature. What has changed is the mechanism. In early 2024, a vector store was the practical way to pull in relevant context under tight token limits; modern tools often rely on much larger context windows and agents that navigate files directly. This project was an early, working take on that same goal — and the retrieval pattern it uses still holds up wherever a codebase is too large to hand a model all at once.

Back to projects