Skip to content

pgvector/pgvector-fortran

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

pgvector-fortran

pgvector examples for Fortran

Supports Libpq-Fortran

Build Status

Getting Started

Follow the instructions for your database library:

Libpq-Fortran

Enable the extension

type(c_ptr) :: res

res = PQexec(conn, "CREATE EXTENSION IF NOT EXISTS vector")

Create a table

res = PQexec(conn, "CREATE TABLE items (id bigserial PRIMARY KEY, embedding vector(3))")

Insert vectors

character(256) :: values(2)

values(1) = "[1,2,3]"
values(2) = "[4,5,6]"
res = PQexecParams(conn, "INSERT INTO items (embedding) VALUES ($1), ($2)", 2, [0, 0], values)

Get the nearest neighbors

character(256) :: values(1)

values(1) = "[3,1,2]"
res = PQexecParams(conn, "SELECT * FROM items ORDER BY embedding <-> $1 LIMIT 5", 1, [0], values)

Add an approximate index

res = PQexec(conn, "CREATE INDEX ON items USING hnsw (embedding vector_l2_ops)")
! or
res = PQexec(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

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-fortran.git
cd pgvector-fortran
createdb pgvector_fortran_test
fpm run

Specify the path to libpq if needed:

FPM_CFLAGS="-I/opt/homebrew/opt/libpq/include" FPM_LDFLAGS="-L/opt/homebrew/opt/libpq/lib" fpm run

About

pgvector examples for Fortran

Resources

License

Security policy

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published