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-lisp: pgvector examples for Common Lisp

BranchesTags
Open more actions menu

Latest commit

 

History

33 Commits
33 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
 
 
cl-dbi.lisp
cl-dbi.lisp
 
 
postmodern.lisp
postmodern.lisp
 
 

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:

  • Postmodern
  • CL-DBI

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

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:

  • 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-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

Readme
MIT license

Security policy

Security policy
Activity
Custom properties

Stars

7 stars

Watchers

1 watching

Forks

0 forks
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.