---
title: "Vector Database for RAG: Do You Need One? (2026 Guide)"
description: "What a vector database does in RAG, when a NumPy array is enough (we timed 100,000 vectors at 12.6 ms), when pgvector beats a new system, when web search replaces the index, and when a dedicated vector database is worth it."
category: "guides"
url: https://keirolabs.cloud/blog/vector-database-for-rag
published: 2026-11-24
updated: 2026-11-24
---

# Vector database for RAG: when you need one, and when you don't

## The 60-second version

**A vector database stores embeddings of your text and finds the passages closest in meaning to a question.** In RAG, it's the retriever for knowledge the model doesn't have. But you need one less often than tutorials suggest:

| Your situation | What to use |
|---|---|
| Under ~100,000 chunks, data changes rarely | **A NumPy array in memory.** We measured 12.6 ms per search over 100,000 vectors on a laptop CPU |
| Already run Postgres | **pgvector,** an extension, so no new system |
| Millions of chunks, many writers, filtering, multi-tenant | **A dedicated vector database** |
| Public, fast-changing facts (prices, releases, news, docs) | **No vector database: use a web search API** |
| Private docs *and* current public facts | **Both:** vector store for private, web search for public |

**The question isn't "which vector database?" but "what knowledge does my RAG need, and where does it already live?"**

## What does a vector database do in RAG?

**It turns retrieval into a nearest-neighbor search.** The pipeline:

1. **Chunk** your documents into passages of a few hundred tokens ([chunking strategies for RAG](/blog/chunking-strategies-rag)).
2. **Embed** each chunk into a vector with an embedding model.
3. **Store** the vectors with their text and metadata.
4. **At question time,** embed the question and find the chunks whose vectors are closest (usually by cosine similarity).
5. **Put those chunks in the prompt** and let the model answer from them.

**A vector database handles steps 3 and 4 at scale:** approximate nearest-neighbor indexes (like HNSW) so search stays fast over millions of vectors, plus metadata filters, updates, deletes and access control.

## Do you need a vector database for RAG?

**Often not.** Three cases where you can skip it:

### 1. Your corpus is small: use an array

**Brute-force search over a few hundred thousand vectors is fast enough for most apps.** This is the whole "vector database" for a small corpus:

```python
import numpy as np

def build_index(vectors) -> np.ndarray:
    m = np.asarray(vectors, dtype=np.float32)
    return m / np.linalg.norm(m, axis=1, keepdims=True)      # normalize once, so dot product = cosine

def top_k(index: np.ndarray, query_vec, k: int = 5) -> list[tuple[int, float]]:
    q = np.asarray(query_vec, dtype=np.float32)
    scores = index @ (q / np.linalg.norm(q))
    k = min(k, len(scores))
    best = np.argpartition(-scores, k - 1)[:k]                 # top k without sorting everything
    return [(int(i), float(scores[i])) for i in best[np.argsort(-scores[best])]]
```

**We timed it** on an AMD Ryzen 7 7735HS laptop CPU, with 768-dimension float32 vectors:

| Vectors | Search time (top 5) | Memory |
|---|---|---|
| 10,000 | 5.3 ms | 0.03 GB |
| 100,000 | 12.6 ms | 0.31 GB |
| 1,000,000 | 149 ms | 3.07 GB |

**Exact search, no index to tune, results identical to a perfect index.** Save the array with `np.save` and load it at startup. The ceiling is memory and latency past about a million vectors; that's when an approximate index earns its complexity.

### 2. The knowledge is public and changes: use web search

**If users ask about prices, releases, regulations, competitors or news, a vector index is out of date the day you build it.** A web search API is a retriever that someone else keeps current, across the whole web:

```python
import os, requests

def retrieve(question: str, n: int = 6) -> list[dict]:
    r = requests.post("https://api.keirolabs.cloud/api/v2/search/lite",
                      headers={"Authorization": f"Bearer {os.environ['KEIRO_API_KEY']}"},
                      json={"query": question, "count": n}, timeout=30)
    r.raise_for_status()
    return r.json()["results"]          # title, url, snippet: ready for the prompt
```

**No chunking, no embeddings, no re-indexing.** There's a full chatbot built this way in [RAG chatbot with web search](/blog/rag-chatbot-web-search).

### 3. You already run Postgres: use pgvector

**pgvector adds a vector column type and similarity search to Postgres,** so your vectors live next to the rows they describe, with the same backups, permissions and transactions:

```sql
CREATE EXTENSION IF NOT EXISTS vector;
CREATE TABLE chunks (id bigserial PRIMARY KEY, doc_id bigint, content text, embedding vector(768));
CREATE INDEX ON chunks USING hnsw (embedding vector_cosine_ops);

-- $1 is the question's embedding
SELECT content FROM chunks ORDER BY embedding <=> $1 LIMIT 5;
```

`<=>` is cosine distance. **Filtering by tenant or document is a normal `WHERE` clause,** which is where many dedicated databases get awkward.

## When do you need a dedicated vector database?

**When the vector store becomes its own scaling problem:**

- **Many millions of vectors,** beyond comfortable memory for brute force or a single Postgres instance.
- **High write rates:** content changing constantly, with many concurrent writers.
- **Heavy filtered search** across many tenants with strict isolation.
- **Built-in hybrid search** (vectors plus keyword) and reranking managed for you.
- **Operational needs:** replication, sharding, managed hosting.

**How to choose between them:** test on your own data and queries. Measure recall (does the right chunk land in the top 5?), latency at your real size, filter behavior, and cost at your write rate. Vendor benchmarks rarely match your workload.

## Vector search alone misses things

**Embeddings match meaning, not exact terms.** They struggle with product codes, error messages, names and version numbers, exactly the things users paste into a chatbot. Two fixes that matter more than which database you pick:

- **Hybrid search:** combine vector results with BM25 keyword results using reciprocal rank fusion ([BM25, hybrid search and RRF](/blog/bm25-hybrid-search-reciprocal-rank-fusion)).
- **Reranking:** retrieve 30 to 50 candidates, then rerank them with a cross-encoder or LLM ([reranking search results](/blog/reranking-search-results)).
- **Better queries:** rewrite questions before embedding them, or embed a hypothetical answer (HyDE) ([query rewriting and HyDE](/blog/query-rewriting-hyde)).

## The common production setup: both

**Most serious RAG systems end up with two retrievers:**

- **A vector store** (or pgvector) for private knowledge: internal docs, tickets, contracts, product data.
- **A web search API** for public, changing knowledge.

**Route between them, or query both and merge with RRF.** A simple router: questions about "our", "my account", internal names go to the vector store; questions about the outside world or anything recent go to web search; ambiguous ones go to both ([when should an AI agent search the web?](/blog/when-should-ai-agent-search-the-web)).

## Checklist

- **List what your RAG must know, and where it lives today.**
- **Under ~100k chunks: start with an in-memory array.**
- **Already on Postgres: pgvector before a new system.**
- **Public or fast-changing facts: web search, not an index.**
- **Add hybrid search and reranking before switching databases.**
- **Measure recall on your own questions before and after every change.**

For the public half of your RAG, Keirolabs `/search/lite` returns title, URL and snippet for $0.03 to $0.10 per 1,000 searches on plans, and `/search/content` adds each page's main text, with optional embedding-ready chunks. New accounts get up to 2,000 free credits with no card ([get a key](https://platform.keirolabs.cloud/register)).
