GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - pgvector/pgvector-perl: pgvector examples for Perl

BranchesTags
Open more actions menu

Latest commit

 

History

30 Commits
30 Commits

Folders and files

NameName
Last commit message
Last commit date
.github/workflows
.github/workflows
 
 
examples
examples
 
 
LICENSE.txt
LICENSE.txt
 
 
README.md
README.md
 
 
example.pl
example.pl
 
 

Repository files navigation

pgvector-perl

pgvector examples for Perl

Supports DBD::Pg

Build Status

Getting Started

Follow the instructions for your database library:

  • DBD::Pg

Or check out some examples:

  • Embeddings with OpenAI
  • Binary embeddings with Cohere
  • Hybrid search with Ollama (Reciprocal Rank Fusion)
  • Sparse search with Text Embeddings Inference

DBD::Pg

Enable the extension

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

Create a table

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

Insert vectors

sub vector {
    return '[' . join(',', @{$_[0]}) . ']';
}

my $sth = $dbh->prepare('INSERT INTO items (embedding) VALUES ($1), ($2), ($3)');
my @embedding1 = (1, 1, 1);
my @embedding2 = (2, 2, 2);
my @embedding3 = (1, 1, 2);
$sth->execute(vector(\@embedding1), vector(\@embedding2), vector(\@embedding3));

Get the nearest neighbors

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[1] . "\n");
}

Add an approximate index

$dbh->do('CREATE INDEX ON items USING hnsw (embedding vector_l2_ops)');
# or
$dbh->do('CREATE INDEX ON items USING ivfflat (embedding vector_l2_ops) WITH (lists = 100)');

Use vector_ip_ops for inner product and vector_cosine_ops for cosine distance

See a full example

Contributing

Everyone is encouraged to help improve this project. Here are a few ways you can help:

  • Report bugs
  • Fix bugs and submit pull requests
  • Write, clarify, or fix documentation
  • Suggest or add new features

To get started with development:

git clone https://github.com/pgvector/pgvector-perl.git
cd pgvector-perl
createdb pgvector_perl_test
cpan DBD::Pg
perl example.pl

To run an example:

cd examples/openai
createdb pgvector_example
perl example.pl

About

pgvector examples for Perl

Resources

Readme
MIT license

Security policy

Security policy
Activity
Custom properties

Stars

3 stars

Watchers

1 watching

Forks

1 fork
Report repository

Releases

Packages

Used by

Contributors

Languages

You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.