pgvector examples for Tcl
Supports tdbc::postgres
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:
- 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-tcl.git
cd pgvector-tcl
createdb pgvector_tcl_test
tclsh example.tclSpecify the path to libpq if needed:
ln -s /opt/homebrew/opt/libpq/lib/libpq.dylib libpq.dylib