Skip to content

feat(ai): add request splitting for time series forecasting - #2874

Open
miladh wants to merge 2 commits into
ai-ts-forecasting/01-data-classesfrom
ai-ts-forecasting/02-request-splitting
Open

miladh wants to merge 2 commits into
ai-ts-forecasting/01-data-classesfrom
ai-ts-forecasting/02-request-splitting

Conversation

@miladh

@miladh miladh commented Oct 5, 2026 •

Copy link
Copy Markdown
Contributor

Stacked on #2873

Description

The forecast and impute endpoints accept at most 32 series and 5 MiB per request, counted as sent (after gzip, unless it's disabled), and a cohort must reach the model in one request. split_into_requests (in utils/_forecasting.py) packs series into requests within both limits, without splitting a cohort, and keeps their input order within each request, so the API's error locations (items[i]) match the input. The caller passes a function that measures a request body as sent; #2875 measures it with the SDK's own request serialization. A cohort with more than 32 series, or a cohort or series over 5 MiB on its own, raises ValueError before anything is sent.

This is internal and not user-facing yet; #2875 uses it.

Checklist:

  • Tests added/updated: test_utils/test_forecasting.py, including seeded randomized checks of both limits and of cohorts staying together.
  • Documentation updated: not applicable (private helper).
  • The PR title follows the Conventional Commit spec.

🤖 Generated with Claude Code

@codecov

codecov Bot commented Oct 5, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 93.18182% with 3 lines in your changes missing coverage. Please review.
⚠️ Please upload report for BASE (ai-ts-forecasting/01-data-classes@ea1105b). Learn more about missing BASE report.

Files with missing lines Patch % Lines
tests/tests_unit/test_utils/test_forecasting.py 88.46% 3 Missing ⚠️
Additional details and impacted files
@@                         Coverage Diff                          @@
##             ai-ts-forecasting/01-data-classes    #2874   +/-   ##
====================================================================
  Coverage                                     ?   93.52%           
====================================================================
  Files                                        ?      530           
  Lines                                        ?    55704           
  Branches                                     ?        0           
====================================================================
  Hits                                         ?    52097           
  Misses                                       ?     3607           
  Partials                                     ?        0           
Files with missing lines Coverage Δ
cognite/client/utils/_forecasting.py 100.00% <100.00%> (ø)
tests/tests_unit/test_utils/test_forecasting.py 88.46% <88.46%> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@miladh
miladh force-pushed the ai-ts-forecasting/02-request-splitting branch from 33d7eca to cfaa6d5 Compare November 2, 2026 11:15
@miladh
miladh force-pushed the ai-ts-forecasting/01-data-classes branch from ea1105b to 12e6a69 Compare November 2, 2026 11:15
@miladh
miladh marked this pull request as ready for review November 2, 2026 11:23
@miladh
miladh requested review from a team as code owners November 2, 2026 11:23

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a utility function split_into_requests to batch InputTimeSeries into requests of at most 256 without splitting cohorts, along with corresponding unit tests. The review feedback points out two issues: handling of empty input (which currently returns [[]] instead of []) and potential key collisions when grouping series without a cohort using integer indices. Actionable suggestions are provided to use object() as a fallback key to avoid collisions and to add a unit test verifying empty input behavior.

Comment thread cognite/client/utils/_forecasting.py Resolved
@miladh
miladh force-pushed the ai-ts-forecasting/02-request-splitting branch 2 times, most recently from b5fb7d7 to 70ed67e Compare November 5, 2026 09:23
miladh and others added 2 commits November 6, 2026 11:03
The forecast and impute endpoints accept at most 32 series and 5 MiB per
request, counted as sent (after gzip, unless it is disabled), and a cohort
must reach the model in one request. split_into_requests packs series into
requests within both limits without splitting a cohort, using a size
function from the caller, and raises before anything is sent if a cohort
or series is over a limit on its own.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Packing grouped a cohort's series together, so a request could list them
in a different order than the input. The API locates errors by position
in the request (items[i]), so those locations pointed at the wrong series.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@miladh
miladh force-pushed the ai-ts-forecasting/02-request-splitting branch from 70ed67e to c601549 Compare November 6, 2026 11:40

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant