Skip to content

Commit

Permalink
VS-271: Fix Vectorize getVcetors, deleteVectors payload in Wrangler C…
Browse files Browse the repository at this point in the history
…lient
  • Loading branch information
garvit-gupta committed Aug 21, 2024
1 parent fc3636b commit b36ac37
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 4 deletions.
5 changes: 3 additions & 2 deletions packages/wrangler/src/vectorize/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import type {
VectorizeMetadataIndexPropertyName,
VectorizeQueryOptions,
VectorizeVector,
VectorizeVectorIds,
VectorizeVectorMutation,
} from "./types";
import type { FormData } from "undici";
Expand Down Expand Up @@ -155,7 +156,7 @@ export async function queryIndex(
export async function getByIds(
config: Config,
indexName: string,
ids: Array<string>
ids: VectorizeVectorIds
): Promise<VectorizeVector[]> {
const accountId = await requireAuth(config);

Expand All @@ -174,7 +175,7 @@ export async function getByIds(
export async function deleteByIds(
config: Config,
indexName: string,
ids: Array<string>
ids: VectorizeVectorIds
): Promise<VectorizeAsyncMutation> {
const accountId = await requireAuth(config);

Expand Down
8 changes: 7 additions & 1 deletion packages/wrangler/src/vectorize/deleteByIds.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import type {
CommonYargsArgv,
StrictYargsOptionsToInterface,
} from "../yargs-types";
import type { VectorizeVectorIds } from "./types";

export function options(yargs: CommonYargsArgv) {
return yargs
Expand Down Expand Up @@ -37,7 +38,12 @@ export async function handler(
}

logger.log(`📋 Deleting vectors...`);
const mutation = await deleteByIds(config, args.name, args.ids);

const ids: VectorizeVectorIds = {
ids: args.ids,
};

const mutation = await deleteByIds(config, args.name, ids);

logger.log(
`✅ Successfully enqueued ${args.ids.length} vectors into index '${args.name}' for deletion. Mutation changeset identifier: ${mutation.mutationId}.`
Expand Down
8 changes: 7 additions & 1 deletion packages/wrangler/src/vectorize/getByIds.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import type {
CommonYargsArgv,
StrictYargsOptionsToInterface,
} from "../yargs-types";
import type { VectorizeVectorIds } from "./types";

export function options(yargs: CommonYargsArgv) {
return yargs
Expand Down Expand Up @@ -37,7 +38,12 @@ export async function handler(
}

logger.log(`📋 Fetching vectors...`);
const vectors = await getByIds(config, args.name, args.ids);

const ids: VectorizeVectorIds = {
ids: args.ids,
};

const vectors = await getByIds(config, args.name, ids);

if (vectors.length === 0) {
logger.warn(
Expand Down
8 changes: 8 additions & 0 deletions packages/wrangler/src/vectorize/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,14 @@ export interface VectorizeVectorMutation {
count: number;
}

/**
* Request type used to pass vector ids to fetch or delete.
*/
export interface VectorizeVectorIds {
/* List of vector ids that are fetched or deleted. */
ids: string[];
}

/**
* Result type indicating a mutation on the Vectorize Index.
* Actual mutations are processed async where the `mutationId` is the unique identifier for the operation.
Expand Down

0 comments on commit b36ac37

Please sign in to comment.