|
10 | 10 | import org.postgresql.copy.CopyManager;
|
11 | 11 | import org.postgresql.core.BaseConnection;
|
12 | 12 | import org.postgresql.util.ByteConverter;
|
13 |
| -import org.postgresql.util.PGBinaryObject; |
14 | 13 |
|
15 | 14 | public class Example {
|
16 | 15 | public static void main(String[] args) throws SQLException {
|
@@ -51,21 +50,13 @@ public static void main(String[] args) throws SQLException {
|
51 | 50 | copyIn.writeToCopy(buffer, 0, 19);
|
52 | 51 |
|
53 | 52 | for (int i = 0; i < rows; i++) {
|
54 |
| - PGBinaryObject[] values = {new PGvector(embeddings.get(i))}; |
| 53 | + PGvector embedding = new PGvector(embeddings.get(i)); |
55 | 54 |
|
56 | 55 | // write row
|
57 |
| - int pos = 0; |
58 |
| - ByteConverter.int2(buffer, pos, values.length); |
59 |
| - pos += 2; |
60 |
| - for (int j = 0; j < values.length; j++) { |
61 |
| - PGBinaryObject value = values[j]; |
62 |
| - int len = value.lengthInBytes(); |
63 |
| - ByteConverter.int4(buffer, pos, len); |
64 |
| - pos += 4; |
65 |
| - value.toBytes(buffer, pos); |
66 |
| - pos += len; |
67 |
| - } |
68 |
| - copyIn.writeToCopy(buffer, 0, pos); |
| 56 | + ByteConverter.int2(buffer, 0, 1); |
| 57 | + ByteConverter.int4(buffer, 2, embedding.lengthInBytes()); |
| 58 | + embedding.toBytes(buffer, 6); |
| 59 | + copyIn.writeToCopy(buffer, 0, 6 + embedding.lengthInBytes()); |
69 | 60 |
|
70 | 61 | // show progress
|
71 | 62 | if (i % 10000 == 0) {
|
|
0 commit comments