import type { Context } from "../context.js"; import { Resource } from "../resource.js"; import { type CloudflareApi, type CloudflareApiOptions } from "./api.js"; /** * Properties for creating or updating a Vectorize Index */ export interface VectorizeIndexProps extends CloudflareApiOptions { /** * Name of the index */ name: string; /** * Optional description of the index */ description?: string; /** * Dimensions of the vectors */ dimensions: number; /** * Distance metric used for vector similarity */ metric: "cosine" | "euclidean" | "dot_product"; /** * Whether to delete the index if removed * If set to false, the index will remain but the resource will be removed from state * * @default true */ delete?: boolean; /** * Whether to adopt an existing index with the same name if it exists * If true and an index with the same name exists, it will be adopted rather than creating a new one * * @default false */ adopt?: boolean; } /** * Output returned after Vectorize Index creation/update */ export interface VectorizeIndex extends Resource<"cloudflare::VectorizeIndex">, VectorizeIndexProps { type: "vectorize"; /** * The unique identifier for the index (same as name) */ id: string; /** * Time at which the index was created */ createdAt?: number; } /** * Creates and manages Cloudflare Vectorize Indexes. * * Vectorize is Cloudflare's vector database that enables vector search within Cloudflare Workers. * * @example * // Create a basic vector index for text embeddings * const basicIndex = await VectorizeIndex("text-embeddings", { * name: "text-embeddings", * config: { * dimensions: 768, * metric: "cosine" * } * }); * * @example * // Create a vector index with a description * const descIndex = await VectorizeIndex("image-embeddings", { * name: "image-embeddings", * description: "Vector index for image embeddings using CLIP model", * config: { * dimensions: 512, * metric: "cosine" * } * }); * * @example * // Adopt an existing index if it already exists instead of failing * const existingIndex = await VectorizeIndex("existing-index", { * name: "existing-index", * adopt: true, * config: { * dimensions: 1024, * metric: "euclidean" * } * }); * * @see https://developers.cloudflare.com/vectorize/ */ export declare const VectorizeIndex: (((this: any, id: string, props?: {}) => never) & (new (_: never) => never)) | ((this: Context, id: string, props: VectorizeIndexProps) => Promise); interface CloudflareVectorizeResponse { result: { name: string; description?: string; created_on?: string; config: { dimensions: number; metric: string; }; }; success: boolean; errors: Array<{ code: number; message: string; }>; messages: string[]; } /** * Create a new Vectorize index */ export declare function createIndex(api: CloudflareApi, indexName: string, props: VectorizeIndexProps): Promise; /** * Get a Vectorize index */ export declare function getIndex(api: CloudflareApi, indexName: string): Promise; /** * Delete a Vectorize index */ export declare function deleteIndex(api: CloudflareApi, indexName: string): Promise; /** * List all Vectorize indexes in an account */ export declare function listIndexes(api: CloudflareApi): Promise<{ name: string; description?: string; }[]>; /** * Update a Vectorize index * * Note: The Cloudflare Vectorize API does not support updating indexes. * This function will always throw an error. */ export declare function updateIndex(api: CloudflareApi, indexName: string, props: VectorizeIndexProps): Promise; export {}; //# sourceMappingURL=vectorize-index.d.ts.map