mirror of
https://github.com/pgvector/pgvector.git
synced 2026-07-13 16:16:56 +08:00
Moved section [skip ci]
This commit is contained in:
32
README.md
32
README.md
@@ -55,6 +55,22 @@ Also supports inner product (`<#>`) and cosine distance (`<=>`)
|
|||||||
|
|
||||||
Note: `<#>` returns the negative inner product since Postgres only supports `ASC` order index scans on operators
|
Note: `<#>` returns the negative inner product since Postgres only supports `ASC` order index scans on operators
|
||||||
|
|
||||||
|
## Querying
|
||||||
|
|
||||||
|
Use a `SELECT` clause to get the distance
|
||||||
|
|
||||||
|
```sql
|
||||||
|
SELECT embedding <-> '[3,1,2]' AS distance FROM items;
|
||||||
|
```
|
||||||
|
|
||||||
|
Use a `WHERE` clause to get rows within a certain distance
|
||||||
|
|
||||||
|
```sql
|
||||||
|
SELECT * FROM items WHERE embedding <-> '[3,1,2]' < 5;
|
||||||
|
```
|
||||||
|
|
||||||
|
Note: Combine with `ORDER BY` and `LIMIT` to use an index
|
||||||
|
|
||||||
## Indexing
|
## Indexing
|
||||||
|
|
||||||
Speed up queries with an approximate index. Add an index for each distance function you want to use.
|
Speed up queries with an approximate index. Add an index for each distance function you want to use.
|
||||||
@@ -145,22 +161,6 @@ To index many different values of `category_id`, consider [partitioning](https:/
|
|||||||
CREATE TABLE items (embedding vector(3), category_id int) PARTITION BY LIST(category_id);
|
CREATE TABLE items (embedding vector(3), category_id int) PARTITION BY LIST(category_id);
|
||||||
```
|
```
|
||||||
|
|
||||||
## Querying
|
|
||||||
|
|
||||||
Use a `SELECT` clause to get the distance
|
|
||||||
|
|
||||||
```sql
|
|
||||||
SELECT embedding <-> '[3,1,2]' AS distance FROM items;
|
|
||||||
```
|
|
||||||
|
|
||||||
Use a `WHERE` clause to get rows within a certain distance
|
|
||||||
|
|
||||||
```sql
|
|
||||||
SELECT * FROM items WHERE embedding <-> '[3,1,2]' < 100;
|
|
||||||
```
|
|
||||||
|
|
||||||
Note: Combine with `ORDER BY` and `LIMIT` to use an index
|
|
||||||
|
|
||||||
## Performance
|
## Performance
|
||||||
|
|
||||||
To speed up queries without an index, increase `max_parallel_workers_per_gather`.
|
To speed up queries without an index, increase `max_parallel_workers_per_gather`.
|
||||||
|
|||||||
Reference in New Issue
Block a user