Your AI assistant "knows" your company handbook because something indexed every page, converted each section into vectors, and retrieves the right chunks when you ask a question. That something is often a vector database: specialized storage for embeddings optimized for nearest-neighbor search at scale. It is not a replacement for PostgreSQL or Elasticsearch, though some products add vector columns to familiar databases.
A vector database stores embedding vectors with metadata and returns the most similar vectors to a query embedding in milliseconds, even across millions of records. In AI tool stacks, vector databases power semantic search, RAG retrieval, recommendation engines, and deduplication. This guide explains the vector database role in the AI stack, how indexing and querying work, managed vs self-hosted tradeoffs, performance factors, data residency implications, and FAQ on reindexing costs. Teams building on AI research and AI API platforms should know whether retrieval runs on a vector DB or a simpler keyword index.
Vector Database Role in the AI Stack
In a typical RAG pipeline, documents flow through chunking, embedding, and indexing into a vector database. At query time the user's question is embedded, similar chunks are retrieved, and those chunks are injected into the LLM prompt. The vector database is the retrieval layer; the LLM is the generation layer. Neither replaces the other.
Vector databases also appear outside RAG: e-commerce similarity search, fraud pattern matching, semantic code search, and clustering customer feedback. Any feature described as "find similar" or "semantic match" likely depends on vector storage underneath, whether branded as a vector DB or implemented as pgvector inside PostgreSQL.
How Indexing and Querying Work
Exact nearest-neighbor search across millions of high-dimensional vectors is too slow for real-time queries. Vector databases use approximate nearest neighbor (ANN) indexes that trade a small amount of recall for large speed gains.
Common ANN approaches
- HNSW (Hierarchical Navigable Small World): Graph-based index; popular default for many hosted vector DBs.
- IVF (Inverted File Index): Clusters vectors into buckets; searches relevant buckets first.
- Product quantization: Compresses vectors to reduce memory; useful at very large scale.
A query embeds the user text, the index returns top-k vector IDs with similarity scores, and the application maps IDs back to original text chunks using stored metadata (file name, page number, last updated timestamp). Hybrid systems run vector search and BM25 keyword search in parallel, then merge rankings with reciprocal rank fusion for better recall on SKUs and proper nouns.
| Concept | Definition | Why it matters |
|---|---|---|
| Collection / namespace | Logical partition of vectors | Isolate tenants, environments, or document types |
| Dimension | Length of each embedding vector | Must match embedding model output exactly |
| Metadata filter | Pre-filter by date, department, product line | Narrows search before similarity ranking |
| Top-k | Number of nearest neighbors returned | Feeds RAG context size and answer quality |
Managed vs Self-Hosted Implications
Managed vector databases (Pinecone, Weaviate Cloud, Zilliz, etc.) offer fast setup, autoscaling, and operational SLAs. Self-hosted options (pgvector, Qdrant, Milvus, Chroma on your infrastructure) trade ops burden for data control and potentially lower cost at steady high volume.
- Managed: Faster time to production; per-query or per-storage pricing; vendor handles index tuning.
- Self-hosted: You manage backups, upgrades, and capacity planning; better for strict data residency.
- Embedded: Lightweight local stores (FAISS files, Chroma embedded) suit prototypes; scale limits hit quickly.
Performance Factors: Dimension, Scale, and Freshness
Retrieval latency grows with index size, vector dimension, filter complexity, and chosen recall settings. Stale indexes produce wrong answers even when search is fast. Plan reindex jobs when source documents change, not only when the database slows down.
| Factor | Effect on system | Tuning lever |
|---|---|---|
| Vector count | More vectors increase search time and storage | Chunking strategy, archival of old content |
| Embedding dimensions | Higher dims improve quality but cost memory | Choose model matched to task, not max dims |
| Index freshness | Stale chunks cause outdated RAG answers | Incremental upserts, scheduled full reindex |
| Top-k size | Large k inflates LLM context and cost | Rerank to fewer chunks before generation |
Data Residency and Deletion in Vector Stores
Vectors are derived from your source documents. GDPR and similar regimes may treat them as personal data if source text contained PII. Deleting a document in your CMS does not automatically delete its vectors unless your pipeline handles tombstoning or reindex-on-delete.
- Map vector IDs to source records for auditable deletion.
- Confirm managed vendor region matches your compliance requirements.
- Encrypt vectors at rest if policy requires protection of derived data.
- Test "right to be forgotten" flows end to end, not only in the primary database.
Frequently Asked Questions
How is a vector database different from traditional search?
Keyword search (BM25, inverted indexes) matches tokens. Vector databases match meaning via embedding similarity. Hybrid systems combine both because each fails on different query types.
What does reindexing cost?
Reindexing re-embeds all chunks and rebuilds indexes. Cost is embedding API charges plus compute time plus temporary storage. Switching embedding models always requires full reindex. Changing chunk size usually does too.
Is pgvector enough or do I need a dedicated vector DB?
pgvector works well up to moderate scale with strong PostgreSQL ops skills. Dedicated vector DBs target higher QPS, billion-vector scale, and ANN tuning features. Prototype on pgvector; migrate when latency or scale SLOs break.
How do I know if my AI tool uses a vector database?
Look for semantic search, "chat with your documents," or RAG in feature lists. Ask the vendor directly: which store, which embedding model, update frequency, and whether you can export or delete vectors.
Can I use a vector database without RAG?
Yes. Similarity search, recommendations, and clustering do not require an LLM. RAG is one popular application, not the only one.
The Bottom Line
Vector databases store embeddings and retrieve similar content fast enough for real-time AI features. They anchor the retrieval layer in most RAG stacks. Choose managed vs self-hosted based on scale, residency, and ops capacity. Keep indexes fresh, match embedding models across index and query, and plan deletion with compliance in mind. Explore AI research and AI API tools on EliteAI.tools and ask how each product handles semantic retrieval under the hood.