Lesson 04.05 · Phase 04 · Memory & Context Engineering
A vector store in 80 lines
A vector store is a dictionary with a nearest-neighbour search on top. Write the 80 lines once, and every database feature after that is an optimisation you can judge.
Learning objectives
- Implement a vector store with upsert, delete, top-k cosine search, metadata filters, a score threshold, and save/load, in under 80 lines.
- Explain why vectors are normalised once at write time, and why a store must refuse vectors from a different embedding model.
- Split long text into overlapping chunks before embedding it.
- Measure when brute-force search becomes too slow, and what approximate indexes trade for speed.
Lesson 4 compared a query against six documents in a loop. An agent's memory is that loop with more requirements:
Loading the full lesson…