| 1 | import * as Cloudflare from "@/Cloudflare/index.ts"; |
| 2 | import * as Effect from "effect/Effect"; |
| 3 | import { DIMENSIONS } from "./vectors.ts"; |
| 4 | |
| 5 | /** |
| 6 | * Shared Vectorize resources used by BOTH the effect-worker and the |
| 7 | * async-worker binding styles. Keeping one index here (instead of one per |
| 8 | * worker) means both workers bind the SAME resource, so the driver test can |
| 9 | * deploy both styles in a single stack and exercise the identical client |
| 10 | * surface against shared data. |
| 11 | * |
| 12 | * Runtime-only vector helpers live in `vectors.ts` (no alchemy import) so the |
| 13 | * plain async Worker can use them without bundling the Effect graph. |
| 14 | */ |
| 15 | export const TestIndex = Cloudflare.Vectorize.Index("VectorizeWorkerIndex", { |
| 16 | dimensions: DIMENSIONS, |
| 17 | metric: "cosine", |
| 18 | }); |
| 19 | |
| 20 | /** |
| 21 | * Declares the metadata index on the `kind` property of the resolved parent |
| 22 | * index. Must be yielded AFTER the parent index is resolved (its `indexName` |
| 23 | * Output is only populated on the resolved resource, not the class handle). |
| 24 | * Metadata indexes must exist before vectors are inserted for them to be |
| 25 | * queryable, so the stack yields this before any worker upserts. |
| 26 | */ |
| 27 | export const ensureMetaIndex = Effect.fn(function* ( |
| 28 | index: Cloudflare.Vectorize.Index, |
| 29 | ) { |
| 30 | return yield* Cloudflare.Vectorize.MetadataIndex( |
| 31 | "VectorizeWorkerKindMetaIndex", |
| 32 | { |
| 33 | indexName: index.indexName, |
| 34 | propertyName: "kind", |
| 35 | indexType: "string", |
| 36 | }, |
| 37 | ); |
| 38 | }); |