RAG and vector searchLoading progress…

Updates and deletes

Design a retrieval record and explain filtering, indexing, partitioning, updates and consistency.

Updates and deletes

Most vector indexes are much better at adding than removing. A delete usually writes a tombstone that search must skip, and cleanup (compaction) happens later. A re-embedding of a changed document writes new vectors and retires the old ones. Without a complete update path, a deleted document can remain searchable because its vector is still in the index.

Six chunks in an index. Click a chunk to delete it (it becomes a tombstone). Compaction physically removes tombstones.

entries stored: 6 live: 6 dead: 0 dead fraction 0 search ignores tombstones; until compaction they still take space and can slow scans re-embedding a document = write the new vectors + retire the old ones (8 + 8 = 16 operations for 8 chunks)

If the update path misses the index, a removed document can stay searchable: its text is gone but its vector still matches. Define when deletes become visible and when cleanup runs.

Delete chunks, then compact.

Predict first. Can a removed document remain in a stale search index?

Chapter context

A vector index solves similarity lookup; a retrieval application also needs durable records, metadata, permissions and updates. Database behavior determines which vectors are eligible and which version of a document an answer uses.

Chapter reference: math, worked example & code

This section belongs to the whole chapter, so it is the same on every lesson in it and may cover a different lesson's topic. The code for the experiment you just ran is inside the experiment itself.

Math and notation

Raw vector storage is M=NdbM=Ndb for N vectors of dimension d and b bytes per coordinate. If a postfilter independently accepts fraction f of an initial k candidates, the expected survivor count is kf; this is an expectation, not a guarantee.

Worked example

Ten million vectors of dimension 768 in float32 require 10,000,000×768×4=30,720,000,000 bytes, or 30.72 decimal GB, before IDs, text, indexes and replicas. If a postfilter accepts 20% of ten candidates under a simplifying independence assumption, the expected survivor count is only two.

Reference code

The following example uses the Python standard library and does not call a remote service.

from math import isclose
bytes_used=10_000_000*768*4
assert bytes_used == 30_720_000_000
assert isclose(bytes_used/1_000_000_000,30.72)
assert 10*.2 == 2

Python examples are provided for study and local execution; this page does not execute Python.

Common mistakes

Filter selectivity and ANN candidate recall interact. Replication adds storage. Matching vector dimension does not establish matching embedding space.