From 2b0a125ea479bfd50f576db6cf2e20b36d996b8d Mon Sep 17 00:00:00 2001 From: Andrew Kane Date: Mon, 18 Sep 2023 16:36:37 -0700 Subject: [PATCH] Added docs for enabling extension --- README.md | 10 ++++++++-- example.pl | 4 ++-- 2 files changed, 10 insertions(+), 4 deletions(-) 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)');