From abd9963e66e6dfa7303b38e2ef1b43f26afcbec4 Mon Sep 17 00:00:00 2001 From: Andrew Kane Date: Wed, 3 Apr 2024 23:55:08 -0700 Subject: [PATCH] Added half vectors section [skip ci] --- README.md | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/README.md b/README.md index ffc6dd6..a96c493 100644 --- a/README.md +++ b/README.md @@ -419,6 +419,34 @@ Use [partitioning](https://www.postgresql.org/docs/current/ddl-partitioning.html CREATE TABLE items (embedding vector(3), category_id int) PARTITION BY LIST(category_id); ``` +## Half Vectors + +*Unreleased* + +Note: Half vectors require compiler support to be performant + +Use the `halfvec` type to store half-precision vectors + +```sql +CREATE TABLE items (id bigserial PRIMARY KEY, embedding halfvec(3)); +``` + +## Half Indexing + +*Unreleased* + +Index vectors at half precision for smaller indexes and faster build times + +```sql +CREATE INDEX ON items USING hnsw ((embedding::halfvec(3)) halfvec_l2_ops); +``` + +Get the nearest neighbors + +```sql +SELECT * FROM items ORDER BY embedding::halfvec(3) <-> '[1,2,3]' LIMIT 5; +``` + ## Binary Vectors Use the `bit` type to store binary vectors ([example](https://github.com/pgvector/pgvector-python/blob/master/examples/hash_image_search.py))