@@ -43,11 +43,7 @@ class AggregateFunctionAIAggData {
4343
4444 void add (StringRef ref) {
4545 auto delta_size = ref.size + (inited ? SEPARATOR_SIZE : 0 );
46- if (handle_overflow (delta_size)) {
47- throw Exception (ErrorCode::OUT_OF_BOUND,
48- " Failed to add data: combined context size exceeded "
49- " maximum limit even after processing" );
50- }
46+ handle_overflow (delta_size);
5147 append_data (ref.data , ref.size );
5248 }
5349
@@ -60,11 +56,7 @@ class AggregateFunctionAIAggData {
6056 _task = rhs._task ;
6157
6258 size_t delta_size = (inited ? SEPARATOR_SIZE : 0 ) + rhs.data .size ();
63- if (handle_overflow (delta_size)) {
64- throw Exception (ErrorCode::OUT_OF_BOUND,
65- " Failed to merge data: combined context size exceeded "
66- " maximum limit even after processing" );
67- }
59+ handle_overflow (delta_size);
6860
6961 if (!inited) {
7062 inited = true ;
@@ -159,7 +151,7 @@ class AggregateFunctionAIAggData {
159151 const std::string& get_task () const { return _task; }
160152
161153#ifdef BE_TEST
162- static void normalize_endpoint_for_test (TAIResource & config) { normalize_endpoint (config); }
154+ static void normalize_endpoint_for_test (AIResource & config) { normalize_endpoint (config); }
163155#endif
164156
165157private:
@@ -195,17 +187,14 @@ class AggregateFunctionAIAggData {
195187 return client->execute_post_request (request_body, &response);
196188 }
197189
198- // handle overflow situations when adding content .
199- bool handle_overflow (size_t additional_size) {
190+ // Treat the context window as a soft batching trigger instead of a hard reject .
191+ void handle_overflow (size_t additional_size) {
200192 const size_t max_context_size = get_ai_context_window_size ();
201- if (additional_size + data.size () <= max_context_size) {
202- return false ;
193+ if (additional_size + data.size () <= max_context_size || !inited ) {
194+ return ;
203195 }
204196
205197 process_current_context ();
206-
207- // check if there is still an overflow after replacement.
208- return (additional_size + data.size () > max_context_size);
209198 }
210199
211200 static size_t get_ai_context_window_size () {
@@ -214,7 +203,7 @@ class AggregateFunctionAIAggData {
214203 return static_cast <size_t >(_ctx->query_options ().ai_context_window_size );
215204 }
216205
217- static void normalize_endpoint (TAIResource & config) {
206+ static void normalize_endpoint (AIResource & config) {
218207 if (iequal (config.provider_type , " GEMINI" )) {
219208 if (!config.endpoint .ends_with (" v1" ) && !config.endpoint .ends_with (" v1beta" )) {
220209 return ;
0 commit comments