The best way to control Claude Code, Codex and more from any computer or phone

main
ts 64 lines 2.4 KB
Raw
1 import type * as s3vectors from "@distilled.cloud/aws/s3vectors";
2 import * as Binding from "alchemy/Binding";
3 import type * as Effect from "effect/Effect";
4 import type { Index } from "./VectorIndex.ts";
5
6 /** Fields the binding injects from the bound {@link Index}. */
7 type IndexRef = "vectorBucketName" | "indexName" | "indexArn";
8
9 export interface QueryVectorsRequest extends Omit<s3vectors.QueryVectorsInput, IndexRef> {}
10 export interface GetVectorsRequest extends Omit<s3vectors.GetVectorsInput, IndexRef> {}
11 export interface ListVectorsRequest extends Omit<s3vectors.ListVectorsInput, IndexRef> {}
12
13 /**
14 * The read-only runtime client returned by binding an {@link Index} via
15 * {@link VectorsRead}. All calls target the bound index (its ARN is
16 * injected); pass raw distilled request shapes minus the index identifier.
17 */
18 export interface ReadVectorsClient {
19 /** Nearest-neighbor similarity query. */
20 readonly query: (
21 request: QueryVectorsRequest,
22 ) => Effect.Effect<s3vectors.QueryVectorsOutput, s3vectors.QueryVectorsError>;
23 /** Fetch vectors by key. */
24 readonly get: (
25 request: GetVectorsRequest,
26 ) => Effect.Effect<s3vectors.GetVectorsOutput, s3vectors.GetVectorsError>;
27 /** List vectors (paginated / segmented scan). */
28 readonly list: (
29 request: ListVectorsRequest,
30 ) => Effect.Effect<s3vectors.ListVectorsOutput, s3vectors.ListVectorsError>;
31 }
32
33 /**
34 * Read-only runtime binding for the S3 Vectors data plane — query, get, and
35 * list vectors in a bound {@link Index}.
36 *
37 * Grants only `s3vectors:QueryVectors`, `s3vectors:GetVectors`, and
38 * `s3vectors:ListVectors` on exactly the bound index's ARN — the
39 * least-privilege choice for retrieval-only consumers (e.g. a RAG search
40 * endpoint that never writes embeddings). Provide the implementation with
41 * `Effect.provide(AWS.S3Vectors.VectorsReadHttp)`.
42 *
43 * ### Reading Vectors
44 * **Example:** Query Nearest Neighbors (read-only)
45 * ```typescript
46 * // init
47 * const vectors = yield* AWS.S3Vectors.VectorsRead(index);
48 *
49 * // runtime
50 * const result = yield* vectors.query({
51 * topK: 5,
52 * queryVector: { float32: [0.1, 0.2, 0.3] },
53 * returnDistance: true,
54 * });
55 * ```
56 *
57 * @binding
58 */
59 export interface VectorsRead extends Binding.Service<
60 VectorsRead,
61 "AWS.S3Vectors.VectorsRead",
62 <I extends Index>(index: I) => Effect.Effect<ReadVectorsClient>
63 > {}
64 export const VectorsRead = Binding.Service<VectorsRead>("AWS.S3Vectors.VectorsRead");