Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitfe6ec03

Browse files
committed
Improved filtering section [skip ci]
1 parentc1161f8 commitfe6ec03

File tree

1 file changed

+30
-4
lines changed

1 file changed

+30
-4
lines changed

‎README.md‎

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -427,25 +427,51 @@ Note: `%` is only populated during the `loading tuples` phase
427427

428428
##Filtering
429429

430-
There are a few ways to index nearest neighbor queries with a`WHERE` clause
430+
There are a few ways to index nearest neighbor queries with a`WHERE` clause.
431431

432432
```sql
433433
SELECT*FROM itemsWHERE category_id=123ORDER BY embedding<->'[3,1,2]'LIMIT5;
434434
```
435435

436-
Createan index onone[or more](https://www.postgresql.org/docs/current/indexes-multicolumn.html)of the`WHERE` columns for exact search
436+
A good place to start is creatingan index onthe filter column. This can provide fast, exact nearest neighbor search in many cases. Postgres has a number of[index types](https://www.postgresql.org/docs/current/indexes-types.html)for this: B-tree (default), hash, GiST, SP-GiST, GIN, and BRIN.
437437

438438
```sql
439439
CREATEINDEXON items (category_id);
440440
```
441441

442-
Or a[partial index](https://www.postgresql.org/docs/current/indexes-partial.html) on the vector column for approximate search
442+
For multiple columns, consider a[multicolumn index](https://www.postgresql.org/docs/current/indexes-multicolumn.html).
443+
444+
```sql
445+
CREATEINDEXON items (store_id, category_id);
446+
```
447+
448+
Exact indexes work well for conditions that match a small fraction of rows. For larger fractions,[approximate indexes](#indexing) can work better.
449+
450+
```sql
451+
CREATEINDEXON items USING hnsw (embedding vector_l2_ops);
452+
```
453+
454+
With approximate indexes, filtering is applied after the index is scanned (known as post-filtering). If a condition matches 10% of rows, with HNSW and the default`hnsw.ef_search` of 40, only 4 rows will match on average. For more rows, increase`hnsw.ef_search`.
455+
456+
```sql
457+
SEThnsw.ef_search=200;
458+
```
459+
460+
Starting with 0.8.0, you can enable[iterative index scans](#iterative-index-scans), which will automatically scan more of the index when needed.
461+
462+
```sql
463+
SEThnsw.iterative_scan= strict_order;
464+
```
465+
466+
You can also create different approximate indexes for each value (or groups of values).
467+
468+
If filtering by a few distinct values, use[partial indexing](https://www.postgresql.org/docs/current/indexes-partial.html).
443469

444470
```sql
445471
CREATEINDEXON items USING hnsw (embedding vector_l2_ops)WHERE (category_id=123);
446472
```
447473

448-
Use[partitioning](https://www.postgresql.org/docs/current/ddl-partitioning.html) for approximate search on many different values of the`WHERE` columns
474+
If filtering by many different values, use[partitioning](https://www.postgresql.org/docs/current/ddl-partitioning.html).
449475

450476
```sql
451477
CREATETABLEitems (embedding vector(3), category_idint) PARTITION BY LIST(category_id);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp