github-actions[bot] commented on code in PR #62494:
URL: https://github.com/apache/doris/pull/62494#discussion_r3097487296
##########
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` accounting is not conservative for
JSON-heavy inputs. `build_batch_prompt()` serializes each prompt with
`rapidjson::Writer::String(...)`, so quotes, backslashes, control chars, etc.
are escaped, but this estimator only counts `prompt.size()`. A prompt full of
`"` / `\` / `
` can be much larger after escaping, so we can keep rows in one batch even
though the serialized prompt that reaches the model already exceeds the
configured byte window. That defeats the main safety guarantee of the new
session variable. Please account for escaped size (or measure the built batch
prompt directly) before deciding whether to flush.
##########
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:
This helper now applies JSON-array unpacking to every scalar text response,
not just batched prompts. That changes existing semantics for single-row
`ai_generate` / `ai_summarize` / `ai_translate` / etc.: if the model
legitimately returns the literal text `[...]`, we now either split it into
multiple rows (`expected 1 items but got N`) or fail because an element is not
a string. Before this PR those values were returned verbatim. Please move the
array parsing into the batch-only execution path (or otherwise gate it on an
explicit batch contract) instead of doing it in the generic adapter layer.
##########
regression-test/suites/ai_p0/test_ai_functions.groovy:
##########
@@ -136,6 +136,27 @@ suite("test_ai_functions") {
res = sql """SHOW RESOURCES WHERE NAME = '${embedResourceName}'"""
assertTrue(res.size() > 0)
+ sql """SET embed_max_batch_size = 1;"""
+ sql """SET ai_context_window_size = 1;"""
+ test {
+ sql """SET embed_max_batch_size = 0;"""
+ exception "embed_max_batch_size"
+ }
+ test {
+ sql """SET embed_max_batch_size = -1;"""
+ exception "embed_max_batch_size"
+ }
+ test {
+ sql """SET ai_context_window_size = 0;"""
+ exception "ai_context_window_size"
+ }
+ test {
+ sql """SET ai_context_window_size = -1;"""
+ exception "ai_context_window_size"
+ }
+ sql """UNSET VARIABLE embed_max_batch_size;"""
+ sql """UNSET VARIABLE ai_context_window_size;"""
Review Comment:
These new checks only validate `SET` constraints. Because both variables are
unset again before any AI query runs, the suite never exercises the actual
FE->thrift->BE propagation that `embed` / other AI functions depend on. A
regression where FE forgets to serialize `embed_max_batch_size` or
`ai_context_window_size`, or BE ignores them and keeps its defaults, would
still pass this suite. Please keep at least one AI query running with
non-default values so the end-to-end behavior is covered.
##########
be/src/exprs/aggregate/aggregate_function_ai_agg.h:
##########
@@ -196,14 +197,45 @@ class AggregateFunctionAIAggData {
// handle overflow situations when adding content.
bool handle_overflow(size_t additional_size) {
- if (additional_size + data.size() <= MAX_CONTEXT_SIZE) {
+ const size_t max_context_size = get_ai_context_window_size();
+ if (additional_size + data.size() <= max_context_size) {
return false;
}
process_current_context();
// check if there is still an overflow after replacement.
- return (additional_size + data.size() > MAX_CONTEXT_SIZE);
+ return (additional_size + data.size() > max_context_size);
+ }
+
Review Comment:
This reads a per-query session variable from the process-wide static `_ctx`.
`ai_agg` already had a static `QueryContext*`, but wiring
`ai_context_window_size` through it makes the cross-query bleed user-visible:
if query A and query B execute `ai_agg` concurrently with different session
values, whichever query called `set_query_context()` last controls the window
seen by both aggregators. The same static also backs timeout/resource lookup.
Please store the needed query state in the aggregate data/function instance
instead of a global pointer.
##########
be/src/exprs/aggregate/aggregate_function_ai_agg.h:
##########
@@ -196,14 +197,45 @@ class AggregateFunctionAIAggData {
// handle overflow situations when adding content.
bool handle_overflow(size_t additional_size) {
- if (additional_size + data.size() <= MAX_CONTEXT_SIZE) {
+ const size_t max_context_size = get_ai_context_window_size();
+ if (additional_size + data.size() <= max_context_size) {
Review Comment:
This overflows incorrectly on the very first row when that row alone is
larger than `ai_context_window_size`. In that case `data` is still empty,
`process_current_context()` calls `_execute_task()`, and `_execute_task()`
throws `data is empty` instead of handling/reporting the oversized input. A
simple repro is `SET ai_context_window_size = 1; SELECT ai_agg('r', 'abcd',
'summarize');`. We need a special case for `!inited` / `data.empty()` here.
--
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]