Skip to content

pgvector/pgvector-lua

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

28 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

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

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

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

Get the nearest neighbors

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
  for k, v in pairs(row) do
    print(k, v)
  end
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

History

View the changelog

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

About

pgvector support for Lua

Resources

License

Security policy

Stars

Watchers

Forks

Packages

No packages published

Languages

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy