Skip to content

pgvector/pgvector-java

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

pgvector-scala

pgvector examples for Scala

Supports Slick

Build Status

Getting Started

Follow the instructions for your database library:

Slick

Add a vector column

class Items(tag: Tag) extends Table[(String)](tag, "items") {
  def embedding = column[String]("embedding", O.SqlType("vector(3)"))
  def * = (embedding)
}

Insert a vector

val embedding = "[1,1,1]"
db.run(sqlu"INSERT INTO items (embedding) VALUES ($embedding::vector)")

Get the nearest neighbors

val embedding = "[1,1,1]"
db.run(sql"SELECT * FROM items ORDER BY embedding <-> $embedding::vector LIMIT 5".as[(String)])

Add an approximate index

db.run(sqlu"CREATE INDEX my_index ON items USING ivfflat (embedding vector_l2_ops)")

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-scala.git
cd pgvector-scala
createdb pgvector_scala_test
sbt run

About

pgvector support for Java, Kotlin, Groovy, and Scala

Resources

License

Security policy

Stars

Watchers

Forks

Packages

 
 
 

Contributors