UNPKG

cloudflare

Version:

The official TypeScript library for the Cloudflare API

238 lines • 9.26 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Indexes = exports.BaseIndexes = void 0; const tslib_1 = require("../../../internal/tslib.js"); // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. const resource_1 = require("../../../core/resource.js"); const MetadataIndexAPI = tslib_1.__importStar(require("./metadata-index.js")); const metadata_index_1 = require("./metadata-index.js"); const pagination_1 = require("../../../core/pagination.js"); const headers_1 = require("../../../internal/headers.js"); const path_1 = require("../../../internal/utils/path.js"); var BaseIndexes = /* @__PURE__ */ (() => { class BaseIndexes extends resource_1.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((0, path_1.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((0, path_1.path) `/accounts/${account_id}/vectorize/v2/indexes`, (pagination_1.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((0, path_1.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((0, path_1.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((0, path_1.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((0, path_1.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((0, path_1.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((0, path_1.path) `/accounts/${account_id}/vectorize/v2/indexes/${indexName}/insert`, { query: { 'unparsable-behavior': unparsableBehavior }, body: body, ...options, headers: (0, headers_1.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((0, path_1.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((0, path_1.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((0, path_1.path) `/accounts/${account_id}/vectorize/v2/indexes/${indexName}/upsert`, { query: { 'unparsable-behavior': unparsableBehavior }, body: body, ...options, headers: (0, headers_1.buildHeaders)([{ 'Content-Type': 'application/x-ndjson' }, options?.headers]), })._thenUnwrap((obj) => obj.result); } } BaseIndexes._key = Object.freeze([ 'vectorize', 'indexes', ]); return BaseIndexes; })(); exports.BaseIndexes = BaseIndexes; var Indexes = /* @__PURE__ */ (() => { class Indexes extends BaseIndexes { constructor() { super(...arguments); this.metadataIndex = new MetadataIndexAPI.MetadataIndex(this._client); } } Indexes.MetadataIndex = metadata_index_1.MetadataIndex; Indexes.BaseMetadataIndex = metadata_index_1.BaseMetadataIndex; return Indexes; })(); exports.Indexes = Indexes; //# sourceMappingURL=indexes.js.map