SproutStackSproutStack home

Vector Databases in 10 Minutes

6 min readBeginner-friendlyFree to read

Read a little, play a little. No scary maths, and no rush.

Share:

A library that finds by meaning

A normal database finds rows by exact match: WHERE id = 42. A vector database finds chunks by meaning: "which passages are closest to this question?" It stores each chunk's embedding (a long list of numbers) plus the text and metadata, then answers nearest-neighbor queries in milliseconds — the engine room of every RAG system.

How "closest" stays fast at millions of vectors

Comparing against every vector is O(n) and hopeless at scale. HNSW (the standard algorithm) builds a layered graph of shortcuts: search descends from sparse top layers to dense bottom ones, skipping huge regions without looking. Result: approximate nearest neighbors — 99% as good as exact, hundreds of times faster. For RAG, approximate is plenty; the LLM smooths over the rest.

What you actually store and ask

Each record: vector + text + metadata like {source, date, tenant}. Each query: filter first (tenant = acme), then rank the survivors by similarity, take top-K (usually 3–10). Filters before ranking matter enormously — without tenant filtering, one customer retrieves another's private docs.

results = collection.query(
    query_texts=["return policy?"],
    where={"tenant": "acme"},   # filter first…
    n_results=4,                # …then rank
)

A worked example: a help center

A company has 2,000 help articles in three languages. Split into chunks, that is about 15,000 records, each storing the vector, the chunk text, and metadata: article_id, product, locale, and updated.

A user on the mobile app asks, in English, "how do I reset my password?" The query filters to locale = en and product = mobile, then ranks the remaining chunks and returns the top five. Without the filters, a desktop article or a Spanish one might rank first, correct in meaning but wrong for this user.

When an article is edited, the old chunks are deleted by article_id and the new ones inserted. Skip the delete step and the index ends up holding both versions, so searches can return outdated instructions alongside the current ones. That is why every chunk should carry the ID of the document it came from.

How approximate is approximate?

Approximate search occasionally misses a true nearest neighbor. The share of true top results it does find is called recall. Indexes like HNSW have settings that trade speed for recall: search a little wider and recall rises, at the cost of a slower query. To check yours, take a sample of queries, run them both exactly (brute force) and through the index, and compare the top results. If recall is high on your data, the speed is free.

You may not need one yet

For a few thousand vectors, a plain array in memory searched by brute force answers in milliseconds, and there is nothing to deploy. If you already run Postgres, the pgvector extension adds vector search to the database you have. A dedicated vector database earns its place when the collection grows large, queries are heavy, or you need its filtering and operations features.

Which one, and the update story

Start with Chroma (embedded, zero ops) or pgvector (already have Postgres?). Scale to Qdrant or Pinecone when millions of vectors or uptime SLAs arrive — see our vector-DB showdown. And updates are surgical: when a document changes, re-embed only its chunks and upsert them. Never rebuild the world.

Remember this

  • Store vector + text + metadata; filter, then rank, then take top-K.
  • HNSW = fast approximate search; good enough is the whole point.

Check your understanding

5 questions · first-try answers earn the most XP

1. A brute-force vector search compares your query against every stored vector, costing O(n). What is the usual reason this becomes a problem?
2. You store a document's embedding and later edit the document. What must you do?
3. What does a metadata filter do during a vector search?
4. Two documents have nearly identical embeddings, but only one is relevant. Why?
5. Which statement about vector databases is actually true?

My notes

Saved in this browser. Highlight a line above and save it, or write it in your own words.

Nothing saved yet. Your highlights will live here.

References

Finished reading?

Ticking it here also ticks the chapter in the sidebar, the section count and your streak — it is all one number.

Practice this in an incident

Related chapters

Spotted a mistake or want a topic covered? Report an issue

📬 An occasional email when new lessons land

New lessons and showdowns, no more than a few times a month. No spam, unsubscribe anytime. We store your email only to send the newsletter.