From fff8e399a340532af5087ed1873640dea51eb66a Mon Sep 17 00:00:00 2001 From: Aidan <64613310+aidangomar@users.noreply.github.com> Date: Wed, 20 Dec 2023 15:22:35 -0500 Subject: [PATCH] feat: Node create index API (#720) --- node/src/index.ts | 5 +++++ node/src/remote/index.ts | 37 +++++++++++++++++++++++++++++++++++-- 2 files changed, 40 insertions(+), 2 deletions(-) diff --git a/node/src/index.ts b/node/src/index.ts index def416d4..9cefbd1e 100644 --- a/node/src/index.ts +++ b/node/src/index.ts @@ -744,6 +744,11 @@ export interface IvfPQIndexConfig { */ replace?: boolean + /** + * Cache size of the index + */ + index_cache_size?: number + type: 'ivf_pq' } diff --git a/node/src/remote/index.ts b/node/src/remote/index.ts index 9ef6723f..a7fc46f8 100644 --- a/node/src/remote/index.ts +++ b/node/src/remote/index.ts @@ -246,8 +246,41 @@ export class RemoteTable implements Table { return data.length } - async createIndex (indexParams: VectorIndexParams): Promise { - throw new Error('Not implemented') + async createIndex (indexParams: VectorIndexParams): Promise { + const unsupportedParams = [ + 'index_name', + 'num_partitions', + 'max_iters', + 'use_opq', + 'num_sub_vectors', + 'num_bits', + 'max_opq_iters', + 'replace' + ] + for (const param of unsupportedParams) { + // eslint-disable-next-line @typescript-eslint/strict-boolean-expressions + if (indexParams[param as keyof VectorIndexParams]) { + throw new Error(`${param} is not supported for remote connections`) + } + } + + const column = indexParams.column ?? 'vector' + const indexType = 'vector' // only vector index is supported for remote connections + const metricType = indexParams.metric_type ?? 'L2' + const indexCacheSize = indexParams ?? null + + const data = { + column, + index_type: indexType, + metric_type: metricType, + index_cache_size: indexCacheSize + } + const res = await this._client.post(`/v1/table/${this._name}/create_index/`, data) + if (res.status !== 200) { + throw new Error(`Server Error, status: ${res.status}, ` + + // eslint-disable-next-line @typescript-eslint/restrict-template-expressions + `message: ${res.statusText}: ${res.data}`) + } } async countRows (): Promise {