@devries-cameron20 / t3code Mirror · read-only
Fork 0

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

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 21, 06:00 UTC

main
ts 50 lines 1.79 KB
Raw
1 import type * as bedrock from "@distilled.cloud/aws/bedrock-agent-runtime";
2 import * as Binding from "alchemy/Binding";
3 import type * as Effect from "effect/Effect";
4 import type { KnowledgeBase } from "./KnowledgeBase.ts";
5
6 /**
7 * The `Retrieve` request with the binding-injected `knowledgeBaseId` removed —
8 * it is supplied automatically from the bound {@link KnowledgeBase}.
9 */
10 export interface RetrieveRequest extends Omit<bedrock.RetrieveRequest, "knowledgeBaseId"> {}
11
12 /**
13 * Runtime binding for `bedrock-agent-runtime:Retrieve` — query a
14 * {@link KnowledgeBase} for the passages most relevant to a natural-language
15 * query, without generating an answer.
16 *
17 * Bind a knowledge base inside a function runtime to get a callable that runs
18 * semantic retrieval. The binding grants the function `bedrock:Retrieve`
19 * scoped to exactly that knowledge base. Use this when you want the raw
20 * retrieved chunks (to build your own prompt); use {@link RetrieveAndGenerate}
21 * for a fully managed RAG answer.
22 *
23 * ### Retrieving Passages
24 * **Example:** Retrieve Relevant Chunks
25 * ```typescript
26 * // init
27 * const retrieve = yield* Bedrock.Retrieve(knowledgeBase);
28 *
29 * // runtime
30 * const result = yield* retrieve({
31 * retrievalQuery: { text: "How do I rotate credentials?" },
32 * retrievalConfiguration: {
33 * vectorSearchConfiguration: { numberOfResults: 5 },
34 * },
35 * });
36 * const passages = result.retrievalResults.map((r) => r.content?.text);
37 * ```
38 *
39 * @binding
40 */
41 export interface Retrieve extends Binding.Service<
42 Retrieve,
43 "AWS.Bedrock.Retrieve",
44 <K extends KnowledgeBase>(
45 knowledgeBase: K,
46 ) => Effect.Effect<
47 (request: RetrieveRequest) => Effect.Effect<bedrock.RetrieveResponse, bedrock.RetrieveError>
48 >
49 > {}
50 export const Retrieve = Binding.Service<Retrieve>("AWS.Bedrock.Retrieve");