Do you need Supabase? Storing vectors yourself
The question#
After building the RAG, a natural question came up: "So the embeddings are stored on our own server. We don't need to pay for Supabase or another vector database?"
For our size, correct. And understanding why teaches one of the most useful habits in engineering: buy infrastructure to solve a problem you actually have, not one you might have one day.
First, separate two jobs#
| Job | Needs AI? | What we use |
|---|---|---|
| Making embeddings (text → 1,536 numbers) | Yes, a model | OpenAI text-embedding-3-small |
| Storing and searching them | No | A JSON file on our server |
People often blur these together. A "vector database" only does the second job.
An embedding is just data
1,536 numbers. You can store them anywhere: a JSON file, a spreadsheet, a normal database, even inside an HTML file in a browser (we did exactly that for the offline knowledge file in lesson 07). Packed as 4-byte floats, each passage's vector is about 6 KB.
How search works without a vector database#
Brute-force (exact) search: compare the question with every passage.
- 1,000 passages × 1,536 numbers ≈ 1.5 million multiplications: milliseconds.
- It is 100% accurate: nothing is skipped.
- Cost grows linearly: 10× the passages, about 10× the time and memory.
What vector databases add#
Supabase is really PostgreSQL + the pgvector extension. Pinecone, Qdrant and Weaviate are others. Their key trick is an approximate nearest neighbour (ANN) index, for example HNSW (a layered graph you can "hop" through towards the closest vectors without checking them all).
| Need | Flat file (ours) | Vector database |
|---|---|---|
| Size | A few thousand passages per base | Millions |
| Speed at scale | Slows linearly | ANN index stays fast |
| Memory | Loads the whole file per question | Reads only what it needs |
| Many users writing at once | Basic | Built for it |
| Filtering ("only this client's docs") | Write it yourself | Built-in queries |
| Accuracy | Exact | Very slightly approximate |
| Cost / setup | Free on existing hosting | Account, schema, keys, often a monthly fee |
The real trade-off
ANN gives up a tiny bit of accuracy (it can occasionally miss the true best match) in exchange for huge speed on huge collections. Below a few thousand items, that trade buys you nothing.
A rule of thumb#
- Up to roughly 5–10 thousand passages: a flat file is fine. That covers most FAQs, policies, courses and product catalogues.
- Tens of thousands to around a million: a database with vector support: SQLite/Postgres with a vector extension, a library like FAISS, or MariaDB 11.7+, which has built-in vector search. (Our hosting's database turned out to be MariaDB 11.8, so this option is already sitting there, unused.)
- Millions, many customers, live updates: a managed vector database earns its fee.
Can we drop the third party for making embeddings too?#
Yes. Open-source embedding models (the sentence-transformers family) run on your own computer or server. The trade-off is speed and quality on small hardware, and the effort to run them. For us, paying fractions of a cent to OpenAI was simpler.
Key takeaways#
- Making embeddings needs a model; storing them does not need special infrastructure.
- Brute-force search is exact and fast enough for thousands of items.
- Vector databases solve scale problems (speed, memory, concurrency, filtering), not possibility problems.
- Pick tools for the problem you have now, and design so you can upgrade later.
Quick quiz#
1. What is Supabase's vector search built on?
PostgreSQL with the pgvector extension.
2. Why might an ANN index return a slightly worse match than brute force?
It deliberately checks only part of the collection to be fast, so very occasionally it skips the true best match.
3. Your knowledge base has 2,000 passages. Do you need a vector database?
No. Exact search over 2,000 vectors takes milliseconds and is perfectly accurate.
Try it yourself#
Estimate your own size
Take a document you'd like an assistant for. Count its characters (most editors show this), divide by about 650 (an 800-character passage minus overlap) and you have roughly how many passages it becomes. How far is that from 5,000?