From 9b5a1a69db5ef889752de54f4c04888659b7023d Mon Sep 17 00:00:00 2001 From: Andrew Kane Date: Fri, 3 Nov 2023 23:43:47 -0700 Subject: [PATCH] Updated readme [skip ci] --- README.md | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index d0235f6..26fcab0 100644 --- a/README.md +++ b/README.md @@ -413,16 +413,22 @@ You’ll need to use [dimensionality reduction](https://en.wikipedia.org/wiki/Di #### Can I store vectors with different dimensions in the same column? -You can use the `vector` type (instead of `vector(3)`). However, you can only create indexes on rows with the same number of dimensions (using [expression](https://www.postgresql.org/docs/current/indexes-expressional.html) and [partial](https://www.postgresql.org/docs/current/indexes-partial.html) indexing). +You can use `vector` as the type (instead of `vector(3)`). ```sql -CREATE INDEX ON items USING hnsw ((embedding::vector(3)) vector_l2_ops) WHERE (model_id = 123); +CREATE TABLE embeddings (item_id bigint, model_id bigint, embedding vector); ``` -and +However, you can only create indexes on rows with the same number of dimensions (using [expression](https://www.postgresql.org/docs/current/indexes-expressional.html) and [partial](https://www.postgresql.org/docs/current/indexes-partial.html) indexing): ```sql -SELECT * FROM items WHERE model_id = 123 ORDER BY embedding::vector(3) <-> '[3,1,2]' LIMIT 5; +CREATE INDEX ON embeddings USING hnsw ((embedding::vector(3)) vector_l2_ops) WHERE (model_id = 123); +``` + +and query with: + +```sql +SELECT * FROM embeddings WHERE model_id = 123 ORDER BY embedding::vector(3) <-> '[3,1,2]' LIMIT 5; ``` #### Can I store vectors with more precision?