mirror of
https://github.com/pgvector/pgvector.git
synced 2026-07-05 20:20:59 +08:00
Changed indices to start at 1 for sparse vectors to match SQL
This commit is contained in:
@@ -501,19 +501,21 @@ SELECT * FROM (
|
||||
Use the `sparsevec` type to store sparse vectors
|
||||
|
||||
```sql
|
||||
CREATE TABLE items (id bigserial PRIMARY KEY, embedding sparsevec(10));
|
||||
CREATE TABLE items (id bigserial PRIMARY KEY, embedding sparsevec(5));
|
||||
```
|
||||
|
||||
Insert vectors
|
||||
|
||||
```sql
|
||||
INSERT INTO items (embedding) VALUES ('{0:1,1:2,2:3}/10'), ('{0:4,1:5,2:6}/10');
|
||||
INSERT INTO items (embedding) VALUES ('{1:1,3:2,5:3}/5'), ('{1:4,3:5,5:6}/5');
|
||||
```
|
||||
|
||||
Note: Indices start at 1 like SQL arrays
|
||||
|
||||
Get the nearest neighbors by L2 distance
|
||||
|
||||
```sql
|
||||
SELECT * FROM items ORDER BY embedding <-> '{0:3,1:1,2:2}/10' LIMIT 5;
|
||||
SELECT * FROM items ORDER BY embedding <-> '{1:3,3:1,5:2}/5' LIMIT 5;
|
||||
```
|
||||
|
||||
## Hybrid Search
|
||||
|
||||
Reference in New Issue
Block a user