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

Open more actions menu

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

26 Commits
26 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

pgvector-haskell

pgvector support for Haskell

Supports postgresql-simple

Build Status

Getting Started

Add this line to your application’s .cabal file under build-depends:

pgvector >= 0.1 && < 0.2

And 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
Morty Proxy This is a proxified and sanitized view of the page, visit original site.