Develop AI Solutions with Azure Data Management Services · Topic 3 of 3
Azure Managed Redis in AI Solutions
AI-200 Azure Managed Redis: caching patterns, expiration and invalidation, caching AI responses, and vector indexes for fast similarity search.
- 4 min
- Azure Managed Redis is an in-memory store for caching and fast vector search.
- Cache-aside: check cache, read source on a miss, store with a TTL.
- Invalidate or update cached keys when the source data changes.
What it is
Azure Managed Redis is a fully managed, in-memory data store based on Redis. AI solutions use it to cache expensive results, such as database queries or model responses, and to run vector similarity search with very low latency.
How it works
Data operations
| Operation | Purpose |
|---|---|
| SET and GET | Store and read a value by key |
| Expiration (TTL) | Set a time to live so a key is removed automatically, for example SET with an EX value in seconds, or EXPIRE |
| DEL | Delete a key, used for invalidation |
| Hashes and JSON | Store structured values such as a user profile or a document with fields (JSON uses the RedisJSON module) |
Choose clear key names, such as product:123, so related keys are easy to find and invalidate.
Caching patterns
| Pattern | How it works |
|---|---|
| Cache-aside | The app checks the cache; on a miss it reads the database, then writes the result to the cache with a TTL |
| Write-through | The app writes to the cache and the database together |
| Invalidation on write | When data changes, delete or update the cached key so readers do not get stale data |
Caching model responses or embeddings for repeated inputs saves cost and time. A semantic cache goes further: it stores a response with the embedding of its prompt and returns it for new prompts that are similar enough.
Expiration and eviction
- A TTL limits how stale cached data can become.
- When memory is full, an eviction policy decides which keys to remove. The default, volatile-lru, removes the least recently used keys among those with a TTL, so keys without a TTL are not evicted.
- Pick TTLs by how quickly the source data changes and how much staleness is acceptable.
Vector indexing and search
With the RediSearch module, Azure Managed Redis supports search indexes over hashes or JSON documents, including vector fields. RediSearch must be enabled when the cache is created, needs the Enterprise clustering policy and the NoEviction eviction policy, and isn't available on the Flash Optimized tier.
- Create an index that defines a vector field with its algorithm (FLAT for exact or HNSW for approximate), dimensions and distance metric (L2, COSINE or IP).
- Store documents with their embeddings.
- Run a KNN query to get the nearest vectors, optionally combined with filters on other fields.
Redis vector search is fast because data is in memory, which suits low-latency lookups such as semantic caching or recommendation, while larger corpora often live in a database or search service.
A worked example: a chatbot receives many near-identical questions. The app embeds each question, searches a Redis vector index for a cached question above a similarity threshold, and returns the cached answer; on a miss it calls the model and caches the new answer with a 24-hour TTL.
"Users see outdated prices after an update" in a caching question points to invalidating or updating the cached key when the data changes, or a shorter TTL.
How the exam asks about this
- "Return frequent results quickly without hitting the database each time." Cache-aside with a TTL.
- "Cached values must expire after 10 minutes." Set a TTL of 600 seconds.
- "Return a stored answer for questions that mean the same thing." A semantic cache with a vector index.
What to remember for the exam
- Azure Managed Redis is an in-memory store for caching and fast vector search.
- Cache-aside: check cache, read source on a miss, store with a TTL.
- Invalidate or update cached keys when the source data changes.
- Eviction policies decide what to remove when memory is full.
- Vector indexes define algorithm (FLAT or HNSW), dimensions and distance metric; query with KNN.
Caching without a TTL or invalidation plan leads to stale data that never refreshes.
Common mistakes
Caching data that changes every request. It adds cost without benefit.
Forgetting to invalidate on updates. Readers get stale values.
Treating Redis as the only copy of important data. Keep the source of truth in a durable database.
Check yourself
What is the cache-aside pattern?
The app checks the cache first; on a miss it reads the source, returns the data and stores it in the cache with a TTL.
What does a TTL do?
It sets how long a key lives before Redis removes it automatically.
What does a semantic cache use to match prompts?
The embeddings of prompts, returning a cached answer when a new prompt is similar enough.
Topic 3 of 3 in Develop AI Solutions with Azure Data Management Services
Test yourself on Develop AI Solutions with Azure Data Management Services
The full Microsoft AI-200 question bank has 650 questions, with timed practice exams and an explanation for every answer.
This study guide is independent and is not affiliated with, endorsed by, or sponsored by Microsoft. Vendor names, certification names and exam codes are trademarks of their respective owners and are used for identification only.