Chapter 61 · Amazon Elasticache
Subchapter 61.10
references/genai/instructions.mdMarkdown10 KBView on GitHub
When to use: The user wants to implement semantic caching, conversational memory, RAG, vector search, recommendation engines, or any GenAI/LLM pattern with ElastiCache. Also useful when the user asks about caching LLM responses (exact or semantic match). The user is working on traditional caching patterns (session store, leaderboard, rate limiting), general setup, monitoring, or migration without a GenAI component.
Read this file first. Load files listed below on demand based on the routing decision.
| File | Load when |
|---|---|
elasticache-search.md | Any pattern needing vector search (Mode 2 server-side or Mode 3). Contains platform gate, version detection, limits, encoding, backfill, AND a Python-side cosine fallback for when FT.* is unavailable. ALWAYS load this file before generating vector code so the version guard and fallback are included. |
semantic-cache.md | User wants semantic caching for LLM/API responses. Step-by-step: FT.CREATE, embed, FT.SEARCH, threshold, store. |
session-store.md | User wants session state, message history, resumable conversations, or Strands session management. Plain data structures, serverless OK. |
agent-memory.md | User wants semantic agent memory, cross-session recall via similarity, or mem0 integration. Requires node-based Valkey 8.2 or above (recommend 9.0). |
rag-retrieval.md | User wants RAG, knowledge base retrieval, or document search. Step-by-step: schema, index, ingest, hybrid query. |
framework-guide.md | User mentions a specific framework (Strands, mem0, LangChain) or asks how to connect their AI app. |
embedding-providers.md | User needs to choose or configure an embedding provider. Bedrock Titan v2 preferred, open-source fallback (fastembed, sentence-transformers). |
Before starting, read .elasticache/requirements.json if it exists. If the genai section is set (mode, mode_2_path, framework), use those values instead of re-asking. If infrastructure.embedding_module is set and the file exists, import from it.
Before recommending a pattern, classify the user’s need into one of these three modes. Many teams asking for “RAG cache” actually need semantic response reuse (Mode 2), not full vector search (Mode 3). Ask a clarifying question before jumping to the heaviest option.
Standard caching of LLM or API responses by exact key match. No vector index needed.
When to use: the user wants to avoid repeated identical LLM calls. Responses are looked up by an exact key (prompt hash, request fingerprint, or deterministic cache key).
Deployment: serverless Valkey. This is just regular SET/GET. Route to data-modeling sub-skill for key schema and TTL guidance.
Cache LLM responses with semantic similarity matching so “nearly identical” prompts return a cached response.
When to use: the user wants fuzzy cache hits, where semantically close prompts share a cached response.
Two implementation paths:
Ask the user which approach they prefer. Default to application-side unless they have high query volume AND confirmed Valkey 8.2 or above node-based. If the user’s Valkey version is < 8.2, application-side is the ONLY option. Always load elasticache-search.md and use the supports_ft_search() version check before generating any FT.* code.
Deployment: serverless Valkey for application-side; node-based Valkey 8.2 or above (recommend 9.0) for server-side.
Load: semantic-cache.md, elasticache-search.md (if server-side), embedding-providers.md
Vector indexing, KNN/ANN queries, RAG retrieval, recommendation via embeddings, agent memory with vector recall, or any workload that requires Valkey to maintain and query a vector index.
When to use: the user needs to store many embeddings and retrieve the top-K most similar. Typical for RAG knowledge bases, agent memory, recommendation engines, semantic search, catalog search.
Deployment: node-based Valkey 8.2 or above (mandatory; recommend 9.0). No serverless.
Load: elasticache-search.md plus the relevant pattern file (rag-retrieval.md, agent-memory.md, or semantic-cache.md), embedding-providers.md, framework-guide.md (if framework mentioned)
Vector search MUST use node-based Valkey 8.2 or above (recommend 9.0). Serverless does NOT support vector search. Never recommend serverless for vector search workloads, not even as a temporary or future option.
Global Datastore MUST use node-based clusters. If the GenAI workload requires multi-Region replication, it must be node-based.
Vector search is NOT available on data tiering node types (r6gd family). Do not recommend r6gd instances for any workload requiring vector search.
Changing embedding providers requires full re-indexing. If the user wants to switch embedding models, warn that ALL existing vectors must be deleted and re-embedded. This is destructive. Confirm before proceeding.
elasticache-search.md and including the supports_ft_search() guard.struct.pack only.redis.commands.search or valkey.commands.search Python wrappers for FT.* commands. Use execute_command() instead. When using supported frameworks like langgraph-checkpoint-aws (ValkeyStore) or Mem0, their built-in abstractions (e.g., store.search(), store.put(), m.add(), m.search()) are acceptable.infrastructure.embedding_module).supports_ft_search().Mode 2 (server-side) and Mode 3 workloads need data-plane access to run FT.CREATE, FT.SEARCH, JSON operations, and other Valkey commands. The primary path is the valkey-py client (pip install valkey). Connect through the cache endpoint (via the jump host or SSM tunnel covered in setup). The agent writes Python that runs each command via execute_command(), consistent with the guidance in “Common Mistakes to Avoid” rule 3.
All GenAI patterns require Valkey. Vector search patterns specifically require Valkey 8.2 or above on node-based clusters (recommend 9.0).
Vector search is available with Valkey 8.2 or above on node-based clusters in all AWS Regions at no additional cost. Not supported on data-tiering instances (r6gd) or serverless caches.
If the user doesn’t have a cache yet, hand off to setup and ensure node-based Valkey 8.2 or above is selected (recommend 9.0) when vector search is needed.
genai.mode is already set in requirements.json, skip classification.requirements.json under genai.mode. If Mode 2, also persist genai.mode_2_path ("app-side" or "server-side").requirements.json for infrastructure.embedding_module. If set and the file exists, import from it. If not set, load embedding-providers.md, ask the user for their preferred model, generate the reusable utility file in their project, and persist the choice.elasticache-search.md for constraints)framework-guide.md and persist the choice to genai.framework in requirements.json.After the pattern is implemented, update .elasticache/requirements.json. GenAI owns the genai section. Read the existing file first, merge your updates, then write it back. Do not overwrite fields owned by setup or requirements.
When your response includes pricing, version constraints, or feature availability, include the freshness disclaimer per SKILL.md Global Rule #5: “For current pricing see https://aws.amazon.com/elasticache/pricing/ (opens in a new tab). For current feature availability see https://docs.aws.amazon.com/AmazonElastiCache/latest/dg/ (opens in a new tab).”