-
Notifications
You must be signed in to change notification settings - Fork 0
/
Main.hs
31 lines (24 loc) · 985 Bytes
/
Main.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
{-# LANGUAGE OverloadedStrings #-}
module Main where
import Database.PostgreSQL.Simple
import Pgvector
main :: IO ()
main = do
conn <- connectPostgreSQL "dbname=pgvector_haskell_test"
_ <- execute_ conn "CREATE EXTENSION IF NOT EXISTS vector"
_ <- execute_ conn "DROP TABLE IF EXISTS items"
_ <- execute_ conn "CREATE TABLE items (embedding vector(3))"
_ <- execute conn
"INSERT INTO items (embedding) VALUES (?)"
[Vector [1, 1, 1]]
_ <- execute conn
"INSERT INTO items (embedding) VALUES (?)"
[Vector [2, 2, 2]]
_ <- execute conn
"INSERT INTO items (embedding) VALUES (?)"
[Vector [1, 1, 2]]
let q = "SELECT embedding FROM items ORDER BY embedding <-> ? LIMIT 5"
forEach conn q [Vector [1, 1, 1]] $ \(Only embedding) ->
putStrLn $ show (embedding :: Vector)
_ <- execute_ conn "CREATE INDEX ON items USING ivfflat (embedding vector_l2_ops) WITH (lists = 1)"
putStrLn "Success"