Skip to content

pgvector/pgvector-tcl

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

pgvector-tcl

pgvector examples for Tcl

Supports tdbc::postgres

Build Status

Getting Started

Follow the instructions for your database library:

tdbc::postgres

Enable the extension

$db allrows "CREATE EXTENSION IF NOT EXISTS vector"

Create a table

$db allrows "CREATE TABLE items (id bigserial PRIMARY KEY, embedding vector(3))"

Insert vectors

set params [dict create embedding {[1,2,3]} embedding2 {[4,5,6]}]
$db allrows "INSERT INTO items (embedding) VALUES (:embedding), (:embedding2)" $params

Get the nearest neighbors

set params [dict create embedding {[3,1,2]}]
$db foreach row "SELECT * FROM items ORDER BY embedding <-> :embedding LIMIT 5" $params {
    puts $row
}

Add an approximate index

$db allrows "CREATE INDEX ON items USING hnsw (embedding vector_l2_ops)"

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:

To get started with development:

git clone https://github.com/pgvector/pgvector-tcl.git
cd pgvector-tcl
createdb pgvector_tcl_test
tclsh example.tcl

Specify the path to libpq if needed:

ln -s /opt/homebrew/opt/libpq/lib/libpq.dylib libpq.dylib

About

pgvector examples for Tcl

Resources

License

Security policy

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages