export async function deployIndex()

in storage-reverse-image-search/functions/src/common/vertex.ts [144:181]


export async function deployIndex(indexEndpoint: string, index: string) {
  const acceleratorType =
    AcceleratorType[config.acceleratorType as keyof typeof AcceleratorType];

  // If acceleratorType is unspecified, acceleratorCount must be undefined.
  const acceleratorCount =
    acceleratorType !== AcceleratorType.ACCELERATOR_TYPE_UNSPECIFIED
      ? config.acceleratorCount
      : undefined;

  const [operation] = await indexEndpointClient.deployIndex({
    indexEndpoint: indexEndpoint,
    deployedIndex: {
      id: `ext_${config.instanceId.replace(/-/g, '_')}_index`,
      index: index,
      dedicatedResources: {
        /** DedicatedResources machineSpec */
        machineSpec: {
          machineType: config.machineType,
          acceleratorType: acceleratorType,
          acceleratorCount: acceleratorCount,
        },

        /** DedicatedResources minReplicaCount */
        minReplicaCount: config.minReplicaCount,

        /** DedicatedResources maxReplicaCount */
        maxReplicaCount: config.maxReplicaCount,
      },
    },
  });

  if (operation.error) {
    throw new Error(operation.error.message);
  }

  return operation.name;
}