cloudflare
Version:
The official TypeScript library for the Cloudflare API
232 lines • 8.81 kB
JavaScript
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
import { APIResource } from "../../../core/resource.mjs";
import * as MetadataIndexAPI from "./metadata-index.mjs";
import { BaseMetadataIndex, MetadataIndex, } from "./metadata-index.mjs";
import { SinglePage } from "../../../core/pagination.mjs";
import { buildHeaders } from "../../../internal/headers.mjs";
import { path } from "../../../internal/utils/path.mjs";
export var BaseIndexes = /* @__PURE__ */ (() => {
class BaseIndexes extends APIResource {
/**
* Creates and returns a new Vectorize Index.
*
* @example
* ```ts
* const createIndex = await client.vectorize.indexes.create({
* account_id: '023e105f4ecef8ad9ca31a8372d0c353',
* config: { dimensions: 768, metric: 'cosine' },
* name: 'example-index',
* });
* ```
*/
create(params, options) {
const { account_id, ...body } = params;
return this._client.post(path `/accounts/${account_id}/vectorize/v2/indexes`, {
body,
...options,
})._thenUnwrap((obj) => obj.result);
}
/**
* Returns a list of Vectorize Indexes
*
* @example
* ```ts
* // Automatically fetches more pages as needed.
* for await (const createIndex of client.vectorize.indexes.list(
* { account_id: '023e105f4ecef8ad9ca31a8372d0c353' },
* )) {
* // ...
* }
* ```
*/
list(params, options) {
const { account_id } = params;
return this._client.getAPIList(path `/accounts/${account_id}/vectorize/v2/indexes`, (SinglePage), options);
}
/**
* Deletes the specified Vectorize Index.
*
* @example
* ```ts
* const index = await client.vectorize.indexes.delete(
* 'example-index',
* { account_id: '023e105f4ecef8ad9ca31a8372d0c353' },
* );
* ```
*/
delete(indexName, params, options) {
const { account_id } = params;
return this._client.delete(path `/accounts/${account_id}/vectorize/v2/indexes/${indexName}`, options)._thenUnwrap((obj) => obj.result);
}
/**
* Delete a set of vectors from an index by their vector identifiers.
*
* @example
* ```ts
* const response = await client.vectorize.indexes.deleteByIDs(
* 'example-index',
* { account_id: '023e105f4ecef8ad9ca31a8372d0c353' },
* );
* ```
*/
deleteByIDs(indexName, params, options) {
const { account_id, ...body } = params;
return this._client.post(path `/accounts/${account_id}/vectorize/v2/indexes/${indexName}/delete_by_ids`, {
body,
...options,
})._thenUnwrap((obj) => obj.result);
}
/**
* Returns the specified Vectorize Index.
*
* @example
* ```ts
* const createIndex = await client.vectorize.indexes.get(
* 'example-index',
* { account_id: '023e105f4ecef8ad9ca31a8372d0c353' },
* );
* ```
*/
get(indexName, params, options) {
const { account_id } = params;
return this._client.get(path `/accounts/${account_id}/vectorize/v2/indexes/${indexName}`, options)._thenUnwrap((obj) => obj.result);
}
/**
* Get a set of vectors from an index by their vector identifiers.
*
* @example
* ```ts
* const response = await client.vectorize.indexes.getByIDs(
* 'example-index',
* { account_id: '023e105f4ecef8ad9ca31a8372d0c353' },
* );
* ```
*/
getByIDs(indexName, params, options) {
const { account_id, ...body } = params;
return this._client.post(path `/accounts/${account_id}/vectorize/v2/indexes/${indexName}/get_by_ids`, {
body,
...options,
})._thenUnwrap((obj) => obj.result);
}
/**
* Get information about a vectorize index.
*
* @example
* ```ts
* const response = await client.vectorize.indexes.info(
* 'example-index',
* { account_id: '023e105f4ecef8ad9ca31a8372d0c353' },
* );
* ```
*/
info(indexName, params, options) {
const { account_id } = params;
return this._client.get(path `/accounts/${account_id}/vectorize/v2/indexes/${indexName}/info`, options)._thenUnwrap((obj) => obj.result);
}
/**
* Inserts vectors into the specified index and returns a mutation id corresponding
* to the vectors enqueued for insertion.
*
* @example
* ```ts
* const response = await client.vectorize.indexes.insert(
* 'example-index',
* {
* account_id: '023e105f4ecef8ad9ca31a8372d0c353',
* body: fs.createReadStream('path/to/file'),
* },
* );
* ```
*/
insert(indexName, params, options) {
const { account_id, body, 'unparsable-behavior': unparsableBehavior } = params;
return this._client.post(path `/accounts/${account_id}/vectorize/v2/indexes/${indexName}/insert`, {
query: { 'unparsable-behavior': unparsableBehavior },
body: body,
...options,
headers: buildHeaders([{ 'Content-Type': 'application/x-ndjson' }, options?.headers]),
})._thenUnwrap((obj) => obj.result);
}
/**
* Returns a paginated list of vector identifiers from the specified index.
*
* @example
* ```ts
* const response = await client.vectorize.indexes.listVectors(
* 'example-index',
* { account_id: '023e105f4ecef8ad9ca31a8372d0c353' },
* );
* ```
*/
listVectors(indexName, params, options) {
const { account_id, ...query } = params;
return this._client.get(path `/accounts/${account_id}/vectorize/v2/indexes/${indexName}/list`, {
query,
...options,
})._thenUnwrap((obj) => obj.result);
}
/**
* Finds vectors closest to a given vector in an index.
*
* @example
* ```ts
* const response = await client.vectorize.indexes.query(
* 'example-index',
* {
* account_id: '023e105f4ecef8ad9ca31a8372d0c353',
* vector: [0.5, 0.5, 0.5],
* },
* );
* ```
*/
query(indexName, params, options) {
const { account_id, ...body } = params;
return this._client.post(path `/accounts/${account_id}/vectorize/v2/indexes/${indexName}/query`, {
body,
...options,
})._thenUnwrap((obj) => obj.result);
}
/**
* Upserts vectors into the specified index, creating them if they do not exist and
* returns a mutation id corresponding to the vectors enqueued for upsertion.
*
* @example
* ```ts
* const response = await client.vectorize.indexes.upsert(
* 'example-index',
* {
* account_id: '023e105f4ecef8ad9ca31a8372d0c353',
* body: fs.createReadStream('path/to/file'),
* },
* );
* ```
*/
upsert(indexName, params, options) {
const { account_id, body, 'unparsable-behavior': unparsableBehavior } = params;
return this._client.post(path `/accounts/${account_id}/vectorize/v2/indexes/${indexName}/upsert`, {
query: { 'unparsable-behavior': unparsableBehavior },
body: body,
...options,
headers: buildHeaders([{ 'Content-Type': 'application/x-ndjson' }, options?.headers]),
})._thenUnwrap((obj) => obj.result);
}
}
BaseIndexes._key = Object.freeze([
'vectorize',
'indexes',
]);
return BaseIndexes;
})();
export var Indexes = /* @__PURE__ */ (() => {
class Indexes extends BaseIndexes {
constructor() {
super(...arguments);
this.metadataIndex = new MetadataIndexAPI.MetadataIndex(this._client);
}
}
Indexes.MetadataIndex = MetadataIndex;
Indexes.BaseMetadataIndex = BaseMetadataIndex;
return Indexes;
})();
//# sourceMappingURL=indexes.mjs.map