Added note about check constraint [skip ci]

This commit is contained in:
Andrew Kane
2023-11-04 15:01:37 -07:00
parent 5d24f5d09a
commit 5986862bd2

View File

@@ -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