diff --git a/index.ts b/index.ts index 5ccbdac..57ea503 100644 --- a/index.ts +++ b/index.ts @@ -35,7 +35,12 @@ export type IndexConfig = { /** * Serverless vector client for upstash. */ -export class Index extends core.Index { +export class Index< + TIndexMetadata extends Record< + string, + unknown + > = Record +> extends core.Index { /** * Create a new vector client by providing the url and token * diff --git a/src/commands/client/fetch/index.ts b/src/commands/client/fetch/index.ts index 4847e28..68e9b31 100644 --- a/src/commands/client/fetch/index.ts +++ b/src/commands/client/fetch/index.ts @@ -9,7 +9,7 @@ type FetchCommandOptions = { export type FetchResult> = Vector | null; export class FetchCommand extends Command[]> { - constructor([ids, opts]: [ids: number[] | string[], opts: FetchCommandOptions]) { + constructor([ids, opts]: [ids: number[] | string[], opts?: FetchCommandOptions]) { super({ ids, ...opts }, "fetch"); } } diff --git a/src/commands/client/upsert/index.ts b/src/commands/client/upsert/index.ts index a320c61..ee28e0a 100644 --- a/src/commands/client/upsert/index.ts +++ b/src/commands/client/upsert/index.ts @@ -1,13 +1,13 @@ import { Command } from "@commands/command"; -type UpsertCommandPayload = { +type UpsertCommandPayload = { id: number | string; vector: number[]; - metadata?: Record; + metadata?: TMetadata; }; -export class UpsertCommand extends Command { - constructor(payload: UpsertCommandPayload | UpsertCommandPayload[]) { +export class UpsertCommand extends Command { + constructor(payload: UpsertCommandPayload | UpsertCommandPayload[]) { super(payload, "upsert"); } } diff --git a/src/vector.ts b/src/vector.ts index 42780db..466b1c4 100644 --- a/src/vector.ts +++ b/src/vector.ts @@ -15,7 +15,7 @@ export type CommandArgs any> = /** * Serverless vector client for upstash vector db. */ -export class Index { +export class Index = Record> { protected client: Requester; /** @@ -64,8 +64,9 @@ export class Index { * * @returns A promise that resolves with an array of query result objects when the request to query the index is completed. */ - query = (args: CommandArgs) => - new QueryCommand(args).exec(this.client); + query = ( + args: CommandArgs + ) => new QueryCommand(args).exec(this.client); /** * Upserts (Updates and Inserts) specific items into the index. @@ -89,7 +90,9 @@ export class Index { * * @returns {string} A promise that resolves with the result of the upsert operation after the command is executed. */ - upsert = (args: CommandArgs) => new UpsertCommand(args).exec(this.client); + upsert = ( + args: CommandArgs> + ) => new UpsertCommand(args).exec(this.client); /** * It's used for retrieving specific items from the index, optionally including @@ -111,8 +114,9 @@ export class Index { * * @returns {Promise[]>} A promise that resolves with an array of fetched items or null if not found, after the command is executed. */ - fetch = (...args: CommandArgs) => - new FetchCommand(args).exec(this.client); + fetch = ( + ...args: CommandArgs + ) => new FetchCommand(args).exec(this.client); /** * It's used for wiping an entire index. @@ -150,8 +154,9 @@ export class Index { * * @returns {Promise>} A promise that resolves with the response containing the next cursor and an array of vectors, after the command is executed. */ - range = (args: CommandArgs) => - new RangeCommand(args).exec(this.client); + range = ( + args: CommandArgs + ) => new RangeCommand(args).exec(this.client); /** * Retrieves info from the index.