File tree Expand file tree Collapse file tree 1 file changed +21
-0
lines changed Expand file tree Collapse file tree 1 file changed +21
-0
lines changed Original file line number Diff line number Diff line change @@ -358,6 +358,25 @@ COMMIT;
358
358
* Null labels are treated as empty arrays
359
359
* Null values in label arrays are ignored
360
360
361
+ # # ORDER BY vector distance
362
+
363
+ pgvectorscale' s diskann index uses relaxed ordering which allows results to be
364
+ slightly out of order by distance. This is analogous to using
365
+ [`iterative scan with relaxed ordering`][pgvector-iterative-index-scan] with
366
+ pgvector' s ivfflat or hnsw indexes.
367
+
368
+ If you need strict ordering you can use a [materialized CTE][materialized- cte]:
369
+
370
+ ` ` ` sql
371
+ WITH relaxed_results AS MATERIALIZED (
372
+ SELECT id, embedding <=> '[1,2,3]' AS distance
373
+ FROM items
374
+ WHERE category_id = 123
375
+ ORDER BY distance
376
+ LIMIT 5
377
+ ) SELECT * FROM relaxed_results ORDER BY distance;
378
+ ` ` `
379
+
361
380
# # Get involved
362
381
363
382
pgvectorscale is still at an early stage. Now is a great time to help shape the
@@ -375,3 +394,5 @@ Timescale is a PostgreSQL cloud company. To learn more visit the [timescale.com]
375
394
[pgvector]: https://github.com/pgvector/pgvector/blob/master/README.md
376
395
[rust-language]: https://www.rust-lang.org/
377
396
[pgvector-install]: https://github.com/pgvector/pgvector?tab=readme-ov-file#installation
397
+ [pgvector-iterative-index-scan]: https://github.com/pgvector/pgvector?tab=readme-ov-file#iterative-index-scans
398
+ [materialized-cte]: https://www.postgresql.org/docs/current/queries-with.html#QUERIES-WITH-CTE-MATERIALIZATION
You can’t perform that action at this time.
0 commit comments