1import type * as kendra from "@distilled.cloud/aws/kendra";
2import type * as Effect from "effect/Effect";
3import * as Binding from "../../Binding.ts";
4import type { Index } from "./SearchIndex.ts";
5
6/**
7 * `Retrieve` request with `IndexId` injected from the bound index.
8 */
9export interface RetrieveRequest extends Omit<
10 kendra.RetrieveRequest,
11 "IndexId"
12> {}
13
14/**
15 * Runtime binding for the `Retrieve` operation (IAM action
16 * `kendra:Retrieve`), scoped to one {@link Index}.
17 *
18 * Retrieves up to 100 semantically-relevant passages (200-token excerpts)
19 * from the index — the building block for retrieval-augmented generation
20 * (RAG) over documents synced into Kendra.
21 * Provide the implementation with
22 * `Effect.provide(AWS.Kendra.RetrieveHttp)`.
23 *
24 * ### Querying an Index
25 * **Example:** Retrieve Passages for RAG
26 * ```typescript
27 * const retrieve = yield* AWS.Kendra.Retrieve(index);
28 *
29 * const passages = yield* retrieve({ QueryText: "vacation policy" });
30 * const context = (passages.ResultItems ?? [])
31 * .map((item) => item.Content)
32 * .join("\n");
33 * ```
34 *
35 * @binding
36 */
37export interface Retrieve extends Binding.Service<
38 Retrieve,
39 "AWS.Kendra.Retrieve",
40 (
41 index: Index,
42 ) => Effect.Effect<
43 (
44 request: RetrieveRequest,
45 ) => Effect.Effect<kendra.RetrieveResult, kendra.RetrieveError>
46 >
47> {}
48export const Retrieve = Binding.Service<Retrieve>("AWS.Kendra.Retrieve");