Your profile

One profile for every MSDEVBUILD site. Only you can see it, and the site owner if you write in.

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 NoSQLPostgreSQL + pgvectorAzure Managed Redis
Vector indexdiskANN, quantizedFlat, flatHNSW, IVFFlatHNSW, FLAT (RediSearch)
QueryORDER BY VectorDistance(...)ORDER BY embedding <=> $1FT.SEARCH with KNN
FiltersWHERE on any JSON propertyAny SQL WHERE, joinsTag and numeric filters
LatencyMillisecondsMillisecondsSub-millisecond reads
Best forAI apps with operational JSON dataRAG over relational dataSemantic 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

3D Data for AI apps: Cosmos DB, PostgreSQL and Redis Run a vector search, then compare it with pgvector and Redis.

🖱️ Drag to rotate · scroll or pinch to zoom

Loading the 3D scene…
</> Embed

Embed this simulation

Free for trainers, teachers and bloggers. Paste this into your page:

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.

Read this tour as text
  1. 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".
  2. 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.
  3. 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 embedding array. Consistency levels trade freshness for speed and cost: Strong, Bounded staleness, Session (default), Consistent prefix, Eventual.
  4. 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.
  5. 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.
  6. 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.
  7. 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 as tenant_id or lang, then send those chunks to the model as context. The answer is grounded in your own data.
  8. 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.

Learn each one properly

More comparisons

Install MSDEVBUILD Azure

Free · no account · works offline

Save the whole course for offline ›

Hi, I’m your Nimbus

Your study buddy. Pick what we do next.

MSDEVBUILD · Multi-Stack Dev Build

Sign in to MSDEVBUILD

One account for Azure certifications and the blog: sign in here and you are signed in on both. Your XP, streak, practice deck and certificate stay in sync on every device. Optional: everything works without an account.