Skip to content

refactor: replace excluded_contained with exclude_overlap for profile search.#35274

Open
hjxilinx wants to merge 8 commits intomainfrom
feat/overlap
Open

refactor: replace excluded_contained with exclude_overlap for profile search.#35274
hjxilinx wants to merge 8 commits intomainfrom
feat/overlap

Conversation

@hjxilinx
Copy link
Copy Markdown
Contributor

Description

This pull request replaces the previous "exclude_contained" feature with a new, more general "exclude_overlap" option for profile search, and updates the implementation, documentation, and tests accordingly. The "exclude_overlap" feature now works for all algorithms (not just DTW) and excludes any matched profiles whose time windows overlap with better-ranked results, rather than only strictly contained windows.

Feature and Logic Updates:

  • Replaced the "exclude_contained" option with a new "exclude_overlap" option in both API and internal logic, making it applicable to all algorithms (not just DTW). The new logic excludes any overlapping time windows, not just strictly contained ones.
  • Updated the filtering function: replaced _filter_exclude_contained with _filter_exclude_overlap, which uses a new _is_interval_overlapping helper to determine overlap (adjacent windows are not considered overlapping).

API and Documentation:

  • Updated API documentation and example requests to use "exclude_overlap" instead of "exclude_contained", and clarified its behavior in the docstring.

Test Suite Updates:

  • Replaced and expanded unit tests to verify the new "exclude_overlap" logic, including cases for partial overlap, non-overlapping windows, adjacent windows, and applicability to both DTW and cosine similarity algorithms.

Codebase Maintenance:

  • Updated variable names, comments, and retry/oversampling logic to refer to the new "exclude_overlap" filter instead of the old containment logic.

These changes improve the flexibility and clarity of the exclusion filter in profile search, making it more broadly useful and easier to understand.

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?

… search.

Co-authored-by: Copilot <copilot@github.com>
Copilot AI review requested due to automatic review settings April 30, 2026 08:54
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 replaces the algorithm-specific exclude_contained filter with a more general exclude_overlap feature, extending its availability to all search algorithms including cosine similarity. The implementation includes new overlap detection logic, updated parameter validation, and a refined retry loop for result oversampling. Valid feedback points out the need to clarify in the docstrings that adjacent windows are not considered overlapping, suggests renaming the _CONTAINMENT_OVERSAMPLE constant for consistency with the new terminology, and identifies a redundant slicing operation that can be removed.

Comment thread tools/tdgpt/taosanalytics/algo/tool/profile_search.py
Comment thread tools/tdgpt/taosanalytics/algo/tool/profile_search.py
Comment thread tools/tdgpt/taosanalytics/algo/tool/profile_search.py
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

This PR updates the profile-search “exclusion” feature by replacing the former exclude_contained option with a more general exclude_overlap option, and updates the implementation, API docs, and unit tests to match the new behavior.

Changes:

  • Replaced exclude_contained with exclude_overlap in request parsing/validation and search result filtering.
  • Implemented overlap-based greedy filtering via _is_interval_overlapping + _filter_exclude_overlap, and applied it across algorithms (DTW + cosine).
  • Updated API documentation and expanded unit tests to cover overlap/adjacency behavior and non-DTW applicability.

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_search.py Adds overlap-based exclusion filter, wires it into scoring/heap retry logic, and updates result parameter handling.
tools/tdgpt/taosanalytics/app.py Updates profile-search API docstring/example request to use exclude_overlap.
tools/tdgpt/taosanalytics/test/unit_test.py Renames/expands tests to validate overlap exclusion (partial overlap, adjacency non-overlap, cosine support, retry underfill).

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

Comment thread tools/tdgpt/taosanalytics/algo/tool/profile_search.py Outdated
Comment thread tools/tdgpt/taosanalytics/app.py Outdated
Comment thread tools/tdgpt/taosanalytics/algo/tool/profile_search.py
Comment thread tools/tdgpt/taosanalytics/algo/tool/profile_search.py Outdated
Copilot AI review requested due to automatic review settings April 30, 2026 09:28
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 3 comments.


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

Comment on lines 388 to 393
has_threshold, top_n = _validate_result_constraints(result_obj, algo_type)
source_arr, source_ts_window = _parse_source_data(parsed_input["source_data"])

exclude_contained = _validate_bool_field(result_obj, "exclude_contained")
if algo_type != "dtw" and "exclude_contained" in result_obj:
raise ValueError('"result.exclude_contained" can only be set for dtw algorithm')

exclude_source = _validate_bool_field(result_obj, "exclude_source")
exclude_overlap = _validate_bool_field(result_obj, "exclude_overlap")

Copy link

Copilot AI Apr 30, 2026

Choose a reason for hiding this comment

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

The refactor removes handling for the legacy result.exclude_contained field, but _validate_params also doesn’t reject it. Requests that still send exclude_contained will be silently accepted and the exclusion behavior won’t be applied. Consider either treating exclude_contained as an alias for exclude_overlap (backward compatibility) or raising a clear ValueError telling clients to migrate.

Copilot uses AI. Check for mistakes.
Comment thread tools/tdgpt/taosanalytics/algo/tool/profile_search.py
Comment thread tools/tdgpt/taosanalytics/app.py Outdated
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings April 30, 2026 09:52
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 2 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
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings April 30, 2026 10:25
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
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 1 comment.


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

Comment thread tools/tdgpt/taosanalytics/test/unit_test.py Outdated
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings April 30, 2026 10:32
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 1 comment.


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

"ts": [[1, 3], [2, 4], [10, 12]],
"data": [
[2, 0, -2], # cosine similarity 1.0 (best)
[1, 0, -1], # cosine similarity 1.0, overlaps with [1,3] → excluded
Copy link

Copilot AI Apr 30, 2026

Choose a reason for hiding this comment

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

This cosine test relies on two candidates having (effectively) equal similarity (both intended as 1.0). Small floating-point differences in np.linalg.norm/division can reorder ties across platforms, which could make [2,4] rank ahead of [1,3] and flip which window gets excluded. To make the test deterministic, use an overlapping candidate with a strictly lower similarity than the best match (or explicitly assert and document the tie-break behavior).

Suggested change
[1, 0, -1], # cosine similarity 1.0, overlaps with [1,3] → excluded
[1, 0, 0], # cosine similarity 1/sqrt(2), overlaps with [1,3] → excluded

Copilot uses AI. Check for mistakes.
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.

3 participants