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

Open more actions menu

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
15 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

pgvector-crystal

pgvector examples for Crystal

Supports crystal-pg

Build Status

Getting Started

Follow the instructions for your database library:

Or check out some examples:

crystal-pg

Enable the extension

db.exec "CREATE EXTENSION IF NOT EXISTS vector"

Create a table

db.exec "CREATE TABLE items (id bigserial PRIMARY KEY, embedding vector(3))"

Insert vectors

embedding1 = "[1,1,1]"
embedding2 = "[2,2,2]"
embedding3 = "[1,1,2]"
db.exec "INSERT INTO items (embedding) VALUES ($1), ($2), ($3)", embedding1, embedding2, embedding3

Get the nearest neighbors

embedding = "[1,1,1]"
db.query("SELECT id, embedding::text FROM items ORDER BY embedding <-> $1 LIMIT 5", embedding) do |rs|
  rs.each do
    id, embedding = rs.read(Int64, String)
    puts "#{id}: #{embedding}"
  end
end

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-crystal.git
cd pgvector-crystal
shards install
createdb pgvector_crystal_test
crystal src/example.cr

To run an example:

cd examples/openai
createdb pgvector_example
crystal examples/openai/example.cr

About

pgvector examples for Crystal

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.