@ragpipe/plugin-cloudflare
v0.4.0
Published
Cloudflare Workers AI embedding and generation plugin for ragpipe
Maintainers
Readme
@ragpipe/plugin-cloudflare
Cloudflare Workers AI embedding and generation plugin for ragpipe.
Install
pnpm add ragpipe @ragpipe/plugin-cloudflareUsage
import { defineConfig } from "ragpipe";
import { cloudflareEmbedding, cloudflareGeneration } from "@ragpipe/plugin-cloudflare";
export default defineConfig({
embedding: cloudflareEmbedding({
accountId: process.env.CLOUDFLARE_ACCOUNT_ID!,
apiToken: process.env.CLOUDFLARE_API_TOKEN!,
model: "@cf/qwen/qwen3-embedding-0.6b",
}),
generation: cloudflareGeneration({
accountId: process.env.CLOUDFLARE_ACCOUNT_ID!,
apiToken: process.env.CLOUDFLARE_API_TOKEN!,
model: "@cf/openai/gpt-oss-20b",
systemPrompt: "Answer based on the provided context.",
}),
// ... vectorStore
});API
cloudflareEmbedding(options)
Returns an EmbeddingPlugin that calls the Cloudflare Workers AI Embedding API.
| Option | Type | Default | Description |
|---|---|---|---|
| accountId | string | — | Cloudflare account ID (required) |
| apiToken | string | — | Cloudflare API token (required) |
| model | string | — | Embedding model name (required) |
- Batch support:
embedMany()sends an array of texts in a single API call
cloudflareGeneration(options)
Returns a GenerationPlugin that calls the Cloudflare Workers AI Generation API.
| Option | Type | Default | Description |
|---|---|---|---|
| accountId | string | — | Cloudflare account ID (required) |
| apiToken | string | — | Cloudflare API token (required) |
| model | string | — | Generation model name (required) |
| systemPrompt | string | "Answer based on the provided context." | Default system instruction |
- Streaming:
generateStream()returns anAsyncIterable<string>via SSE - History: Pass
{ history }to include conversation context - Per-call override: Pass
{ systemPrompt }at call time to override the default
Get an API Token
- Go to Cloudflare Dashboard
- Create a token with Workers AI read permission
- Set
CLOUDFLARE_ACCOUNT_IDandCLOUDFLARE_API_TOKENin your environment
License
MIT
