Skip to content

Make normalized tensor shortcuts explicit - #9513

Draft
connortsui20 wants to merge 1 commit into
developfrom
ct/norm-compute-mode
Draft

Make normalized tensor shortcuts explicit#9513
connortsui20 wants to merge 1 commit into
developfrom
ct/norm-compute-mode

Conversation

@connortsui20

Copy link
Copy Markdown
Member

Rationale for this change

Normalized is a physical encoding whose direction is only approximately unit length, so trusting it belongs to scalar-function policy instead of a logical UnitVector dtype.

What changes are included in this PR?

Adds NormMode::{Exact, AssumeNormalized} to cosine similarity and L2 norm. Exact mode measures physical direction norms, while assumed mode retains the current shortcut; both modes persist, and legacy metadata keeps its existing behavior.

What APIs are changed? Are there any user-facing changes?

CosineSimilarity::try_new, L2Norm::try_new, and build_similarity_search_tree now require an explicit NormMode. This adds no logical dtype or Arrow extension type.

@connortsui20 connortsui20 added the changelog/break A breaking API change label Aug 20, 2026
@codspeed-hq

codspeed-hq Bot commented Aug 20, 2026

Copy link
Copy Markdown

Merging this PR will degrade performance by 7.36%

⚠️ Unknown Walltime execution environment detected

Using the Walltime instrument on standard Hosted Runners will lead to inconsistent data.

For the most accurate results, we recommend using CodSpeed Macro Runners: bare-metal machines fine-tuned for performance measurement consistency.

⚡ 2 improved benchmarks
❌ 3 regressed benchmarks
✅ 1951 untouched benchmarks
🆕 12 new benchmarks
⏩ 442 skipped benchmarks1

Warning

Please fix the performance issues or acknowledge them on CodSpeed.

Performance Changes

Mode Benchmark BASE HEAD Efficiency
Simulation column_x_extension_constant[256] 650.4 µs 834 µs -22.01%
Simulation column_x_extension_constant[2] 290.9 µs 355.4 µs -18.16%
Simulation column_x_extension_constant[32] 230 µs 273 µs -15.72%
WallTime words_gather_scalar[65536] 9.4 µs 8.3 µs +13.39%
Simulation compress_fsst[(500, 64, 8)] 585.9 µs 523.7 µs +11.88%
🆕 Simulation normalized_assume[2] N/A 159.3 µs N/A
🆕 Simulation normalized_assume[256] N/A 84.2 µs N/A
🆕 Simulation normalized_assume[32] N/A 88.2 µs N/A
🆕 Simulation normalized_exact[2] N/A 261.7 µs N/A
🆕 Simulation normalized_exact[256] N/A 113.7 µs N/A
🆕 Simulation normalized_exact[32] N/A 120.4 µs N/A
🆕 Simulation normalized_assume[2] N/A 36.6 µs N/A
🆕 Simulation normalized_assume[256] N/A 25 µs N/A
🆕 Simulation normalized_assume[32] N/A 25 µs N/A
🆕 Simulation normalized_exact[2] N/A 847.6 µs N/A
🆕 Simulation normalized_exact[256] N/A 232.8 µs N/A
🆕 Simulation normalized_exact[32] N/A 267.8 µs N/A

Tip

Investigate this regression by commenting @codspeedbot fix this regression on this PR, or directly use the CodSpeed MCP with your agent.


Comparing ct/norm-compute-mode (76656f1) with develop (9876921)

Open in CodSpeed

Footnotes

  1. 442 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

Signed-off-by: Connor Tsui <connor.tsui20@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

changelog/break A breaking API change

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant