pgvector examples for Prolog
Supports postgresql-prolog
Follow the instructions for your database library:
Enable the extension
postgresql:query(Connection, "CREATE EXTENSION IF NOT EXISTS vector", ok)Create a table
postgresql:query(Connection, "CREATE TABLE items (id bigserial PRIMARY KEY, embedding vector(3))", ok)Insert vectors
postgresql:sql(Connection, [insert_into(items, [embedding]), values("[1,2,3]")], data([]))Get the nearest neighbors
postgresql:query(Connection, "SELECT * FROM items ORDER BY embedding <-> '[3,1,2]' LIMIT 5", Rows)Add an approximate index
postgresql:query(Connection, "CREATE INDEX ON items USING hnsw (embedding vector_l2_ops)", ok)Use vector_ip_ops for inner product and vector_cosine_ops for cosine distance
See a full example
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-prolog.git
cd pgvector-prolog
createdb pgvector_prolog_test
scryer-prolog example.pl -g "main,halt."