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 * `Query` request with `IndexId` injected from the bound index.
8 */
9export interface QueryRequest extends Omit<kendra.QueryRequest, "IndexId"> {}
10
11/**
12 * Runtime binding for the `Query` operation (IAM action
13 * `kendra:Query`), scoped to one {@link Index}.
14 *
15 * Searches the index with a natural-language query — returns ranked
16 * answers, FAQ matches, and document results, optionally filtered on
17 * document attributes and the querying user's context.
18 * Provide the implementation with
19 * `Effect.provide(AWS.Kendra.QueryHttp)`.
20 *
21 * ### Querying an Index
22 * **Example:** Search an Index
23 * ```typescript
24 * const query = yield* AWS.Kendra.Query(index);
25 *
26 * const results = yield* query({ QueryText: "how do I configure SSO?" });
27 * for (const item of results.ResultItems ?? []) {
28 * console.log(item.Type, item.DocumentTitle?.Text);
29 * }
30 * ```
31 *
32 * @binding
33 */
34export interface Query extends Binding.Service<
35 Query,
36 "AWS.Kendra.Query",
37 (
38 index: Index,
39 ) => Effect.Effect<
40 (
41 request?: QueryRequest,
42 ) => Effect.Effect<kendra.QueryResult, kendra.QueryError>
43 >
44> {}
45export const Query = Binding.Service<Query>("AWS.Kendra.Query");