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 #793: Casting bit vectors to floating-point representations
Date: Wed, 05 Mar 2025 15:14:06 +0000
Message-ID: <gh-pgvector-pgvector-793-c2701232173@github.com> (raw)
In-Reply-To: <gh-pgvector-pgvector-793@github.com>
References: <gh-pgvector-pgvector-793@github.com>

Hi @kevinhu, you can create SQL functions for this:

```sql
CREATE FUNCTION bit_to_vector(v bit) RETURNS vector AS $$
    SELECT array_agg(get_bit(v, i) * 2 - 1) FROM generate_series(0, bit_length(v) - 1) i
$$ LANGUAGE SQL;

CREATE FUNCTION bit_to_halfvec(v bit) RETURNS halfvec AS $$
    SELECT array_agg(get_bit(v, i) * 2 - 1) FROM generate_series(0, bit_length(v) - 1) i
$$ LANGUAGE SQL;
```

and use:

```sql
SELECT bit_to_vector('101');
SELECT bit_to_halfvec('101');
```

view thread (3+ messages)  latest in thread

Message-ID: <gh-pgvector-pgvector-793-c2701232173@github.com>
Permalink:  ../gh-pgvector-pgvector-793-c2701232173@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