Building a Vector Database from Scratch: Testing and Insights into AI Coding Agents
This article evaluates the practical coding capabilities of large language models (LLMs) in a backend agentic coding scenario by asking them to implement a vector database from scratch. It outlines the test design, evaluation dimensions, observed strengths, and critical weaknesses—such as shallow algorithm understanding, state loss in long tasks, and poor performance awareness. The article also discusses how to build verifiable task loops and task decomposition for reliable AI-assisted engineering, and concludes that human architects are still essential for high-level decisions and validation.
Building a Vector Database from Scratch: Testing and Insights into AI Coding Agents
Why Test with a Vector Database
With the rise of retrieval-augmented generation (RAG), semantic search, and similar technologies, vector databases have become a common component in backend systems. A vector database involves multiple core backend domains—data structure design, indexing algorithms, persistent storage, concurrency control, and API wrapping—making it a compact but full-featured engineering target.
Using this as a testing task for intelligent coding offers several natural advantages:
- Clear objectives: The requirement can be described in a few sentences—support vector insertion, similarity search, persistence, and other basic capabilities.
- Quantifiable validation: Recall rate, query latency, and data consistency can be objectively measured via test scripts, avoiding vague assessments like “looks correct but doesn’t run.”
- Controllable difficulty gradient: From brute-force scanning to approximate nearest neighbor (ANN) search, then to disk-based indexing and concurrency safety, the difficulty can be increased layer by layer, making it easy to observe model behavior under varying complexity.
This article only shares personal test conclusions for the single scenario of “backend agentic coding.” It does not generalize to frontend, data analysis, or other task types.
Test Methodology and Evaluation Dimensions
Task Setup
All tests used a unified prompt, requiring the model to autonomously complete the following as an agent:
- Design the overall architecture of the vector database (storage layer, index layer, query layer, interface layer).
- Implement core functionality from scratch, without relying on existing vector search libraries.
- Write unit tests and benchmark tests to verify correctness and performance.
- Iteratively fix issues discovered during testing.
Evaluation Dimensions
| Dimension | Description |
|---|---|
| Architecture soundness | Whether module division is clear and responsibilities are single-purpose |
| Code correctness | Whether functionality passes tests and edge cases are handled |
| Algorithm selection | Whether the model understands the trade-offs between brute-force and ANN |
| Autonomous iteration ability | Whether it can locate and fix errors independently when failures occur |
| Engineering completeness | Logging, configuration, documentation, test coverage |
Observed Results and Typical Issues
What Worked Well
On the architecture design front, mainstream LLMs generally produced sensible layered designs, for example:
project/├── storage/ # Persistence layer: segment files, write-ahead log├── index/ # Index layer: flat index / hierarchical graph index├── query/ # Query layer: distance computation, filtering, Top-K├── api/ # Interface layer: HTTP/gRPC wrappers└── tests/ # Unit and benchmark tests
For basic functionality, core logic such as insertion, cosine similarity calculation, and Top-K retrieval had a high correctness rate, indicating the models’ solid grasp of common algorithmic patterns.
Core Shortcomings Revealed
First, insufficient algorithmic depth. Models tended to choose the easiest flat-scan approach. When explicitly asked to implement approximate nearest neighbor search, they often made critical detail errors—for example, incorrect neighbor pruning logic in graph index construction, or improperly set probabilistic parameters for multi-level skip lists. These errors do not cause crashes but significantly degrade recall, representing “silent failures” that only dedicated benchmark tests can expose.
Second, state loss during long tasks. Across multiple iterations, the agent sometimes forgot earlier design decisions, rewrote the same module with two conflicting styles, or reopened already-solved problems. This suggests that in real engineering, external memory (such as design documents, task checklists) must be used to constrain agent behavior.
Third, weak performance awareness. Generated code was often correct but inefficient: frequent memory copies, rebuilding temporary structures on every query, overly coarse lock granularity, etc. For database-like systems, the cost of these issues scales with data volume.
A Typical Iterative Fix Cycle
When benchmark tests revealed abnormal recall, the better-performing agents followed a debugging loop similar to this:
# Validate distance computation with known dataassert cosine([1, 0], [1, 0]) == 1.0assert cosine([1, 0], [0, 1]) == 0.0# Compare against brute-force results to locate index-level errorsbruteforce_topk = linear_search(query, vectors, k)index_topk = ann_search(query, k)recall = overlap(bruteforce_topk, index_topk) / k
An agent that independently reaches the step of “building a controlled comparison experiment” clearly has stronger debugging skills than one that repeatedly modifies code without understanding the root cause. This difference is a useful observation point for evaluating the quality of coding agents.
Implications for Engineering Practice
Build Verifiable Task Loops to Drive Agents
Simply asking the model to “write code” is limited. A more effective approach is to establish an automated loop of “implement → test → feedback → fix.” The more objective the test scripts and benchmark data, the more reliable the agent’s self-correction.
Decompose Complex Systems into Subtasks
Implementing a database from scratch is a long-horizon task. Handing it to an agent as a single monolithic prompt can easily lead to loss of control. A reasonable method is to break the work into independently verifiable subtasks (e.g., persistence first, then indexing, then concurrency), locking down milestones at each stage.
Humans Still Own Architecture and Acceptance
The most reliable capability of current agents is “efficiently implementing local functionality within clearly defined specifications.” Global architecture decisions, performance trade-offs, and correctness validation still require engineering oversight. Treating the agent as a capable junior engineer that needs explicit instructions is the most pragmatic positioning at this stage.
Conclusion
This test can be summarized in one sentence: In the backend agentic coding scenario, large language models are already capable of handling medium-complexity engineering tasks with clear structure and solid validation, but they still show significant gaps in algorithmic depth, long-range consistency, and performance optimization. For teams, the focus should not be on “whether AI can replace humans,” but on quickly building verifiable task loops and decomposition practices to maximize the value of AI-assisted programming within a controlled scope. As model reasoning and tool-calling capabilities continue to evolve, the quality of such “build from scratch” tasks will serve as a direct, observable measure of technological progress.
