Skip to content

Commit

Permalink
pg vector example code
Browse files Browse the repository at this point in the history
  • Loading branch information
omenking authored Sep 26, 2024
1 parent 059b9f2 commit f01b1c7
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions rds/pgvector/Readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
```sql
SELECT * FROM pg_available_extensions WHERE name = 'vector';
```

```sql
CREATE EXTENSION IF NOT EXISTS vector;
```

```sql
CREATE TABLE items (
id SERIAL PRIMARY KEY,
embedding vector(3) -- a vector of dimension 3
);
```

```sql
INSERT INTO items (embedding) VALUES
('[0.1, 0.2, 0.3]'),
('[0.4, 0.5, 0.6]'),
('[0.7, 0.8, 0.9]');
```

```sql
SELECT * FROM items;
```

Nearest Neighbor Search

```sql
SELECT id, embedding, embedding <-> '[0.2, 0.1, 0.4]' AS distance
FROM items
ORDER BY embedding <-> '[0.2, 0.1, 0.4]' LIMIT 5;
```

0 comments on commit f01b1c7

Please sign in to comment.