Init

API definition

APP_ERROR Init(int dim, int capacity, AscendMetricType metricType, int64_t resourceSize = -1) override;

Function

Initializes feature database parameters and allocates memory resources.

Input

int dim: dimension of the feature vector.

AscendMetricType metricType: feature distance category (vector inner product, Euclidean distance, and cosine similarity).

int capacity: maximum database capacity. The API allocates capacity × dim × sizeof(fp16) bytes of memory data based on the value of capacity.

int64_t resourceSize: device cache resources allocated in advance. When the retrieval interface is called, the resources can be directly used without calling aclrtmalloc to allocate memory resources, achieving optimization acceleration.

The default value is -1, indicating that cache resources (128 MB) are allocated based on the default size. You can configure the size based on the data volume of the retrieval service and the resource usage on the device.

For example, if batch of a query operation is set to 64, the database has 1 million vectors, and an FP32 value occupies four bytes, resourceSize can be set to 256,000,000 bytes (64 × 1000000 × 4). Note that the maximum cache resources can be allocated internally by the API is 4 GB.

Output

N/A

Return value

APP_ERROR: return status. For details, see Return Code Reference.

Restrictions

  • dim ∈ {32, 64, 128, 256, 384, 512, 1024}
  • metricType: Currently, IndexILFlat supports only the vector inner product distance, that is, only AscendMetricType::ASCEND_METRIC_INNER_PRODUCT is supported.
  • capacity: The upper limit of the memory that can be allocated is 12,288,000,000 bytes, and the value range of capacity is (0, 12000000].
    • For 512-dimensional base vector of the FP16 type, the maximum supported capacity is 12 million (12288000000/(512 × sizeof(fp_16))).
    • For 256-dimensional base vector of the FP16 type, the maximum capacity can only be 12 million, though memory supports a larger capacity value.
  • resourceSize: The value can be -1 or an integer in the range of [134217728, 4294967296], in bytes, which is equivalent to [128 MB, 4096 MB].