github-actions[bot] commented on code in PR #62494:
URL: https://github.com/apache/doris/pull/62494#discussion_r3108208060


##########
be/src/exprs/function/ai/ai_adapter.h:
##########
@@ -137,26 +139,68 @@ class AIAdapter {
 
     virtual Status build_embedding_request(const std::vector<std::string>& 
inputs,
                                            std::string& request_body) const {
-        return Status::NotSupported("{} does not support the Embed feature.",
-                                    _config.provider_type);
+        return embed_not_supported_status();
     }
 
-    virtual Status build_multimodal_embedding_request(MultimodalType 
/*media_type*/,
-                                                      const std::string& 
/*media_url*/,
-                                                      std::string& 
/*request_body*/) const {
+    virtual Status build_multimodal_embedding_request(
+            const std::vector<MultimodalType>& /*media_types*/,
+            const std::vector<std::string>& /*media_urls*/,
+            const std::vector<std::string>& /*media_content_types*/,
+            std::string& /*request_body*/) const {
         return Status::NotSupported("{} does not support multimodal Embed 
feature.",
                                     _config.provider_type);
     }
 
     virtual Status parse_embedding_response(const std::string& response_body,
                                             std::vector<std::vector<float>>& 
results) const {
-        return Status::NotSupported("{} does not support the Embed feature.",
-                                    _config.provider_type);
+        return embed_not_supported_status();
     }
 
 protected:
     TAIResource _config;
 
+    Status embed_not_supported_status() const {
+        return Status::NotSupported(
+                "{} does not support the Embed feature. Currently supported 
providers are "
+                "OpenAI, Gemini, Voyage, Jina, Qwen, and Minimax.",
+                _config.provider_type);
+    }
+
+    // Appends one provider-parsed text result to `results`.
+    // The adapter has already parsed the provider's outer response envelope 
before calling here.
+    // Example:
+    // provider response -> choices[0].message.content = "[\"1\",\"0\",\"1\"]"
+    // this helper       -> appends "1", "0", "1" into `results`
+    static Status append_parsed_text_result(std::string_view text,
+                                            std::vector<std::string>& results) 
{
+        size_t begin = 0;
+        size_t end = text.size();
+        while (begin < end && std::isspace(static_cast<unsigned 
char>(text[begin]))) {
+            ++begin;
+        }
+        while (begin < end && std::isspace(static_cast<unsigned char>(text[end 
- 1]))) {
+            --end;
+        }

Review Comment:
   `append_parsed_text_result()` is now shared by both the batched scalar path 
and the non-batched `ai_agg` path, so the `[` ... `]` heuristic is no longer 
safe. A concrete case: if an `ai_agg` task asks the model to return a JSON 
array string like `["a","b"]`, this helper will split it into two result items 
and `AggregateFunctionAIAggData::_execute_task()` will silently return only 
`results[0]`. In the opposite direction, a single-row batched string function 
can still accept malformed bracketed output because a parse failure falls back 
to raw text. We need separate batch-vs-scalar parsing semantics here instead of 
guessing from the returned text shape.



##########
be/src/exprs/function/ai/ai_functions.h:
##########
@@ -211,77 +212,187 @@ class AIFunction : public IFunction {
                                               });
     }
 
-    // Wrapper for executing a single LLM request
-    Status execute_single_request(const std::string& input, std::string& 
result,
-                                  const TAIResource& config, 
std::shared_ptr<AIAdapter>& adapter,
-                                  FunctionContext* context) const {
-        std::vector<std::string> inputs = {input};
-        std::vector<std::string> results;
+    // Provider-reusable helper for string-returning functions.

Review Comment:
   The new `ai_context_window_size` guard is only estimating `prompt.size() + 
20`, but `build_batch_prompt()` serializes through RapidJSON and escapes 
quotes, backslashes, newlines, etc. A batch of quote-heavy rows can stay under 
this estimate and still produce a much larger JSON payload on the wire, so the 
window check can be bypassed and provider-side context limits can still be hit. 
Can we base the flush decision on the serialized size instead of the raw string 
length?



##########
be/src/exprs/function/ai/embed.h:
##########
@@ -70,22 +70,58 @@ class FunctionEmbed : public AIFunction<FunctionEmbed> {
     static FunctionPtr create() { return std::make_shared<FunctionEmbed>(); }
 
 private:
+    static int32_t _get_embed_max_batch_size(FunctionContext* context) {
+        QueryContext* query_ctx = context->state()->get_query_ctx();
+        DORIS_CHECK(query_ctx != nullptr);
+
+        return query_ctx->query_options().embed_max_batch_size;
+    }
+
     Status _execute_text_embed(FunctionContext* context, Block& block,
                                const ColumnNumbers& arguments, uint32_t result,
                                size_t input_rows_count, const TAIResource& 
config,
                                std::shared_ptr<AIAdapter>& adapter) const {
         auto col_result = ColumnArray::create(
                 ColumnNullable::create(ColumnFloat32::create(), 
ColumnUInt8::create()));
+        std::vector<std::string> batch_prompts;
+        size_t current_batch_size = 0;
+        const int32_t max_batch_size = _get_embed_max_batch_size(context);
+        const size_t max_context_window_size =
+                static_cast<size_t>(get_ai_context_window_size(context));
 
         for (size_t i = 0; i < input_rows_count; ++i) {
             std::string prompt;
             RETURN_IF_ERROR(build_prompt(block, arguments, i, prompt));
 
-            std::vector<float> float_result;
-            RETURN_IF_ERROR(execute_single_request(prompt, float_result, 
config, adapter, context));
-            _insert_embedding_result(*col_result, float_result);
+            const size_t prompt_size = prompt.size();

Review Comment:
   The same accounting bug exists in `EMBED` text batching. 
`current_batch_size` only sums raw `prompt.size()`, but 
`build_embedding_request()` will JSON-escape each input string. Inputs with 
lots of quotes, backslashes, or newlines can therefore exceed 
`ai_context_window_size` after serialization even though this loop keeps them 
in one batch. Since this new session variable is meant to cap batch size in 
bytes, the decision here should use the serialized payload size.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to