Commit 2a8afb9
authored
[Opt](ai-func) Improving AI function performance (#62494)
### Release note
Improving the performance of AI functions through batch sending, embed
controls the number of (text/file) items sent in a single batch through
the variable `embed_max_batch_size`, and the remaining functions
internally maintain a conservative context window.
The current sending format is similar to:
```json
"input": [
{"role": "system", "content": "system_prompt here"},
{"role": "user",
"content": [
{"idx": 1, "text": "xxx"},
{"idx": 2, "text": "xxx"},
]
}
]
```
performance:
```sql
-- AI_CLASSIFY
SELECT
COUNT(*) AS total_rows,
SUM(IF(res = 'science', 1, 0)) AS excepte_eq_res
FROM (
SELECT AI_CLASSIFY('deepseek-chat', str, ['science', 'sport']) AS res
FROM test_str
) t;
-- before
+------------+----------------+
| total_rows | excepte_eq_res |
+------------+----------------+
| 100 | 100 |
+------------+----------------+
1 row in set (2 min 11.579 sec)
-- now
+------------+----------------+
| total_rows | excepte_eq_res |
+------------+----------------+
| 100 | 100 |
+------------+----------------+
1 row in set (10.487 sec)
-- AI_FILTER
SELECT
COUNT(*) AS total_rows,
SUM(IF(res = 1, 1, 0)) AS zero_res_rows
FROM (
SELECT AI_FILTER('deepseek-chat', str) AS res
FROM test_str
) t;
-- before
+------------+---------------+
| total_rows | zero_res_rows |
+------------+---------------+
| 100 | 0 |
+------------+---------------+
1 row in set (2 min 2.979 sec)
-- now
+------------+---------------+
| total_rows | zero_res_rows |
+------------+---------------+
| 100 | 0 |
+------------+---------------+
1 row in set (5.007 sec)
-- EMBED
select count(embed('qwen-embed', str)) FROM test_str;
-- before
+---------------------------------+
| count(embed('qwen-embed', str)) |
+---------------------------------+
| 100 |
+---------------------------------+
1 row in set (4 min 4.888 sec)
-- now
set embed_max_batch_size = 10;
+---------------------------------+
| count(embed('qwen-embed', str)) |
+---------------------------------+
| 100 |
+---------------------------------+
1 row in set (23.424 sec)
-- Multimodal_Embed
SELECT COUNT(EMBED('qwen_mul_embed', to_json(file))) FROM test_jpg2;
-- before: can't get results for a long time(over 20 mins).
-- now
set embed_max_batch_size = 20;
+----------------------------------------------------+
| .... |
| 1152 |
+----------------------------------------------------+
1142 rows in set (1 min 13.577 sec)
```1 parent 1c7e71e commit 2a8afb9
22 files changed
Lines changed: 2016 additions & 512 deletions
File tree
- be
- src/exprs
- aggregate
- function/ai
- test/ai
- fe/fe-core/src
- main/java/org/apache/doris/qe
- test/java/org/apache/doris/qe
- gensrc/thrift
- regression-test/suites/ai_p0
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
29 | 29 | | |
30 | 30 | | |
31 | 31 | | |
| 32 | + | |
32 | 33 | | |
33 | 34 | | |
34 | 35 | | |
| |||
37 | 38 | | |
38 | 39 | | |
39 | 40 | | |
40 | | - | |
41 | | - | |
42 | | - | |
43 | | - | |
44 | | - | |
45 | 41 | | |
46 | 42 | | |
47 | 43 | | |
48 | 44 | | |
49 | 45 | | |
50 | | - | |
51 | | - | |
52 | | - | |
53 | | - | |
54 | | - | |
| 46 | + | |
55 | 47 | | |
56 | 48 | | |
57 | 49 | | |
| |||
64 | 56 | | |
65 | 57 | | |
66 | 58 | | |
67 | | - | |
68 | | - | |
69 | | - | |
70 | | - | |
71 | | - | |
| 59 | + | |
72 | 60 | | |
73 | 61 | | |
74 | 62 | | |
| |||
151 | 139 | | |
152 | 140 | | |
153 | 141 | | |
| 142 | + | |
154 | 143 | | |
155 | 144 | | |
156 | 145 | | |
| |||
161 | 150 | | |
162 | 151 | | |
163 | 152 | | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
164 | 157 | | |
165 | 158 | | |
166 | 159 | | |
| |||
194 | 187 | | |
195 | 188 | | |
196 | 189 | | |
197 | | - | |
198 | | - | |
199 | | - | |
200 | | - | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
201 | 195 | | |
202 | 196 | | |
203 | 197 | | |
| 198 | + | |
204 | 199 | | |
205 | | - | |
206 | | - | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
207 | 228 | | |
208 | 229 | | |
209 | 230 | | |
| |||
305 | 326 | | |
306 | 327 | | |
307 | 328 | | |
308 | | - | |
| 329 | + | |
0 commit comments