Skip to content

Commit f3de487

Browse files
committed
Started readme updates [skip ci]
1 parent 721d4b7 commit f3de487

File tree

1 file changed

+57
-0
lines changed

1 file changed

+57
-0
lines changed

README.md

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -445,6 +445,63 @@ Use [partitioning](https://www.postgresql.org/docs/current/ddl-partitioning.html
445445
CREATE TABLE items (embedding vector(3), category_id int) PARTITION BY LIST(category_id);
446446
```
447447

448+
## Streaming Queries [unreleased]
449+
450+
*Added in 0.8.0*
451+
452+
With approximate indexes, you can end up with less results than expected due to filtering conditions in the query.
453+
454+
Starting with 0.8.0, you can enable streaming queries. If too few results from the initial index scan match the query filters, it will resume scanning until enough results are found. This can significantly improve recall (at the cost of speed).
455+
456+
```tsql
457+
SET hnsw.streaming = on;
458+
-- or
459+
SET ivfflat.streaming = off;
460+
```
461+
462+
### Streaming Options
463+
464+
Since scanning a large portion of the index is expensive, there are options to control when the scan ends.
465+
466+
#### HNSW
467+
468+
Specify the max number of additional tuples visited
469+
470+
```sql
471+
SET hnsw.ef_stream = 10000;
472+
```
473+
474+
The scan will also end if reaches `work_mem`, at which point a notice is shown
475+
476+
```text
477+
NOTICE: hnsw iterative search exceeded work_mem after 50000 tuples
478+
HINT: Increase work_mem to scan more tuples.
479+
```
480+
481+
Adjust this with:
482+
483+
```sql
484+
SET work_mem = '8MB';
485+
```
486+
487+
#### IVFFlat
488+
489+
Specify the max number of probes
490+
491+
```sql
492+
SET ivfflat.max_probes = 100;
493+
```
494+
495+
### Streaming Order
496+
497+
With streaming queries, it’s possible for rows to be slightly out of order by distance. For strict ordering, use:
498+
499+
```sql
500+
WITH approx_order AS MATERIALIZED (
501+
SELECT *, embedding <-> '[1,2,3]' AS distance FROM items WHERE ... ORDER BY distance LIMIT 5
502+
) SELECT * FROM query ORDER BY distance;
503+
```
504+
448505
## Half-Precision Vectors
449506

450507
*Added in 0.7.0*

0 commit comments

Comments
 (0)