pg.ddx.io  pgvector/pgvector GitHub issues and pull requests  
help / color / mirror / Atom feed
From: ankane (@ankane) <noreply+ankane@github.com>
To: pgvector/pgvector <noreply+pgvector-pgvector@github.com>
Subject: Re: [pgvector/pgvector] issue #991: Optimize zero-vector detection in vector_norm with early exit
Date: Wed, 24 Jun 2026 19:29:17 +0000
Message-ID: <gh-pgvector-pgvector-991-c4792913001@github.com> (raw)
In-Reply-To: <gh-pgvector-pgvector-991@github.com>
References: <gh-pgvector-pgvector-991@github.com>

Hi @zthhhhh, thanks for the suggestion.

I wouldn't expect this to have a significant impact on build or insert time, so I don't think it's worth complicating the code, but someone is welcome to submit a PR with benchmarks that shows it does significantly improve performance while adding little code/complexity.

A few other thoughts:

<strike>The approach outlined would still need to square to ensure it's non-zero.</strike> Edit: this probably isn't necessary since the norm uses a wider type.

Two other approaches would be:

1. Pass the norm to the normalize function (this is how the code originally worked before multiple types)
2. Call the normalize function, then check for all zeros

view thread (3+ messages)  latest in thread

Message-ID: <gh-pgvector-pgvector-991-c4792913001@github.com>
Permalink:  ../gh-pgvector-pgvector-991-c4792913001@github.com/

 · 


This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox