|
1 | | -# pgvector-scala |
| 1 | +# pgvector-java |
2 | 2 |
|
3 | | -[pgvector](https://github.com/pgvector/pgvector) examples for Scala |
| 3 | +[pgvector](https://github.com/pgvector/pgvector) examples for Java and Scala |
4 | 4 |
|
5 | 5 | Supports [JDBC](https://docs.oracle.com/javase/tutorial/jdbc/basics/index.html) and [Slick](https://github.com/slick/slick) |
6 | 6 |
|
7 | | -[](https://github.com/pgvector/pgvector-scala/actions) |
| 7 | +[](https://github.com/pgvector/pgvector-java/actions) |
8 | 8 |
|
9 | 9 | ## Getting Started |
10 | 10 |
|
11 | 11 | Follow the instructions for your database library: |
12 | 12 |
|
13 | | -- [JDBC](#jdbc) |
| 13 | +- [JDBC (Java)](#jdbc-java) |
| 14 | +- [JDBC (Scala)](#jdbc-scala) |
14 | 15 | - [Slick](#slick) |
15 | 16 |
|
16 | | -## JDBC |
| 17 | +## JDBC (Java) |
| 18 | + |
| 19 | +Create a table |
| 20 | + |
| 21 | +```java |
| 22 | +Statement stmt = conn.createStatement(); |
| 23 | +stmt.executeUpdate("CREATE TABLE items (embedding vector(3))"); |
| 24 | +``` |
| 25 | + |
| 26 | +Insert a vector |
| 27 | + |
| 28 | +```java |
| 29 | +stmt.executeUpdate("INSERT INTO items (embedding) VALUES ('[1,1,1]')"); |
| 30 | +``` |
| 31 | + |
| 32 | +Get the nearest neighbors |
| 33 | + |
| 34 | +```java |
| 35 | +ResultSet rs = stmt.executeQuery("SELECT * FROM items ORDER BY embedding <-> '[1,1,1]' LIMIT 5"); |
| 36 | +while (rs.next()) { |
| 37 | + System.out.println(rs.getString("embedding")); |
| 38 | +} |
| 39 | +``` |
| 40 | + |
| 41 | +Add an approximate index |
| 42 | + |
| 43 | +```java |
| 44 | +stmt.executeUpdate("CREATE INDEX my_index ON items USING ivfflat (embedding vector_l2_ops)"); |
| 45 | +``` |
| 46 | + |
| 47 | +Use `vector_ip_ops` for inner product and `vector_cosine_ops` for cosine distance |
| 48 | + |
| 49 | +See a [full example](src/main/java/JDBCJava.java) |
| 50 | + |
| 51 | +## JDBC (Scala) |
17 | 52 |
|
18 | 53 | Create a table |
19 | 54 |
|
@@ -45,7 +80,7 @@ stmt.executeUpdate("CREATE INDEX my_index ON items USING ivfflat (embedding vect |
45 | 80 |
|
46 | 81 | Use `vector_ip_ops` for inner product and `vector_cosine_ops` for cosine distance |
47 | 82 |
|
48 | | -See a [full example](src/main/scala/JDBC.scala) |
| 83 | +See a [full example](src/main/scala/JDBCScala.scala) |
49 | 84 |
|
50 | 85 | ## Slick |
51 | 86 |
|
@@ -86,16 +121,16 @@ See a [full example](src/main/scala/Slick.scala) |
86 | 121 |
|
87 | 122 | Everyone is encouraged to help improve this project. Here are a few ways you can help: |
88 | 123 |
|
89 | | -- [Report bugs](https://github.com/pgvector/pgvector-scala/issues) |
90 | | -- Fix bugs and [submit pull requests](https://github.com/pgvector/pgvector-scala/pulls) |
| 124 | +- [Report bugs](https://github.com/pgvector/pgvector-java/issues) |
| 125 | +- Fix bugs and [submit pull requests](https://github.com/pgvector/pgvector-java/pulls) |
91 | 126 | - Write, clarify, or fix documentation |
92 | 127 | - Suggest or add new features |
93 | 128 |
|
94 | 129 | To get started with development: |
95 | 130 |
|
96 | 131 | ```sh |
97 | | -git clone https://github.com/pgvector/pgvector-scala.git |
98 | | -cd pgvector-scala |
99 | | -createdb pgvector_scala_test |
| 132 | +git clone https://github.com/pgvector/pgvector-java.git |
| 133 | +cd pgvector-java |
| 134 | +createdb pgvector_java_test |
100 | 135 | sbt run |
101 | 136 | ``` |
0 commit comments