Skip to content

feat: add profile search api and tests.#35150

Merged
zitsen merged 19 commits intomainfrom
feat/corr
Apr 20, 2026
Merged

feat: add profile search api and tests.#35150
zitsen merged 19 commits intomainfrom
feat/corr

Conversation

@hjxilinx
Copy link
Copy Markdown
Contributor

@hjxilinx hjxilinx commented Apr 15, 2026

This pull request introduces a new profile searching algorithm to the analytics toolkit, providing a robust implementation for searching time series profiles using DTW (Dynamic Time Warping) and cosine similarity. It also adds a new API endpoint for profile searching , comprehensive input validation, and a suite of unit tests to ensure correctness. Additional improvements include a new Pearson correlation endpoint and enhancements to existing batch processing routes.

New profile searching algorithm and API:

  • Added do_profile_search_impl in profile_search.py implementing core logic for searching a source time series against multiple target profiles using DTW or cosine similarity, with support for normalization, sliding window, and flexible result filtering.
  • Introduced a new API endpoint /api/v1/analysis/profile-search in app.py that exposes the profile searching functionality, including input validation, error handling, and logging.

Testing and validation:

  • Added comprehensive unit tests for the profile searching logic in unit_test.py, covering DTW and cosine similarity, normalization options, windowing, thresholding, error cases, and input validation.
    API and batch processing enhancements:

  • Added a new /api/v1/analysis/pearsonr endpoint for Pearson correlation, with robust input and error handling.

  • Updated batch processing to support both legacy and versioned endpoints, improving backward compatibility.

These changes significantly enhance the toolkit's analytical capabilities, robustness, and test coverage.# Description

Issue(s)

Checklist

Please check the items in the checklist if applicable.

  • Is the user manual updated?
  • Are the test cases passed and automated?
  • Is there no significant decrease in test coverage?

Copilot AI review requested due to automatic review settings April 15, 2026 11:37
Copy link
Copy Markdown
Contributor

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

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 profile matching feature using Dynamic Time Warping (DTW) and Cosine similarity, alongside a new Pearson correlation endpoint. The changes include the core algorithm implementation, new API routes for versioned analysis, and unit tests. The review feedback identifies several areas for improvement: potential runtime errors in the Pearson correlation endpoint due to missing data or NaN results, performance inefficiencies caused by redundant data validation and large sliding window generation, and a logic issue where sequences are incorrectly truncated during cosine similarity calculations.

Comment thread tools/tdgpt/taosanalytics/app.py
Comment thread tools/tdgpt/taosanalytics/algo/tool/profile_match.py Outdated
Comment thread tools/tdgpt/taosanalytics/algo/tool/profile_search.py
Comment thread tools/tdgpt/taosanalytics/algo/tool/profile_match.py Outdated
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds new analytics capabilities to TDgpt/taosanalytics by introducing a profile-matching algorithm (DTW/cosine) and exposing it via a new REST endpoint, alongside a new Pearson correlation endpoint and accompanying unit tests.

Changes:

  • Added do_profile_match_impl (DTW/cosine similarity, normalization, windowing, top-N/threshold filtering).
  • Exposed new endpoints: /api/v1/analysis/profile-match and /api/v1/analysis/pearsonr; added a versioned batch route alias.
  • Added unit tests covering profile matching behavior and validation.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.

File Description
tools/tdgpt/taosanalytics/algo/tool/profile_match.py Implements profile matching core logic with validation, normalization, and DTW/cosine scoring.
tools/tdgpt/taosanalytics/app.py Adds new v1 endpoints for pearson correlation and profile matching; adds versioned batch route alias.
tools/tdgpt/taosanalytics/test/unit_test.py Adds unit tests for do_profile_match_impl covering key scenarios and validation errors.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread tools/tdgpt/taosanalytics/algo/tool/profile_match.py Outdated
Comment thread tools/tdgpt/taosanalytics/algo/tool/profile_match.py Outdated
Comment thread tools/tdgpt/taosanalytics/app.py Outdated
Comment thread tools/tdgpt/taosanalytics/app.py
Copilot AI review requested due to automatic review settings April 17, 2026 05:46
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 5 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread tools/tdgpt/taosanalytics/app.py
Comment thread tools/tdgpt/taosanalytics/algo/tool/profile_match.py Outdated
Comment thread tools/tdgpt/taosanalytics/algo/tool/profile_search.py
Comment thread tools/tdgpt/taosanalytics/app.py Outdated
Comment thread tools/tdgpt/taosanalytics/app.py Outdated
Copilot AI review requested due to automatic review settings April 17, 2026 06:45
@hjxilinx hjxilinx review requested due to automatic review settings April 17, 2026 06:45
Copilot AI review requested due to automatic review settings April 17, 2026 06:45
@hjxilinx hjxilinx review requested due to automatic review settings April 17, 2026 06:45
Copilot AI review requested due to automatic review settings April 17, 2026 06:46
@hjxilinx hjxilinx review requested due to automatic review settings April 17, 2026 06:46
Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 17, 2026

Just as a heads up, I was blocked by some firewall rules while working on your feedback. Expand below for details.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • download-r2.pytorch.org
    • Triggering command: /usr/bin/pip pip install -r /home/REDACTED/work/TDengine/TDengine/tools/tdgpt/requirements.txt -q (dns block)
    • Triggering command: /usr/bin/pip pip install -r /home/REDACTED/work/TDengine/TDengine/tools/tdgpt/requirements_ess.txt -q (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

@hjxilinx
Copy link
Copy Markdown
Contributor Author

@copilot extract method for validating min_window/max_widow, method for prifle_list formation, method for vaildating source_arr.

…ta, _validate_and_parse_window_params

Agent-Logs-Url: https://github.com/taosdata/TDengine/sessions/af600a70-f5ff-48a4-bfc5-b2315b0b4cd3

Co-authored-by: hjxilinx <8252296+hjxilinx@users.noreply.github.com>
Copilot AI review requested due to automatic review settings April 17, 2026 07:57
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated 5 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread tools/tdgpt/taosanalytics/algo/tool/profile_match.py Outdated
Comment thread tools/tdgpt/taosanalytics/algo/tool/profile_search.py
Comment thread tools/tdgpt/taosanalytics/test/unit_test.py
Comment thread tools/tdgpt/taosanalytics/app.py Outdated
Comment thread tools/tdgpt/taosanalytics/app.py
Copilot AI review requested due to automatic review settings April 17, 2026 09:35
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread tools/tdgpt/taosanalytics/algo/tool/profile_search.py
Comment thread tools/tdgpt/taosanalytics/test/unit_test.py Outdated
Comment thread tools/tdgpt/taosanalytics/app.py
Copilot AI review requested due to automatic review settings April 17, 2026 09:54
@hjxilinx hjxilinx review requested due to automatic review settings April 17, 2026 09:54
Copilot AI review requested due to automatic review settings April 17, 2026 10:10
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 6 out of 6 changed files in this pull request and generated 5 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread tools/tdgpt/taosanalytics/algo/tool/profile_search.py
Comment thread tools/tdgpt/taosanalytics/algo/tool/profile_search.py Outdated
Comment thread tools/tdgpt/taosanalytics/test/restful_api_test.py Outdated
Comment thread tools/tdgpt/taosanalytics/app.py
Comment thread tools/tdgpt/taosanalytics/app.py
…calar extraction; restore pearsonr error mapping

Agent-Logs-Url: https://github.com/taosdata/TDengine/sessions/631a084a-29b9-4456-b381-b16572369e6f

Co-authored-by: hjxilinx <8252296+hjxilinx@users.noreply.github.com>
Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 17, 2026

@copilot extract method for validating min_window/max_widow, method for prifle_list formation, method for vaildating source_arr.

Already done in commit 9a591df. The three helpers are present in profile_search.py: _validate_source_data, _validate_min_max_window, and _validate_profile_list. The parent _validate_params orchestrates them.

Copilot AI review requested due to automatic review settings April 17, 2026 10:48
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 6 out of 6 changed files in this pull request and generated 3 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread tools/tdgpt/taosanalytics/app.py
Comment thread tools/tdgpt/taosanalytics/test/restful_api_test.py
Comment thread tools/tdgpt/taosanalytics/algo/tool/profile_search.py Outdated
@zitsen
Copy link
Copy Markdown
Contributor

zitsen commented Apr 20, 2026

Code Review

Critical Issue: Misleading API docstring in app.pydo_profile_search

The docstring example shows ts as a flat list while data is a 2D profile list — this is an invalid combination that will mislead API consumers:

// ❌ Shown in docstring (invalid)
"target_data": {
    "ts": [1, 2, 3, 4, 5, 6],
    "data": [ [1, 2, 3, 4, 5] ]
}

When data is a list of profiles (2D), ts must be a list of [start_ts, end_ts] pairs:

// ✅ Correct format
"target_data": {
    "ts": [[1, 5]],
    "data": [ [1, 2, 3, 4, 5] ]
}

Please fix the docstring example before merging.

@zitsen
Copy link
Copy Markdown
Contributor

zitsen commented Apr 20, 2026

Code Review

Critical Issue: Misleading API docstring in app.pydo_profile_search

The docstring example shows ts as a flat list while data is a 2D profile list — this is an invalid combination that will mislead API consumers:

// ❌ Shown in docstring (invalid)
"target_data": {
    "ts": [1, 2, 3, 4, 5, 6],
    "data": [ [1, 2, 3, 4, 5] ]
}

When data is a list of profiles (2D), ts must be a list of [start_ts, end_ts] pairs:

// ✅ Correct format
"target_data": {
    "ts": [[1, 5]],
    "data": [ [1, 2, 3, 4, 5] ]
}

Please fix the docstring example before merging.

Misunderstood, approve all.

@zitsen zitsen merged commit 5c4cfaa into main Apr 20, 2026
11 checks passed
@zitsen zitsen deleted the feat/corr branch April 20, 2026 06:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants