diff --git a/README.md b/README.md index 8db8591..57acaac 100644 --- a/README.md +++ b/README.md @@ -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 @@ -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"); } ``` diff --git a/example.pl b/example.pl index f765f0d..a2c34d6 100644 --- a/example.pl +++ b/example.pl @@ -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]}) . ']'; @@ -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)');