github-actions[bot] commented on code in PR #62494:
URL: https://github.com/apache/doris/pull/62494#discussion_r3092725998
##########
be/test/ai/aggregate_function_ai_agg_test.cpp:
##########
@@ -389,6 +389,59 @@ TEST_F(AggregateFunctionAIAggTest,
add_batch_single_place_multiple_calls_test) {
_agg_function->destroy(place);
}
+TEST_F(AggregateFunctionAIAggTest,
ai_context_window_size_session_variable_test) {
+ TQueryOptions query_options = create_fake_query_options();
+ query_options.__set_ai_context_window_size(8);
+ auto query_ctx = MockQueryContext::create(TUniqueId(),
ExecEnv::GetInstance(), query_options);
+ query_ctx->set_mock_ai_resource();
+ _query_ctx = query_ctx;
+ _agg_function->set_query_context(query_ctx.get());
+
+ auto resource_col = ColumnString::create();
+ auto text_col = ColumnString::create();
+ auto task_col = ColumnString::create();
+
+ resource_col->insert_data("mock_resource", 13);
+ text_col->insert_data("abcd", 4);
+ task_col->insert_data("summarize", 9);
+
+ resource_col->insert_data("mock_resource", 13);
+ text_col->insert_data("efgh", 4);
+ task_col->insert_data("summarize", 9);
+
+ std::unique_ptr<char[]> memory(new char[_agg_function->size_of_data()]);
+ AggregateDataPtr place = memory.get();
+ _agg_function->create(place);
+
+ const IColumn* columns[3] = {resource_col.get(), text_col.get(),
task_col.get()};
+ _agg_function->add(place, columns, 0, _arena);
+ _agg_function->add(place, columns, 1, _arena);
+
+ const auto& data = *reinterpret_cast<const
AggregateFunctionAIAggData*>(place);
+ std::string actual(reinterpret_cast<const char*>(data.data.data()),
data.data.size());
+ EXPECT_EQ(actual, "this is a mock response\nefgh");
Review Comment:
This assertion cannot pass with the current `handle_overflow()` logic above.
After the first overflow, `data` becomes `"this is a mock response"`, so with
`ai_context_window_size = 8` the second `add()` still overflows and throws
before `"\nefgh"` can be appended. Either the implementation needs another
change, or this test should assert the exception instead.
##########
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:
`ai_context_window_size` is supposed to be a byte limit, but this estimator
only counts raw prompt bytes plus a constant. `build_batch_prompt()`
JSON-escapes every prompt afterwards, so inputs with lots of quotes,
backslashes, or newlines can serialize well past the configured window even
though they pass this check. That means the new batching guardrail still allows
provider/context-window failures on escaping-heavy inputs.
##########
be/src/exprs/aggregate/aggregate_function_ai_agg.h:
##########
@@ -196,14 +197,45 @@ class AggregateFunctionAIAggData {
Review Comment:
With the new session-variable path this overflows on any setting smaller
than the post-summarization text. Concrete example: `ai_context_window_size =
8`, first row `abcd`, second row `efgh`. After `process_current_context()` the
mock response is `"this is a mock response"` (23 bytes), so `additional_size +
data.size()` is still `> 8` and `add()` throws before the second row can be
appended. FE currently allows values as low as 1, so this is now a reachable
regression.
##########
be/src/exprs/function/ai/ai_adapter.h:
##########
@@ -185,6 +273,7 @@ class VoyageAIAdapter : public AIAdapter {
Review Comment:
Adding `media_content_types` only on the derived `build_embedding_request()`
overloads breaks the virtual contract. The base
`AIAdapter::build_embedding_request()` at the top of this file still has the
old 2-argument signature, so every `override` here is invalid, and the existing
2-argument call sites (`embed.h`, the adapter unit tests) stop compiling.
Please update the base declaration and all overrides consistently before
switching the implementations.
##########
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:
Same issue in the EMBED text path: this batches on `prompt.size()` only, but
the provider request is JSON-encoded later. Escaping-heavy inputs (`"`, `\`,
newlines, etc.) can exceed `ai_context_window_size` after serialization even
when the raw-size check passes, so the new session variable does not actually
bound the request bytes 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]