• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 2024 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 *     http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16/**
17 * @file
18 * @kit ArkData
19 */
20
21/**
22 * Provides methods for intelligent data processing.
23 *
24 * @namespace intelligence
25 * @syscap SystemCapability.DistributedDataManager.DataIntelligence.Core
26 * @since 15
27 */
28declare namespace intelligence {
29  /**
30   * Obtains a text embedding model.
31   *
32   * @param { ModelConfig } config - The configuration of the embedding model.
33   * @returns { Promise<TextEmbedding> } The promise returned by the function.
34   * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;
35   * <br>2. Incorrect parameter types.
36   * @throws { BusinessError } 801 - Capability not supported.
37   * @throws { BusinessError } 31300000 - Inner error.
38   * @syscap SystemCapability.DistributedDataManager.DataIntelligence.Core
39   * @since 15
40   */
41  function getTextEmbeddingModel(config: ModelConfig): Promise<TextEmbedding>;
42
43  /**
44   * Obtains an image embedding model.
45   *
46   * @param { ModelConfig } config - The configuration of the embedding model.
47   * @returns { Promise<ImageEmbedding> } The promise returned by the function.
48   * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;
49   * <br>2. Incorrect parameter types.
50   * @throws { BusinessError } 801 - Capability not supported.
51   * @throws { BusinessError } 31300000 - Inner error.
52   * @syscap SystemCapability.DistributedDataManager.DataIntelligence.Core
53   * @since 15
54   */
55  function getImageEmbeddingModel(config: ModelConfig): Promise<ImageEmbedding>;
56
57  /**
58   * Manages configurations of the embedding model.
59   *
60   * @interface ModelConfig
61   * @syscap SystemCapability.DistributedDataManager.DataIntelligence.Core
62   * @since 15
63   */
64  interface ModelConfig {
65    /**
66     * Version of the model.
67     * The outputs of text or image embedding models with the same version are in the same vector space.
68     *
69     * @type { ModelVersion }
70     * @syscap SystemCapability.DistributedDataManager.DataIntelligence.Core
71     * @since 15
72     */
73    version: ModelVersion;
74
75    /**
76     * Indicates whether NPU is used.
77     *
78     * @type { boolean }
79     * @syscap SystemCapability.DistributedDataManager.DataIntelligence.Core
80     * @since 15
81     */
82    isNpuAvailable: boolean;
83
84    /**
85     * If NPU is used for accelerating, a local path is required for model caching.
86     *
87     * @type { ?string }
88     * @syscap SystemCapability.DistributedDataManager.DataIntelligence.Core
89     * @since 15
90     */
91    cachePath?: string;
92  }
93
94  /**
95   * Version of the model.
96   *
97   * @enum { number }
98   * @syscap SystemCapability.DistributedDataManager.DataIntelligence.Core
99   * @since 15
100   */
101  enum ModelVersion {
102    /**
103     * The basic embedding model.
104     *
105     * @syscap SystemCapability.DistributedDataManager.DataIntelligence.Core
106     * @since 15
107     */
108    BASIC_MODEL = 0
109  }
110
111  /**
112   * Describes the text embedding functions of the multi-modal embedding model.
113   * Chinese and English are supported.
114   *
115   * @interface TextEmbedding
116   * @syscap SystemCapability.DistributedDataManager.DataIntelligence.Core
117   * @since 15
118   */
119  interface TextEmbedding {
120    /**
121     * Loads this text embedding model. If the loading fails, an error code is returned.
122     *
123     * @returns { Promise<void> } The promise returned by the function.
124     * @throws { BusinessError } 801 - Capability not supported.
125     * @throws { BusinessError } 31300000 - Inner error.
126     * @syscap SystemCapability.DistributedDataManager.DataIntelligence.Core
127     * @since 15
128     */
129    loadModel(): Promise<void>;
130
131    /**
132     * Releases this text embedding model. If the releasing fails, an error code is returned.
133     *
134     * @returns { Promise<void> } The promise returned by the function.
135     * @throws { BusinessError } 801 - Capability not supported.
136     * @throws { BusinessError } 31300000 - Inner error.
137     * @syscap SystemCapability.DistributedDataManager.DataIntelligence.Core
138     * @since 15
139     */
140    releaseModel(): Promise<void>;
141
142    /**
143     * Obtains the embedding vector of the given text.
144     * The model can process up to 512 characters of text per inference, supporting both Chinese and English.
145     *
146     * @param { string } text - The input text of the embedding model.
147     * @returns { Promise<Array<number>> } The promise used to return the embedding result.
148     * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;
149     * <br>2. Incorrect parameter types.
150     * @throws { BusinessError } 801 - Capability not supported.
151     * @throws { BusinessError } 31300000 - Inner error.
152     * @syscap SystemCapability.DistributedDataManager.DataIntelligence.Core
153     * @since 15
154     */
155    getEmbedding(text: string): Promise<Array<number>>;
156
157    /**
158     * Obtains the embedding vector of a given batch of text.
159     * The model can process up to 512 characters of text per inference, supporting both Chinese and English.
160     *
161     * @param { Array<string> } batchTexts - The input batch of texts of the embedding model.
162     * @returns { Promise<Array<Array<number>>> } The promise used to return the embedding result.
163     * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;
164     * <br>2. Incorrect parameter types.
165     * @throws { BusinessError } 801 - Capability not supported.
166     * @throws { BusinessError } 31300000 - Inner error.
167     * @syscap SystemCapability.DistributedDataManager.DataIntelligence.Core
168     * @since 15
169     */
170    getEmbedding(batchTexts: Array<string>): Promise<Array<Array<number>>>;
171  }
172
173  /**
174   * Describes the image embedding functions of the multi-modal embedding model.
175   *
176   * @interface ImageEmbedding
177   * @syscap SystemCapability.DistributedDataManager.DataIntelligence.Core
178   * @since 15
179   */
180  interface ImageEmbedding {
181    /**
182     * Loads this image embedding model. If the loading fails, an error code is returned.
183     *
184     * @returns { Promise<void> } The promise returned by the function.
185     * @throws { BusinessError } 801 - Capability not supported.
186     * @throws { BusinessError } 31300000 - Inner error.
187     * @syscap SystemCapability.DistributedDataManager.DataIntelligence.Core
188     * @since 15
189     */
190    loadModel(): Promise<void>;
191
192    /**
193     * Releases this image embedding model. If the releasing fails, an error code is returned.
194     *
195     * @returns { Promise<void> } The promise returned by the function.
196     * @throws { BusinessError } 801 - Capability not supported.
197     * @throws { BusinessError } 31300000 - Inner error.
198     * @syscap SystemCapability.DistributedDataManager.DataIntelligence.Core
199     * @since 15
200     */
201    releaseModel(): Promise<void>;
202
203    /**
204     * Obtains the embedding vector of the given image.
205     * The model can handle images below 20 MB in size in a single inference.
206     *
207     * @param { Image } image - The input image of the embedding model.
208     * @returns { Promise<Array<number>> } The promise used to return the embedding result.
209     * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;
210     * <br>2. Incorrect parameter types.
211     * @throws { BusinessError } 801 - Capability not supported.
212     * @throws { BusinessError } 31300000 - Inner error.
213     * @syscap SystemCapability.DistributedDataManager.DataIntelligence.Core
214     * @since 15
215     */
216    getEmbedding(image: Image): Promise<Array<number>>;
217  }
218
219  /**
220   * The type of the image can be its URI.
221   *
222   * @typedef { string } Image
223   * @syscap SystemCapability.DistributedDataManager.RelationalStore.Core
224   * @since 15
225   */
226  type Image = string;
227
228  /**
229   * Splits text.
230   *
231   * @param { string } text - Text for chunking. The length of the text is no longer then 100k tokens.
232   * @param { SplitConfig } config - Configurations of text chunking.
233   * @returns { Promise<Array<string>> } The promise used to return the result.
234   * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;
235   * <br>2. Incorrect parameter types.
236   * @throws { BusinessError } 801 - Capability not supported.
237   * @throws { BusinessError } 31300000 - Inner error.
238   * @syscap SystemCapability.DistributedDataManager.DataIntelligence.Core
239   * @since 15
240   */
241  function splitText(text: string, config: SplitConfig): Promise<Array<string>>;
242
243  /**
244   * Manages text chunk process configurations.
245   *
246   * @interface SplitConfig
247   * @syscap SystemCapability.DistributedDataManager.DataIntelligence.Core
248   * @since 15
249   */
250  interface SplitConfig {
251    /**
252     * The maximun size of chunks.
253     *
254     * @type { number }
255     * @syscap SystemCapability.DistributedDataManager.DataIntelligence.Core
256     * @since 15
257     */
258    size: number;
259
260    /**
261     * The ratio of overlap between adjacent chunks.
262     *
263     * @type { number }
264     * @syscap SystemCapability.DistributedDataManager.DataIntelligence.Core
265     * @since 15
266     */
267    overlapRatio: number;
268  }
269}
270
271export default intelligence;