| 1 | import type * as aoss from "@distilled.cloud/aws/opensearchserverless"; |
| 2 | import type * as Effect from "effect/Effect"; |
| 3 | import * as Binding from "../../Binding.ts"; |
| 4 | import type { Collection } from "./Collection.ts"; |
| 5 | |
| 6 | /** |
| 7 | * Runtime binding for the `CreateIndex` operation scoped to one collection |
| 8 | * (IAM action `aoss:APIAccessAll` on the collection ARN). |
| 9 | * |
| 10 | * Creates an index in the bound {@link Collection} from inside a function |
| 11 | * runtime — the control-plane path for the multi-tenant pattern where each |
| 12 | * tenant gets its own (vector) index. The calling principal must also be |
| 13 | * granted `aoss:CreateIndex` on the index pattern by a data |
| 14 | * {@link AccessPolicy}. Provide the implementation with |
| 15 | * `Effect.provide(AWS.OpenSearchServerless.CreateIndexHttp)`. |
| 16 | * ### Managing Indexes at Runtime |
| 17 | * **Example:** Create a tenant's vector index |
| 18 | * ```typescript |
| 19 | * // init — bind the operation to the collection |
| 20 | * const createIndex = yield* AWS.OpenSearchServerless.CreateIndex(collection); |
| 21 | * |
| 22 | * // runtime |
| 23 | * yield* createIndex({ |
| 24 | * indexName: `tenant-${tenantId}`, |
| 25 | * indexSchema: { |
| 26 | * mappings: { |
| 27 | * properties: { |
| 28 | * embedding: { type: "knn_vector", dimension: 1536 }, |
| 29 | * }, |
| 30 | * }, |
| 31 | * }, |
| 32 | * }); |
| 33 | * ``` |
| 34 | * |
| 35 | * @binding |
| 36 | */ |
| 37 | export interface CreateIndex extends Binding.Service< |
| 38 | CreateIndex, |
| 39 | "AWS.OpenSearchServerless.CreateIndex", |
| 40 | ( |
| 41 | collection: Collection, |
| 42 | ) => Effect.Effect< |
| 43 | ( |
| 44 | request: Omit<aoss.CreateIndexRequest, "id">, |
| 45 | ) => Effect.Effect<aoss.CreateIndexResponse, aoss.CreateIndexError> |
| 46 | > |
| 47 | > {} |
| 48 | export const CreateIndex = Binding.Service<CreateIndex>( |
| 49 | "AWS.OpenSearchServerless.CreateIndex", |
| 50 | ); |