@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, 04:45 UTC

main
ts 58 lines 2.3 KB
Raw
1 import type * as runtime from "@cloudflare/workers-types";
2 import * as Binding from "alchemy/Binding";
3 import * as Effect from "effect/Effect";
4 import type { Index } from "./VectorizeIndex.ts";
5
6 /**
7 * Bind a {@link Index} to a Worker and obtain the Effect-native Vectorize
8 * client (`describe`, `query`, `upsert`, …).
9 *
10 * `SearchIndex` is a single identifier that is simultaneously the binding's
11 * Context tag, its type, and the callable —
12 * `yield* Cloudflare.Vectorize.SearchIndex(index)`.
13 *
14 * **Example:** Querying an index inside a Worker
15 * ```typescript
16 * const vec = yield* Cloudflare.Vectorize.SearchIndex(MyIndex);
17 * const matches = yield* vec.query([0.1, 0.2, 0.3], { topK: 5 });
18 * ```
19 *
20 * @binding
21 * @product Vectorize
22 * @category AI
23 */
24 export interface SearchIndex extends Binding.Service<
25 SearchIndex,
26 "Cloudflare.Vectorize.SearchIndex",
27 (index: Index) => Effect.Effect<SearchIndexClient>
28 > {}
29
30 export const SearchIndex = Binding.Service<SearchIndex>("Cloudflare.Vectorize.SearchIndex");
31
32 export interface SearchIndexClient {
33 /**
34 * An Effect that resolves to the raw underlying Cloudflare Vectorize
35 * binding. Use this for direct access not covered by the helpers below.
36 */
37 raw: Effect.Effect<runtime.Vectorize>;
38 /** Get information about the bound index (dimensions, vector count). */
39 describe: () => Effect.Effect<runtime.VectorizeIndexInfo>;
40 /** Find the nearest neighbors of `vector`. */
41 query: (
42 vector: runtime.VectorFloatArray | number[],
43 options?: runtime.VectorizeQueryOptions,
44 ) => Effect.Effect<runtime.VectorizeMatches>;
45 /** Find the nearest neighbors of an existing vector by its id. */
46 queryById: (
47 vectorId: string,
48 options?: runtime.VectorizeQueryOptions,
49 ) => Effect.Effect<runtime.VectorizeMatches>;
50 /** Insert vectors. Throws if any provided id already exists. */
51 insert: (vectors: runtime.VectorizeVector[]) => Effect.Effect<runtime.VectorizeAsyncMutation>;
52 /** Upsert vectors, replacing any existing vectors with matching ids. */
53 upsert: (vectors: runtime.VectorizeVector[]) => Effect.Effect<runtime.VectorizeAsyncMutation>;
54 /** Delete vectors by id. */
55 deleteByIds: (ids: string[]) => Effect.Effect<runtime.VectorizeAsyncMutation>;
56 /** Fetch vectors by id. */
57 getByIds: (ids: string[]) => Effect.Effect<runtime.VectorizeVector[]>;
58 }