Evaluating LLM Coding Agents by Building a Vector Database from Scratch
Building a vector database from scratch provides a practical way to evaluate LLM coding agents across system design, algorithm correctness, performance, and autonomous debugging. This article outlines a reproducible task specification, key implementation considerations, evaluation criteria, common failure patterns, and a workflow for comparing models beyond whether their code simply runs.
1. Why Use a Vector Database to Evaluate Coding Agents?
Evaluating an LLM’s agentic coding capabilities requires a task that is representative of real development work and covers the core engineering workflow. A vector database fits this requirement well. As a foundational component of modern retrieval-augmented generation (RAG) systems, it involves data modeling, vector indexing, similarity computation, persistence, and query interfaces.
Asking a model to build the system from scratch, rather than call an existing vector search library, exposes its capabilities in several areas:
- Requirements analysis and task decomposition: Can it break “build a vector database” into storage, indexing, retrieval, and interface components?
- Architecture design: Can it define sensible modules, abstraction boundaries, and extension points?
- Code correctness: Are similarity calculations and nearest-neighbor search implemented correctly, including edge cases?
- Engineering completeness: Does the implementation include tests, documentation, error handling, and configuration management?
- Autonomous iteration: Can the model identify and fix defects using feedback from execution?
Compared with isolated algorithm problems or code-completion tasks, this kind of end-to-end system-building exercise more closely resembles backend development. Its findings are therefore more useful when assessing models for real engineering workflows.
2. Define a Reproducible Evaluation Task
A comparable, reproducible evaluation needs clear scope and acceptance criteria. A practical task specification might include:
- Objective: Build an embedded vector database supporting vector insertion, deletion, updates, and nearest-neighbor search.
- Data scale: Support insertion and search at a scale of approximately 100,000 vectors.
- Search semantics: Support cosine similarity and inner product.
- Performance requirements: Meet quantifiable baselines for query latency and recall.
- Deliverables: A runnable service or library, unit tests, benchmark scripts, and design documentation.
Use the same seeded dataset and fixed instructions across evaluations to reduce noise from randomness. Multiple evaluation runs can also reveal how reliably a model completes the task end to end without human intervention.
3. Core Implementation Components
A vector database built from scratch typically needs the following components.
3.1 Storage and Data Model
The storage design should address three layers:
- In-memory representation: How vectors, IDs, and metadata are organized.
- Persistence: An append-only log or snapshot mechanism that allows data to be recovered after a restart.
- Deletion and updates: A strategy based on tombstones or compaction.
An illustrative interface is:
class VectorStore:def upsert(self, id: str, vector: list[float], metadata: dict | None = None) -> None: ...def delete(self, id: str) -> None: ...def search(self, query: list[float], top_k: int, metric: str = "cosine") -> list[SearchResult]: ...def flush(self) -> None: ...
3.2 Similarity Computation
Cosine similarity uses normalized vectors, while inner product uses the direct dot product. Important implementation considerations include:
- Precompute normalization for cosine similarity when inserting vectors, and normalize the query once so comparisons can use dot products without repeated normalization.
- Handle edge cases such as zero vectors.
- Use numerically stable calculations to reduce the risk of floating-point errors affecting rankings.
3.3 Index Structures
For smaller datasets, brute-force search can provide exact results with acceptable performance. As the dataset grows, an approximate nearest-neighbor (ANN) index may become necessary.
Common options include:
- Hierarchical Navigable Small World (HNSW): Offers a good balance between query performance and recall, but is more complex to build.
- Inverted File (IVF) indexing: Clusters vectors into buckets and scans only a subset during search. It is comparatively straightforward to implement.
- Product Quantization (PQ): Compresses vector storage to reduce memory use, at the cost of accuracy.
A useful evaluation question is whether the model can select an appropriate indexing strategy for the data scale and correctly manage the trade-off between recall and latency.
3.4 Concurrency and Consistency
An embedded implementation can start with a single-threaded design. If the database is exposed as a service, it also needs to consider:
- Read-write locks or concurrency-safe data structures.
- Batch write interfaces to improve throughput.
- Consistency semantics for deletion during search, including whether results may contain IDs that have already been deleted.
4. Evaluation Criteria and Evidence Collection
A complete coding-agent evaluation should score multiple dimensions and retain evidence of the implementation process:
- Completion: Does the system run end to end, and do all tests pass?
- Correctness: Does it pass carefully designed tests for edge cases, metric switching, and searches after deletion?
- Performance: How does it compare with a baseline such as exact search in recall, queries per second (QPS), and memory usage?
- Code quality: Is the code modular, readable, and supported by appropriate error handling, type annotations, and comments?
- Autonomous repair: Can the model diagnose and fix problems after test failures or runtime errors?
- Design soundness: Does the implementation avoid both unnecessary complexity and missing essential components?
Blinded review can help reduce subjective bias: assign anonymous identifiers to outputs from different models, then have reviewers score them against the same criteria without knowing their source.
Keep full execution logs as well. These make it possible to trace when a model first took an incorrect direction and how that mistake affected subsequent work.
5. Common Findings and Bottlenecks
System-level coding evaluations often reveal several recurring patterns.
5.1 The First Version Looks Complete but Contains Subtle Defects
An implementation may have a convincing structure while failing to handle zero vectors in cosine similarity, synchronize the index after updates, or remove deleted entries from search results.
These failures show why apparent completeness must be verified through targeted tests rather than inferred from the code’s organization.
5.2 Performance Optimization Is Often Overlooked
Many implementations stop at brute-force search and introduce an index only when performance requirements are explicit.
This suggests that measurable performance baselines in the task instructions can substantially influence the model’s implementation strategy.
5.3 Autonomous Debugging Ability Varies Widely
Some models can trace a failed test to a normalization error or a missing index rebuild. Others enter a cycle of repeated rewrites that makes the implementation increasingly inconsistent.
Recording both the number of repair iterations and whether the implementation ultimately converges helps distinguish these behaviors.
5.4 Documentation and Design Explanations Are Uneven
Stronger system-level outputs include architecture diagrams, descriptions of module responsibilities, and explanations of design trade-offs.
These deliverables directly affect how much effort a human developer needs to take over and maintain the system.
5.5 Context Management Is a Constraint in Long Tasks
Multi-file implementations and repeated revisions make it easy for a model to lose track of earlier decisions, such as the meaning of a similarity metric parameter. The result can be inconsistent behavior across components.
One way to mitigate this is to ask the model to define a design contract—including interface signatures and data formats—before implementation begins.
6. A Workflow for Reproducible Evaluation
To reproduce this evaluation in your own environment, use the following steps:
- Fix the task specification. Include functional requirements, performance baselines, acceptance criteria, and restrictions, such as prohibiting direct use of an existing vector search library.
- Fix the data generation script and random seed. Use consistent input data across runs.
- Build an automated scoring script. Run unit tests, benchmarks, and static checks, then produce structured results.
- Retain process logs. Record each model action, execution output, and code diff.
- Repeat the evaluation. Run each model at least three times, examine variance, and report the median or mean to reduce dependence on a single run.
- Manually review key aspects. Performance metrics alone cannot establish maintainability or architectural soundness; these still require human judgment.
7. Conclusion
Building a vector database from scratch is a practical backend task for evaluating LLM coding agents across requirements decomposition, system design, algorithm implementation, engineering practices, and autonomous debugging.
Whether the code runs is only one part of the assessment. A more useful evaluation combines correctness, performance, code quality, and autonomous repair, supported by fixed tasks, consistent datasets, automated scoring, and repeated experiments.
For developers, this approach provides both a basis for model selection and a concrete engineering framework for designing agentic coding workflows.
