General Description

The C++ interface of the mxIndex feature retrieval component FeatureRetrieval complies with the exception handling mechanism of the open-source Faiss interface. Therefore, you must invoke the interface and handle exceptions in the try / catch statement block. For details, see the handling methods in Code Reference. This prevents the program from exiting due to exceptions.

FeatureRetrieval inherits indexes from Faiss and supports multiple retrieval indexes. It provides APIs for creating, querying, and deleting libraries. Figure 1 and Figure 2 show the inheritance relationship between APIs.

Figure 1 Inheritance relationship between some AscendIndexConfig APIs
Figure 2 Inheritance relationship between some AscendIndex APIs
  • Some input of FeatureRetrieval is of the pointer type. Therefore, you need to ensure that pointers have a valid value to prevent potential risks and problems such as out-of-bounds read and write during the running of FeatureRetrieval. In addition, FeatureRetrieval assists the Ascend AI Processors in vector retrieval and calculation. Therefore, ensure that the entered device ID is valid. Otherwise, the function may fail due to the device connection failure.
  • Currently, a single device can be used by only one host process. When a device is occupied by a process, other retrieval processes fail to connect to this device. Wait for 20 seconds and reconnect to the device. If the connection still fails after five attempts, the program reports an error and exits.
  • Faiss is a vector retrieval acceleration library widely used in the industry. To help ecosystem users quickly migrate vector retrieval and clustering services from the CPU/GPU platform to the Ascend platform, the base class AscendIndex of many algorithms on the Ascend platform is inherited from the faiss::Index class. Member variables such as d and ntotal in the faiss::Index class are public. When using the subclasses of AscendIndex and AscendIndexInt8, do not modify these public member variables.
  • This document does not describe the member functions and variables of the base class faiss::Index.
  • resources in the Config class (resourceSize or other similar names are also used in some classes.) reserves the memory, in byte, for storing intermediate results during feature retrieval. Increase the value, if the base library is large (for example, if it has more than 3 million features) and the number of query requests is large. This prevents performance jitter caused by temporary memory allocation during retrieval. You are advised to set the value to 1024 x 1024 x 1024 bytes.

    When a new index is created, a comparison is performed between it and allocated resources. If there is any difference, the original memory resources will be destroyed, and new memory resources will be allocated based on the resources variable of the latest index. Therefore, ensure that all values of resources of the indexes are the same.