We use essential cookies for the website to function, as well as analytics cookies for analyzing and creating statistics of the website performance. To agree to the use of analytics cookies, click "Accept All". You can manage your preferences at any time by clicking "Cookie Settings" on the footer. More Information.

Only Essential Cookies
Accept All
ReferencesApplication FrameworkArkDataArkTS APIs@ohos.data.intelligence (ArkData Intelligence Platform)

@ohos.data.intelligence (ArkData Intelligence Platform)

Phone15+PC/2in115+Tablet15+TV19+Wearable18+

ArkData Intelligence Platform (AIP) provides application data vectorization, which leverages embedding models to convert multi-modal data such as unstructured text and images into semantic vectors.

NOTE

The initial APIs of this module are supported since API version 15. Updates will be marked with a superscript to indicate their earliest API version.

Modules to Import

Collapse
Word wrap
Dark theme
Copy code
  1. import { intelligence } from '@kit.ArkData';

intelligence.getTextEmbeddingModel

Phone26.0.0+PC/2in115+Tablet26.0.0+

getTextEmbeddingModel(config: ModelConfig): Promise<TextEmbedding>

Obtains a text embedding model. This API uses a promise to return the result.

System capability: SystemCapability.DistributedDataManager.DataIntelligence.Core

Device behavior differences: Before API version 26.0.0, this API is supported on PCs/2-in-1 devices. On other devices, it returns error code 801. Since API version 26.0.0, this API is supported on PCs/2-in-1 devices, phones, and tablets. On other devices, it returns error code 801.

Parameters

Expand
Name Type Mandatory Description
config ModelConfig Yes Configuration of the embedded model to obtain.

Return value

Expand
Type Description
Promise<TextEmbedding> Promise used to return the text embedding model object.

Error codes

For details about the error codes, see Universal Error Codes and AIP Error Codes.

Expand
ID Error Message
401 Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.
801 Capability not supported.
31300000 Inner error.

Example

Collapse
Word wrap
Dark theme
Copy code
  1. import { BusinessError } from '@kit.BasicServicesKit';
  2. let textConfig: intelligence.ModelConfig = {
  3. version: intelligence.ModelVersion.BASIC_MODEL,
  4. isNpuAvailable: false,
  5. cachePath: "/data"
  6. }
  7. let textEmbedding: intelligence.TextEmbedding;
  8. intelligence.getTextEmbeddingModel(textConfig)
  9. .then((data: intelligence.TextEmbedding) => {
  10. console.info("Succeeded in getting TextModel");
  11. textEmbedding = data;
  12. })
  13. .catch((err: BusinessError) => {
  14. console.error("Failed to get TextModel and code is " + err.code);
  15. })

intelligence.getSupportedCloudModel

Phone26.0.0+PC/2in126.0.0+Tablet26.0.0+

getSupportedCloudModel(): Promise<Array<CloudModelInfo>>

Obtains the supported cloud-side model information. This API uses a promise to return the result.

Since: 26.0.0

System capability: SystemCapability.DistributedDataManager.DataIntelligence.Core

Device behavior differences: This API is supported on PCs/2-in-1 devices, phones, and tablets. On other devices, it returns error code 801.

Model restriction: This API can be used only in the stage model.

Return value

Expand
Type Description
Promise<Array<CloudModelInfo>> Promise used to return the supported cloud-side model information.

Example

Collapse
Word wrap
Dark theme
Copy code
  1. intelligence.getSupportedCloudModel()
  2. .then((info: Array<intelligence.CloudModelInfo>) => {
  3. console.info("Succeeded in getting CloudModelInfo");
  4. });

intelligence.getImageEmbeddingModel

PC/2in115+

getImageEmbeddingModel(config: ModelConfig): Promise<ImageEmbedding>

Obtains an image embedding model. This API uses a promise to return the result.

System capability: SystemCapability.DistributedDataManager.DataIntelligence.Core

Device behavior differences: This API is supported on PCs/2-in-1 devices. On other devices, it returns error code 801.

Parameters

Expand
Name Type Mandatory Description
config ModelConfig Yes Configuration of the embedded model to obtain.

Return value

Expand
Type Description
Promise<ImageEmbedding> Promise used to return the image embedding model object.

Error codes

For details about the error codes, see Universal Error Codes and AIP Error Codes.

Expand
ID Error Message
401 Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.
801 Capability not supported.
31300000 Inner error.

Example

Collapse
Word wrap
Dark theme
Copy code
  1. import { BusinessError } from '@kit.BasicServicesKit';
  2. let imageConfig: intelligence.ModelConfig = {
  3. version: intelligence.ModelVersion.BASIC_MODEL,
  4. isNpuAvailable: false,
  5. cachePath: "/data"
  6. }
  7. let imageEmbedding: intelligence.ImageEmbedding;
  8. intelligence.getImageEmbeddingModel(imageConfig)
  9. .then((data: intelligence.ImageEmbedding) => {
  10. console.info("Succeeded in getting ImageModel");
  11. imageEmbedding = data;
  12. })
  13. .catch((err: BusinessError) => {
  14. console.error("Failed to get ImageModel and code is " + err.code);
  15. })

intelligence.splitText

PC/2in115+

splitText(text: string, config: SplitConfig): Promise<Array<string>>

Splits text. This API uses a promise to return the result.

System capability: SystemCapability.DistributedDataManager.DataIntelligence.Core

Device behavior differences: This API is supported on PCs/2-in-1 devices. On other devices, it returns error code 801.

Parameters

Expand
Name Type Mandatory Description
text string Yes Text to split, which can be any value.
config SplitConfig Yes Configuration for splitting the text.

Return value

Expand
Type Description
Promise<Array<string>> Promise used to return the blocks of the text.

Error codes

For details about the error codes, see Universal Error Codes and AIP Error Codes.

Expand
ID Error Message
401 Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.
801 Capability not supported.
31300000 Inner error.

Example

Collapse
Word wrap
Dark theme
Copy code
  1. import { BusinessError } from '@kit.BasicServicesKit';
  2. let splitConfig: intelligence.SplitConfig = {
  3. size: 10,
  4. overlapRatio: 0.1
  5. }
  6. let splitText = 'text';
  7. intelligence.splitText(splitText, splitConfig)
  8. .then((data: Array<string>) => {
  9. console.info("Succeeded in splitting Text");
  10. })
  11. .catch((err: BusinessError) => {
  12. console.error("Failed to split Text and code is " + err.code);
  13. })

ModelConfig

Phone15+PC/2in115+Tablet15+

Represents the configuration an embedded model.

System capability: SystemCapability.DistributedDataManager.DataIntelligence.Core

Expand
Name Type Read-Only Optional Description
version ModelVersion No No Version of the model.
isNpuAvailable boolean No No Whether to use the NPU to accelerate the vectorization process. The value true means to use the NPU, and the value false means the opposite. If this parameter is set to true but the device does not support NPUs, loading an embedding model will trigger error 31300000.
cachePath string No Yes

Local directory for model caching if the NPU is used. The value is in the /xxx/xxx/xxx format, for example, /data. The path cannot exceed 512 characters.

Default value: ""

modelInfo CloudModelInfo No Yes

Type and version information of the cloud-side model. It is configured when a text embedding model is used. Obtain the supported model information through the getSupportedCloudModel API. The default value is empty.

Since: 26.0.0

Model restriction: This API can only be used in the stage model.

networkPolicy NetworkPolicy No Yes

Network policy for downloading the cloud-side model. It is configured when a text embedding model is used. The default value is WIFI_ONLY.

Since: 26.0.0

Model restriction: This API can only be used in the stage model.

ModelVersion

Phone15+PC/2in115+Tablet15+

Enumerates the model versions.

System capability: SystemCapability.DistributedDataManager.DataIntelligence.Core

Expand
Name Value Description
BASIC_MODEL 0 Basic embedding model version.

CloudModelInfo

Phone26.0.0+PC/2in126.0.0+Tablet26.0.0+

Defines the configuration information of the cloud-side model. It is configured when a cloud-side text vector model is used. You can obtain the cloud-side model information supported by the current device by calling getSupportedCloudModel.

Since: 26.0.0

System capability: SystemCapability.DistributedDataManager.DataIntelligence.Core

Model restriction: This API can be used only in the stage model.

Expand
Name Type Read-only Optional Description
modelType string No No Model type name, for example, "arkdata_text_embedding": cloud-side text vector model.
modelVersionCode string No Yes Model version. The default value is empty.

NetworkPolicy

Phone26.0.0+PC/2in126.0.0+Tablet26.0.0+

Enumerates the network policies for downloading cloud-side models.

Since: 26.0.0

System capability: SystemCapability.DistributedDataManager.DataIntelligence.Core

Model restriction: This API can be used only in the stage model.

Expand
Name Value Description
WIFI_ONLY 0 Downloads the model only over Wi-Fi.
WIFI_AND_CELLULAR 1 Downloads the model over Wi-Fi and cellular networks.

Image

Phone15+PC/2in115+Tablet15+TV19+Wearable18+

type Image = string

Represents the URI of an image, which is of the string type.

System capability: SystemCapability.DistributedDataManager.RelationalStore.Core

Expand
Type Description
string Image URI, which cannot exceed 512 characters.

SplitConfig

Phone15+PC/2in115+Tablet15+

Represents the configuration for text splitting.

System capability: SystemCapability.DistributedDataManager.DataIntelligence.Core

Expand
Name Type Read-Only Optional Description
size number No No Maximum size of a block. The value is a non-negative integer.
overlapRatio number No No

Overlap ratio between adjacent blocks.

Value range: [0,1]

The value 0 indicates the lowest overlap ratio, and 1 indicates the highest overlap ratio.

TextEmbedding

Phone15+PC/2in115+Tablet15+

Provides APIs for manipulating text embedding models.

Before calling any of the following APIs, you must obtain a TextEmbedding instance by using intelligence.getTextEmbeddingModel.

System capability: SystemCapability.DistributedDataManager.DataIntelligence.Core

Device behavior differences: This API is supported on phones, PCs/2-in-1 devices, and tablets. On other devices, it returns error code 801.

loadModel

Phone26.0.0+PC/2in115+Tablet26.0.0+

loadModel(): Promise<void>

Loads this text embedding model. This API uses a promise to return the result.

System capability: SystemCapability.DistributedDataManager.DataIntelligence.Core

Device behavior differences: Before API version 26.0.0, this API is supported on PCs/2-in-1 devices. On other devices, it returns error code 801. Since API version 26.0.0, this API is supported on PCs/2-in-1 devices, phones, and tablets. On other devices, it returns error code 801.

Return value

Expand
Type Description
Promise<void> Promise that returns no value.

Error codes

For details about the error codes, see Universal Error Codes and AIP Error Codes.

Expand
ID Error Message
801 Capability not supported.
31300000 Inner error.

Example

Collapse
Word wrap
Dark theme
Copy code
  1. import { BusinessError } from '@kit.BasicServicesKit';
  2. textEmbedding.loadModel()
  3. .then(() => {
  4. console.info("Succeeded in loading Model");
  5. })
  6. .catch((err: BusinessError) => {
  7. console.error("Failed to load Model and code is " + err.code);
  8. })

releaseModel

Phone26.0.0+PC/2in115+Tablet26.0.0+

releaseModel(): Promise<void>

Releases this text embedding model. This API uses a promise to return the result.

System capability: SystemCapability.DistributedDataManager.DataIntelligence.Core

Device behavior differences: Before API version 26.0.0, this API is supported on PCs/2-in-1 devices. On other devices, it returns error code 801. Since API version 26.0.0, this API is supported on PCs/2-in-1 devices, phones, and tablets. On other devices, it returns error code 801.

Return value

Expand
Type Description
Promise<void> Promise that returns no value.

Error codes

For details about the error codes, see Universal Error Codes and AIP Error Codes.

Expand
ID Error Message
801 Capability not supported.
31300000 Inner error.

Example

Collapse
Word wrap
Dark theme
Copy code
  1. import { BusinessError } from '@kit.BasicServicesKit';
  2. textEmbedding.releaseModel()
  3. .then(() => {
  4. console.info("Succeeded in releasing Model");
  5. })
  6. .catch((err: BusinessError) => {
  7. console.error("Failed to release Model and code is " + err.code);
  8. })

getEmbedding

Phone26.0.0+PC/2in115+Tablet26.0.0+

getEmbedding(text: string): Promise<Array<number>>

Obtains the embedding vector of the given text. This API uses a promise to return the result.

Before calling this API, ensure that an embedding model is successfully loaded by using loadModel.

System capability: SystemCapability.DistributedDataManager.DataIntelligence.Core

Device behavior differences: Before API version 26.0.0, this API is supported on PCs/2-in-1 devices. On other devices, it returns error code 801. Since API version 26.0.0, this API is supported on PCs/2-in-1 devices, phones, and tablets. On other devices, it returns error code 801.

Parameters

Expand
Name Type Mandatory Description
text string Yes Text for the embedding model, which cannot exceed 512 characters.

Return value

Expand
Type Description
Promise<Array<number>> Promise used to return the vectorization result.

Error codes

For details about the error codes, see Universal Error Codes and AIP Error Codes.

Expand
ID Error Message
401 Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.
801 Capability not supported.
31300000 Inner error.

Example

Collapse
Word wrap
Dark theme
Copy code
  1. import { BusinessError } from '@kit.BasicServicesKit';
  2. textEmbedding.loadModel();
  3. let text = 'text';
  4. textEmbedding.getEmbedding(text)
  5. .then((data: Array<number>) => {
  6. console.info("Succeeded in getting Embedding");
  7. })
  8. .catch((err: BusinessError) => {
  9. console.error("Failed to get Embedding and code is " + err.code);
  10. })

getEmbedding

Phone26.0.0+PC/2in115+Tablet26.0.0+

getEmbedding(batchTexts: Array<string>): Promise<Array<Array<number>>>

Obtains the embedding vector of a given batch of texts. This API uses a promise to return the result.

Before calling this API, ensure that an embedding model is successfully loaded by using loadModel.

System capability: SystemCapability.DistributedDataManager.DataIntelligence.Core

Device behavior differences: Before API version 26.0.0, this API is supported on PCs/2-in-1 devices. On other devices, it returns error code 801. Since API version 26.0.0, this API is supported on PCs/2-in-1 devices, phones, and tablets. On other devices, it returns error code 801.

Parameters

Expand
Name Type Mandatory Description
batchTexts Array<string> Yes Batch of texts, each of which cannot exceed 512 characters.

Return value

Expand
Type Description
Promise<Array<Array<number>>> Promise used to return the vectorization result.

Error codes

For details about the error codes, see Universal Error Codes and AIP Error Codes.

Expand
ID Error Message
401 Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.
801 Capability not supported.
31300000 Inner error.

Example

Collapse
Word wrap
Dark theme
Copy code
  1. import { BusinessError } from '@kit.BasicServicesKit';
  2. textEmbedding.loadModel();
  3. let batchTexts = ['text1', 'text2'];
  4. textEmbedding.getEmbedding(batchTexts)
  5. .then((data: Array<Array<number>>) => {
  6. console.info("Succeeded in getting Embedding");
  7. })
  8. .catch((err: BusinessError) => {
  9. console.error("Failed to get Embedding and code is " + err.code);
  10. })

ImageEmbedding

PC/2in115+

Provides APIs for manipulating image embedding models.

Before calling any of the following APIs, you must obtain an ImageEmbedding instance by using intelligence.getImageEmbeddingModel.

System capability: SystemCapability.DistributedDataManager.DataIntelligence.Core

loadModel

PC/2in115+

loadModel(): Promise<void>

Loads this image embedding model. This API uses a promise to return the result.

System capability: SystemCapability.DistributedDataManager.DataIntelligence.Core

Device behavior differences: This API is supported on PCs/2-in-1 devices. On other devices, it returns error code 801.

Return value

Expand
Type Description
Promise<void> Promise that returns no value.

Error codes

For details about the error codes, see Universal Error Codes and AIP Error Codes.

Expand
ID Error Message
801 Capability not supported.
31300000 Inner error.

Example

Collapse
Word wrap
Dark theme
Copy code
  1. import { BusinessError } from '@kit.BasicServicesKit';
  2. imageEmbedding.loadModel()
  3. .then(() => {
  4. console.info("Succeeded in loading Model");
  5. })
  6. .catch((err: BusinessError) => {
  7. console.error("Failed to load Model and code is " + err.code);
  8. })

releaseModel

PC/2in115+

releaseModel(): Promise<void>

Releases this image embedding model. This API uses a promise to return the result.

System capability: SystemCapability.DistributedDataManager.DataIntelligence.Core

Device behavior differences: This API is supported on PCs/2-in-1 devices. On other devices, it returns error code 801.

Return value

Expand
Type Description
Promise<void> Promise that returns no value.

Error codes

For details about the error codes, see Universal Error Codes and AIP Error Codes.

Expand
ID Error Message
801 Capability not supported.
31300000 Inner error.

Example

Collapse
Word wrap
Dark theme
Copy code
  1. import { BusinessError } from '@kit.BasicServicesKit';
  2. imageEmbedding.releaseModel()
  3. .then(() => {
  4. console.info("Succeeded in releasing Model");
  5. })
  6. .catch((err: BusinessError) => {
  7. console.error("Failed to release Model and code is " + err.code);
  8. })

getEmbedding

PC/2in115+

getEmbedding(image: Image): Promise<Array<number>>

Obtains the embedding vector of the given image. This API uses a promise to return the result.

Before calling this API, ensure that an embedding model is successfully loaded by using loadModel.

System capability: SystemCapability.DistributedDataManager.DataIntelligence.Core

Device behavior differences: This API is supported on PCs/2-in-1 devices. On other devices, it returns error code 801.

Parameters

Expand
Name Type Mandatory Description
image Image Yes URI of the input image of the embedding model.

Return value

Expand
Type Description
Promise<Array<number>> Promise used to return the vectorization result.

Error codes

For details about the error codes, see Universal Error Codes and AIP Error Codes.

Expand
ID Error Message
401 Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.
801 Capability not supported.
31300000 Inner error.

Example

Collapse
Word wrap
Dark theme
Copy code
  1. import { BusinessError } from '@kit.BasicServicesKit';
  2. imageEmbedding.loadModel();
  3. let image = 'file://<packageName>/data/storage/el2/base/haps/entry/files/xxx.jpg';
  4. imageEmbedding.getEmbedding(image)
  5. .then((data: Array<number>) => {
  6. console.info("Succeeded in getting Embedding");
  7. })
  8. .catch((err: BusinessError) => {
  9. console.error("Failed to get Embedding and code is " + err.code);
  10. })
Search in References
Enter a keyword.