jose luis
jose luis
CDCloudflare Developers
Created by jose luis on 12/24/2024 in #workers-help
Is it possible to use service bindings with `vectorize` db?
I have a worker A that uses worker B. This worker B has bindings to a vectorize index (this index works when used by itself). Both are deployed (given that vectorize doesn't work locally) , but this fail with Cannot read properties of undefined (reading 'VECTORIZE'), which is the binding defined in the wrangler.toml for WorkerB. I guess i'm missing something obvious or this cannot work. (the deployed url from the worker A fails with Error 1101)
//workerB.ts
export interface Env {
VECTORIZE: Vectorize;
}
export default class WorkerB extends WorkerEntrypoint {
// Currently, entrypoints without a named handler are not supported
async fetch() {
return new Response(null, { status: 404 });
}
async getSimilarImages(env: Env) {
return env.VECTORIZE.queryById('FJ4188-100_0_0_crop_1_res');
}
}
//WorkerA.ts
export default {
async fetch(request, env) {
// const result = await env.WORKER_B.add(1, 2);
const result = await env.WORKER_B.getSimilarImages();
console.log(result);
return new Response(result, { status: 200 });
},
};
//workerB.ts
export interface Env {
VECTORIZE: Vectorize;
}
export default class WorkerB extends WorkerEntrypoint {
// Currently, entrypoints without a named handler are not supported
async fetch() {
return new Response(null, { status: 404 });
}
async getSimilarImages(env: Env) {
return env.VECTORIZE.queryById('FJ4188-100_0_0_crop_1_res');
}
}
//WorkerA.ts
export default {
async fetch(request, env) {
// const result = await env.WORKER_B.add(1, 2);
const result = await env.WORKER_B.getSimilarImages();
console.log(result);
return new Response(result, { status: 200 });
},
};
5 replies