type Cloudflare = {
token: string;
email: string;
key: string;
};
/**
* Create Vectorize Index
* Creates and returns a new Vectorize Index.
*/
export async function main(
auth: Cloudflare,
account_identifier: string,
body: {
config: (
| {
preset:
| "@cf/baai/bge-small-en-v1.5"
| "@cf/baai/bge-base-en-v1.5"
| "@cf/baai/bge-large-en-v1.5"
| "openai/text-embedding-ada-002"
| "cohere/embed-multilingual-v2.0";
[k: string]: unknown;
}
| {
dimensions: number;
metric: "cosine" | "euclidean" | "dot-product";
[k: string]: unknown;
}
) & { [k: string]: unknown };
description?: string;
name: string;
[k: string]: unknown;
}
) {
const url = new URL(
`https://api.cloudflare.com/client/v4/accounts/${account_identifier}/vectorize/indexes`
);
const response = await fetch(url, {
method: "POST",
headers: {
"X-AUTH-EMAIL": auth.email,
"X-AUTH-KEY": auth.key,
"Content-Type": "application/json",
Authorization: "Bearer " + auth.token,
},
body: JSON.stringify(body),
});
if (!response.ok) {
const text = await response.text();
throw new Error(`${response.status} ${text}`);
}
return await response.json();
}
Submitted by hugo697 354 days ago