From 572a9ab4049dfe3ac368aef1598feea1ee8407d5 Mon Sep 17 00:00:00 2001 From: Andrew Kane Date: Sun, 27 Oct 2024 18:58:50 -0700 Subject: [PATCH] Updated readme [skip ci] --- README.md | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 8150348..384ba6d 100644 --- a/README.md +++ b/README.md @@ -485,14 +485,16 @@ WITH relaxed_results AS MATERIALIZED ( ) SELECT * FROM relaxed_results ORDER BY distance; ``` -For queries that filter by distance, use a materialized CTE and place the filter outside of it for best performance (due to the [current behavior](https://www.postgresql.org/message-id/flat/CAOdR5yGUoMQ6j7M5hNUXrySzaqZVGf_Ne%2B8fwZMRKTFxU1nbJg%40mail.gmail.com) of the Postgres executor) +For queries that filter by distance, use a materialized CTE and place the distance filter outside of it for best performance (due to the [current behavior](https://www.postgresql.org/message-id/flat/CAOdR5yGUoMQ6j7M5hNUXrySzaqZVGf_Ne%2B8fwZMRKTFxU1nbJg%40mail.gmail.com) of the Postgres executor) ```sql -WITH filtered_results AS MATERIALIZED ( - SELECT id, embedding <-> '[1,2,3]' AS distance FROM items WHERE category_id = 123 ORDER BY distance LIMIT 5 -) SELECT * FROM filtered_results WHERE distance < 0.1 ORDER BY distance; +WITH nearest_results AS MATERIALIZED ( + SELECT id, embedding <-> '[1,2,3]' AS distance FROM items ORDER BY distance LIMIT 5 +) SELECT * FROM nearest_results WHERE distance < 5 ORDER BY distance; ``` +Note: Place any other filters inside the CTE + ### Iterative Scan Options Since scanning a large portion of an approximate index is expensive, there are options to control when a scan ends