Command Palette

Search for a command to run...

Hectal
Phase 5Intermediate6 of 14 in RAG and Vector Search

Vector Databases

Store embeddings so they survive restarts, take updates, answer filtered queries and fit in memory: pgvector, other stores, sizing and a VectorStore.

Phase 3 built vector search in memory: fast to write, gone when the program stops. A real product needs more. Vectors must be saved, changed and deleted while people search, filtered by who is asking, and sized so the machine does not run out of memory. This phase is about the systems that do that, called vector stores or vector databases.

You will build a small VectorStore by hand (upsert, delete with tombstones, search with a metadata filter, compaction), so every feature of a real store has a mechanism you can point at. Then you will meet the real thing with PostgreSQL and pgvector, checked against its official documentation, and the other kinds of store, named by category and with no rankings.

The phase ends with AskDocs getting a VectorStore interface: an in-memory version that runs here, and the SQL it maps to in pgvector. Swapping stores later then touches one file.

0/10 · 0%
10 topics ~3 h 16 code blocks & diagrams
Start with the first topic
1
5.1

When a List in Memory Stops Being Enough

A list of vectors in a program searches fine until the program restarts, two people write at once, a question needs a filter, or there are millions of vectors. A vector database is the set of features that fix those, and you may not need one yet.

18 min 1 code practice

2
5.2

PostgreSQL with pgvector

pgvector adds a vector column type, three distance operators and two index types to PostgreSQL, so embeddings live in a normal table next to your other data and a search is an ordinary SQL query.

21 min 2 code practice

3
5.3

Kinds of Vector Stores

Vector stores come in four families: dedicated vector databases, search engines with vector fields, extensions to a database you already run, and embedded libraries. They differ in where the data lives and who operates it, not in what a search means.

20 min 1 code practice

4
5.4

Collections, Ids and Payloads

A collection fixes the vector length and the distance when it is created. You choose the ids, and each point can carry a small payload. The full text usually stays in your own table, found by id.

20 min 1 code practice

5
5.5

Filtering in a Vector Store

A filter such as "only this user's documents" sounds simple, but an approximate index may collect its nearest candidates first and filter afterwards, leaving too few results. Stores fix it by filtering inside the search, by searching again with a wider net, or by splitting the data.

22 min 2 code practice

6
5.6

Upserts, Deletes and Consistency

Documents change while people search. Stores handle this by appending a new row and marking the old one dead (a tombstone), clearing the dead rows later (compaction), and, when copies exist, by making a reader wait until its copy has seen the write.

21 min 2 code practice

7
5.7

Sizing and Cost

How much memory and disk a vector store needs follows from three numbers you control: how many vectors, how many numbers each has, and how many bytes a number takes. Add the index, the copies and some headroom, and you can estimate before you buy.

20 min 1 code practice

8
5.8

Choosing a Store

Choose from what you already run, how big your data is, which filters and keyword search you need and who will operate it. Put the store behind an interface so the choice can be reversed.

19 min 1 code practice

9
5.9

Build: A Store for AskDocs

AskDocs version 5 puts a VectorStore interface between the product and its vectors: upsert, delete and search with a filter. An in-memory version runs here, and a second version shows the pgvector SQL the same calls map to.

25 min 2 code practice

10
5.10

Playbook: Vector Store Recipes

Ready-to-copy recipes for any vector store: a schema and index template, a query template with parameters, the sizing function, a compaction trigger, a migration overlap check and a blue-green re-index.

23 min 3 code practice

Practise this phase

Hands-on exercises: write the code, run it, and press Check to have it tested automatically.