Skip to content

Commit af1d293

Browse files
authored
update workflow extend and event param. made env.db reference consistent. (#20441)
1 parent 0921480 commit af1d293

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

src/content/docs/workers-ai/tutorials/build-a-retrieval-augmented-generation-ai.mdx

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -216,10 +216,12 @@ class_name = "RAGWorkflow"
216216

217217
</WranglerConfig>
218218

219-
In `src/index.js`, add a new class called `RAGWorkflow` that extends `Workflow`:
219+
In `src/index.js`, add a new class called `RAGWorkflow` that extends `WorkflowEntrypoint`:
220220

221221
```js
222-
export class RAGWorkflow {
222+
import { WorkflowEntrypoint } from "cloudflare:workers";
223+
224+
export class RAGWorkflow extends WorkflowEntrypoint {
223225
async run(event, step) {
224226
await step.do('example step', async () => {
225227
console.log("Hello World!")
@@ -268,14 +270,17 @@ Now, we can update our workflow to begin adding notes to our database, and gener
268270
This example features the [`@cf/baai/bge-base-en-v1.5` model](/workers-ai/models/bge-base-en-v1.5/), which can be used to create an embedding. Embeddings are stored and retrieved inside [Vectorize](/vectorize/), Cloudflare's vector database. The user query is also turned into an embedding so that it can be used for searching within Vectorize.
269271

270272
```js
271-
export class RAGWorkflow {
273+
import { WorkflowEntrypoint } from "cloudflare:workers";
274+
275+
export class RAGWorkflow extends WorkflowEntrypoint {
272276
async run(event, step) {
273-
const { text } = event.params
277+
const env = this.env
278+
const { text } = event.payload
274279

275280
const record = await step.do(`create database record`, async () => {
276281
const query = "INSERT INTO notes (text) VALUES (?) RETURNING *"
277282

278-
const { results } = await env.DATABASE.prepare(query)
283+
const { results } = await env.DB.prepare(query)
279284
.bind(text)
280285
.run()
281286

@@ -510,7 +515,7 @@ console.log(output) // [{ pageContent: 'Some long piece of text...' }]
510515
To use this splitter, we'll update the workflow to split the text into smaller chunks. We'll then iterate over the chunks and run the rest of the workflow for each chunk of text:
511516

512517
```js
513-
export class RAGWorkflow {
518+
export class RAGWorkflow extends WorkflowEntrypoint {
514519
async run(event, step) {
515520
const env = this.env
516521
const { text } = event.payload;
@@ -527,7 +532,7 @@ export class RAGWorkflow {
527532
const record = await step.do(`create database record: ${index}/${texts.length}`, async () => {
528533
const query = "INSERT INTO notes (text) VALUES (?) RETURNING *"
529534

530-
const { results } = await env.DATABASE.prepare(query)
535+
const { results } = await env.DB.prepare(query)
531536
.bind(text)
532537
.run()
533538

0 commit comments

Comments
 (0)