Skip to content

Commit

Permalink
Added docs for enabling extension
Browse files Browse the repository at this point in the history
  • Loading branch information
ankane committed Sep 18, 2023
1 parent acbc768 commit 2b0a125
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
10 changes: 8 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,16 @@ Follow the instructions for your database library:

## DBD::Pg

Enable the extension

```perl
$dbh->do('CREATE EXTENSION IF NOT EXISTS vector');
```

Create a table

```perl
$dbh->do('CREATE TABLE items (embedding vector(3))');
$dbh->do('CREATE TABLE items (id bigserial PRIMARY KEY, embedding vector(3))');
```

Insert vectors
Expand All @@ -41,7 +47,7 @@ my $sth = $dbh->prepare('SELECT * FROM items ORDER BY embedding <-> $1 LIMIT 5')
my @embedding = (1, 1, 1);
$sth->execute(vector(\@embedding));
while (my @row = $sth->fetchrow_array()) {
print($row[0] . "\n");
print($row[1] . "\n");
}
```

Expand Down
4 changes: 2 additions & 2 deletions example.pl
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

$dbh->do('CREATE EXTENSION IF NOT EXISTS vector');
$dbh->do('DROP TABLE IF EXISTS items');
$dbh->do('CREATE TABLE items (embedding vector(3))');
$dbh->do('CREATE TABLE items (id bigserial PRIMARY KEY, embedding vector(3))');

sub vector {
return '[' . join(',', @{$_[0]}) . ']';
Expand All @@ -20,7 +20,7 @@ sub vector {
my @embedding = (1, 1, 1);
$sth->execute(vector(\@embedding));
while (my @row = $sth->fetchrow_array()) {
print($row[0] . "\n");
print($row[1] . "\n");
}

$dbh->do('CREATE INDEX my_index ON items USING ivfflat (embedding vector_l2_ops)');

0 comments on commit 2b0a125

Please sign in to comment.