| 1 | /** |
| 2 | * Pure, dependency-free vector helpers shared by both worker fixtures. Kept |
| 3 | * separate from `index-resource.ts` (which imports `@/Cloudflare`) so the plain |
| 4 | * async Worker bundle does NOT drag the alchemy/Effect graph — and its |
| 5 | * `node:os` transitive import — into the Worker, which Cloudflare rejects. |
| 6 | */ |
| 7 | export const DIMENSIONS = 32; |
| 8 | |
| 9 | /** Builds a deterministic `DIMENSIONS`-length vector seeded by the first values. */ |
| 10 | export const vector = (...seed: number[]): number[] => |
| 11 | Array.from({ length: DIMENSIONS }, (_, i) => seed[i] ?? (i % 10) / 10); |
| 12 | |
| 13 | /** |
| 14 | * The three vectors every worker upserts. Ids are namespaced by `label` so the |
| 15 | * effect/async workers stay independent even though they share one index. |
| 16 | */ |
| 17 | export const seedVectors = (label: string) => [ |
| 18 | { |
| 19 | id: `${label}-a`, |
| 20 | values: vector(0.1, 0.2, 0.3), |
| 21 | metadata: { kind: "first" }, |
| 22 | }, |
| 23 | { |
| 24 | id: `${label}-b`, |
| 25 | values: vector(0.9, 0.8, 0.7), |
| 26 | metadata: { kind: "second" }, |
| 27 | }, |
| 28 | { |
| 29 | id: `${label}-c`, |
| 30 | values: vector(0.4, 0.5, 0.6), |
| 31 | metadata: { kind: "third" }, |
| 32 | }, |
| 33 | ]; |