Skip to content

pgvector/pgvector-haskell

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

pgvector-haskell

pgvector support for Haskell

Supports postgresql-simple

Build Status

Getting Started

Follow the instructions for your database library:

postgresql-simple

Import the library

import Pgvector

Enable the extension

execute_ conn "CREATE EXTENSION IF NOT EXISTS vector"

Create a table

execute_ conn "CREATE TABLE items (embedding vector(3))"

Insert a vector

execute conn
    "INSERT INTO items (embedding) VALUES (?)"
    [Vector [1, 1, 1]]

Get the nearest neighbors

let q = "SELECT embedding FROM items ORDER BY embedding <-> ? LIMIT 5"
forEach conn q [Vector [1, 1, 1]] $ \(Only embedding) ->
    putStrLn $ show (embedding :: Vector)

Add an approximate index

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

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-haskell.git
cd pgvector-haskell
createdb pgvector_haskell_test
cabal test

About

pgvector support for Haskell

Resources

License

Security policy

Stars

Watchers

Forks

Packages

No packages published