Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

pgvector/pgvector-lisp

Open more actions menu

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

30 Commits
30 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

pgvector-lisp

pgvector examples for Common Lisp

Supports Postmodern and CL-DBI

Build Status

Getting Started

Follow the instructions for your database library:

Or check out some examples:

Postmodern

Enable the extension

(load-extension "vector")

Create a table

(query (:create-table 'items ((id :type bigserial :primary-key t) (embedding :type (vector 3)))))

Insert a vector

(query (:insert-into 'items :set 'embedding "[1,1,1]"))

Get the nearest neighbors

(doquery (:limit (:order-by (:select 'id 'embedding :from 'items) (:<-> 'embedding "[1,1,1]")) 5) (id embedding)
    (format t "~A: ~A~%" id embedding))

Add an approximate index

(query (:create-index 'my-index :on 'items :using hnsw :fields "embedding vector_l2_ops"))
;; or
(query (:create-index 'my-index :on 'items :using ivfflat :fields "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

CL-DBI

Enable the extension

(dbi:do-sql *conn* "CREATE EXTENSION IF NOT EXISTS vector")

Create a table

(dbi:do-sql *conn* "CREATE TABLE items (id bigserial PRIMARY KEY, embedding vector(3))")

Insert a vector

(dbi:do-sql *conn* "INSERT INTO items (embedding) VALUES (?)" (list "[1,1,1]"))

Get the nearest neighbors

(dbi:fetch-all (dbi:execute (dbi:prepare *conn* "SELECT * FROM items ORDER BY embedding <-> ? LIMIT 5") (list "[1,1,1]")))

Add an approximate index

(dbi:do-sql *conn* "CREATE INDEX ON items USING hnsw (embedding vector_l2_ops)")
;; or
(dbi:do-sql *conn* "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:

To get started with development:

git clone https://github.com/pgvector/pgvector-lisp.git
cd pgvector-lisp
createdb pgvector_lisp_test
sbcl --noinform --non-interactive --load postmodern.lisp --load cl-dbi.lisp

To run an example:

cd examples/openai
createdb pgvector_example
sbcl --noinform --non-interactive --load example.lisp

About

pgvector examples for Common Lisp

Resources

License

Security policy

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published
Morty Proxy This is a proxified and sanitized view of the page, visit original site.