From 5986862bd2d564b5247f728a58caeed24f3e8f7e Mon Sep 17 00:00:00 2001 From: Andrew Kane Date: Sat, 4 Nov 2023 15:01:37 -0700 Subject: [PATCH] Added note about check constraint [skip ci] --- README.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/README.md b/README.md index a7cf519..bca3de8 100644 --- a/README.md +++ b/README.md @@ -442,6 +442,12 @@ CREATE TABLE items (id bigserial PRIMARY KEY, embedding double precision[]); INSERT INTO items (embedding) VALUES ('{1,2,3}'), ('{4,5,6}'); ``` +Optionally, add a [check constraint](https://www.postgresql.org/docs/current/ddl-constraints.html) to ensure data can be converted to the `vector` type and has the expected dimensions. + +```sql +ALTER TABLE items ADD CHECK (vector_dims(embedding::vector) = 3); +``` + Use [expression indexing](https://www.postgresql.org/docs/current/indexes-expressional.html) to index (at a lower precision): ```sql