Compare
Cosmos DB vs PostgreSQL vs Redis for Vector Search
30-second answer
Use Cosmos DB for NoSQL when vectors belong next to JSON app data such as chat history, with global scale and the change feed. Use PostgreSQL with pgvector when you want SQL, joins and metadata filters in the same query. Use Azure Managed Redis for in-memory speed, such as a semantic cache.
Simulate it »Side by side
↔ Swipe the table to see every column.
| Cosmos DB for NoSQL | PostgreSQL + pgvector | Azure Managed Redis | |
|---|---|---|---|
| Vector index | diskANN, quantizedFlat, flat | HNSW, IVFFlat | HNSW, FLAT (RediSearch) |
| Query | ORDER BY VectorDistance(...) | ORDER BY embedding <=> $1 | FT.SEARCH with KNN |
| Filters | WHERE on any JSON property | Any SQL WHERE, joins | Tag and numeric filters |
| Latency | Milliseconds | Milliseconds | Sub-millisecond reads |
| Best for | AI apps with operational JSON data | RAG over relational data | Semantic caching, hot data |
Prices are illustrative pay-as-you-go list prices converted at approximate rates, for "price feel" only. Check the Azure pricing calculator for real quotes.
Which one should I pick?
Cosmos DB
Pick it when chat history, user profiles and vectors should live together and scale globally
PostgreSQL + pgvector
Pick it when your data is relational and you filter on many columns
Managed Redis
Pick it when you need the fastest lookups or a cache in front of a model
Simulate it
🖱️ Drag to rotate · scroll or pinch to zoom
Vector search in Cosmos DB
A vector embedding policy tells Cosmos DB where the vectors are, their dimensions and distance function. A vector index makes search fast: diskANN or quantizedFlat for large sets, or flat for exact search on small vectors (up to 505 dimensions). Then ORDER BY VectorDistance(c.embedding, @q) returns the closest items.
🤔 What happens if…
Read this tour as text
- Text becomes a vector. An embedding model turns text into a list of numbers, a vector (1,536 numbers for
text-embedding-3-small). Texts that mean similar things get vectors that sit close together, so "refund" lands near "money back". - Cosmos DB: items, partitions, RUs. In Azure Cosmos DB for NoSQL, JSON items live in containers, spread across logical partitions by the partition key. Every operation costs Request Units (RUs). A point read by id and partition key costs about 1 RU. A query that scans every partition costs far more.
- Indexing and consistency. By default Cosmos DB indexes every property, so writes cost more RUs. An indexing policy can exclude paths you never filter on, such as the big
embeddingarray. Consistency levels trade freshness for speed and cost: Strong, Bounded staleness, Session (default), Consistent prefix, Eventual. - Vector search in Cosmos DB. A vector embedding policy tells Cosmos DB where the vectors are, their dimensions and distance function. A vector index makes search fast:
diskANNorquantizedFlatfor large sets, orflatfor exact search on small vectors (up to 505 dimensions). ThenORDER BY VectorDistance(c.embedding, @q)returns the closest items. - Change feed. The change feed is an ordered log of inserts and updates in a container (deletes only show up in the *all versions and deletes* mode). A change feed processor reads it with a lease container that remembers how far each worker got, so a new product can be embedded the moment it’s saved.
- PostgreSQL with pgvector. In Azure Database for PostgreSQL, the pgvector extension adds a
vector(1536)column type. Without an index, every search compares against every row (a sequential scan). An HNSW or IVFFlat index finds near neighbours fast, trading a little recall for a lot of speed. - RAG with a metadata filter. Retrieval-augmented generation (RAG): embed the question, fetch the closest chunks (
ORDER BY embedding <=> $1 LIMIT 5), filter by metadata such astenant_idorlang, then send those chunks to the model as context. The answer is grounded in your own data. - Azure Managed Redis. Azure Managed Redis keeps hot data in memory. Cache-aside: check Redis, and on a miss read the database and store the result with a TTL. When data changes, invalidate the key. Redis can also hold a vector index for fast similarity search, for example a semantic cache of answers.
Questions people ask
Do I need Azure AI Search for RAG?
Not always. Cosmos DB, PostgreSQL and Redis all do vector search. Azure AI Search adds hybrid ranking and skillsets when you need them.
Which distance function should I use?
Cosine is the usual choice for OpenAI embeddings. Use the same function the embedding model was designed for.