Skip to content

Latest commit

 

History

History
83 lines (55 loc) · 1.93 KB

README.md

File metadata and controls

83 lines (55 loc) · 1.93 KB

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