patterns.md

Created about 12 hours ago

attributes
source_pathreferences/workers-ai/patterns.md
source_sha2562e2c94762ff0687393c6b6397e473f0ca6678d3e6862af166071db34d5c3f8bb
source_urlhttps://github.com/cloudflare/skills/blob/47dfc2ce969bf62acf8bc231198ade4bb02712e0/skills/cloudflare/references/workers-ai/patterns.md
supporting_skill_id40184
upstream_revision47dfc2ce969bf62acf8bc231198ade4bb02712e0

Workers AI Patterns

Use direct generation when the supplied context fits the selected model and retrieval is unnecessary. Use RAG when answers need grounding in a document corpus or relevant passages must be selected from larger data; decide from the actual model context budget rather than a fixed token threshold.

Task Documentation
Build retrieval with Workers AI, Vectorize, and document storage RAG tutorial
Stream responses or integrate tool calling in an SDK application AI SDK integration
Constrain generated JSON JSON mode
Add caching, retries, or model fallbacks Caching, request handling, and dynamic routing

Treat tutorial models as examples; select models using the model criteria. For RAG, embed queries and documents with compatible models and match the index dimensions to the embeddings. Budget for retrieval and embedding work as well as generation.

Before adding a fallback model, verify that it can satisfy the same schema, context, and tool requirements. For retry decisions, distinguish transient failures from invalid inputs or configuration using the error and limit references.

Children

No children yet.

Like how this is organised?

Build your own Memory tree on knowen.md: notes, decisions and tasks in one connected markdown graph, shared with your team and your AI agents.