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-lua: pgvector support for Lua

BranchesTags
Open more actions menu

Latest commit

 

History

65 Commits
65 Commits

Folders and files

NameName
Last commit message
Last commit date
.github/workflows
.github/workflows
 
 
examples
examples
 
 
src
src
 
 
test
test
 
 
.gitignore
.gitignore
 
 
CHANGELOG.md
CHANGELOG.md
 
 
LICENSE.txt
LICENSE.txt
 
 
README.md
README.md
 
 
pgvector-dev-1.rockspec
pgvector-dev-1.rockspec
 
 

Repository files navigation

pgvector-lua

pgvector support for Lua

Supports pgmoon

Build Status

Getting Started

Run:

luarocks install pgvector

And follow the instructions for your database library:

  • pgmoon

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

pgmoon

Require the library

local pgvector = require("pgvector")

Enable the extension

pg:query("CREATE EXTENSION IF NOT EXISTS vector")

Create a table

pg:query("CREATE TABLE items (id bigserial PRIMARY KEY, embedding vector(3))")

Insert a vector

local embedding = pgvector.new({1, 1, 1})
pg:query("INSERT INTO items (embedding) VALUES ($1)", embedding)

Get the nearest neighbors

local embedding = pgvector.new({1, 1, 1})
local res = pg:query("SELECT * FROM items ORDER BY embedding <-> $1 LIMIT 5", embedding)
for i, row in ipairs(res) do
  print(row["id"])
end

Add an approximate index

pg:query("CREATE INDEX ON items USING hnsw (embedding vector_l2_ops)")
-- or
pg:query("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

Reference

Half Vectors

Create a half vector from a table

local vec = pgvector.halfvec({1, 2, 3})

Sparse Vectors

Create a sparse vector from a table of non-zero elements

local elements = {[1] = 1, [3] = 2, [5] = 3}
local vec = pgvector.sparsevec(elements, 6)

Get the number of dimensions

vec["dim"]

Get the non-zero elements

vec["elements"]

History

View the changelog

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-lua.git
cd pgvector-lua
createdb pgvector_lua_test
luarocks install pgmoon
luarocks install luasocket
lua test/pgvector.lua

To run an example:

createdb pgvector_example
luarocks install luasec
luarocks install lua-cjson
lua examples/openai/example.lua

About

pgvector support for Lua

Resources

Readme
MIT license

Security policy

Security policy
Activity
Custom properties

Stars

4 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.