Skip to content

Commit 704ce5c

Browse files
committed
Added reference section to readme [skip ci]
1 parent 09cb16f commit 704ce5c

1 file changed

Lines changed: 126 additions & 0 deletions

File tree

README.md

Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -502,6 +502,132 @@ Use `vector_ip_ops` for inner product and `vector_cosine_ops` for cosine distanc
502502

503503
See a [full example](src/test/scala/com/pgvector/SlickTest.scala)
504504

505+
## Reference
506+
507+
### Vectors
508+
509+
Create a vector from an array
510+
511+
```java
512+
PGvector vec = new PGvector(new float[] {1, 2, 3});
513+
```
514+
515+
Or a `List<T>`
516+
517+
```java
518+
List<Float> list = List.of(Float.valueOf(1), Float.valueOf(2), Float.valueOf(3));
519+
PGvector vec = new PGvector(list);
520+
```
521+
522+
Get an array
523+
524+
```java
525+
float[] arr = vec.toArray();
526+
```
527+
528+
### Half Vectors
529+
530+
Create a half vector from an array
531+
532+
```java
533+
PGhalfvec vec = new PGhalfvec(new float[] {1, 2, 3});
534+
```
535+
536+
Or a `List<T>`
537+
538+
```java
539+
List<Float> list = List.of(Float.valueOf(1), Float.valueOf(2), Float.valueOf(3));
540+
PGhalfvec vec = new PGhalfvec(list);
541+
```
542+
543+
Get an array
544+
545+
```java
546+
float[] arr = vec.toArray();
547+
```
548+
549+
### Binary Vectors
550+
551+
Create a binary vector from a byte array
552+
553+
```java
554+
PGbit vec = new PGbit(new byte[] {(byte) 0b00000000, (byte) 0b11111111});
555+
```
556+
557+
Or a boolean array
558+
559+
```java
560+
PGbit vec = new PGbit(new boolean[] {true, false, true});
561+
```
562+
563+
Or a string
564+
565+
```java
566+
PGbit vec = new PGbit("101");
567+
```
568+
569+
Get the length (number of bits)
570+
571+
```java
572+
int length = vec.length();
573+
```
574+
575+
Get a byte array
576+
577+
```java
578+
byte[] bytes = vec.toByteArray();
579+
```
580+
581+
Or a boolean array
582+
583+
```java
584+
boolean[] bits = vec.toArray();
585+
```
586+
587+
### Sparse Vectors
588+
589+
Create a sparse vector from an array
590+
591+
```java
592+
PGsparsevec vec = new PGsparsevec(new float[] {1, 0, 2, 0, 3, 0});
593+
```
594+
595+
Or a map of non-zero elements
596+
597+
```java
598+
Map<Integer, Float> map = new HashMap<Integer, Float>();
599+
map.put(Integer.valueOf(0), Float.valueOf(1));
600+
map.put(Integer.valueOf(2), Float.valueOf(2));
601+
map.put(Integer.valueOf(4), Float.valueOf(3));
602+
PGsparsevec vec = new PGsparsevec(map, 6);
603+
```
604+
605+
Note: Indices start at 0
606+
607+
Get the number of dimensions
608+
609+
```java
610+
int dim = vec.getDimensions();
611+
```
612+
613+
Get the indices of non-zero elements
614+
615+
```java
616+
int[] indices = vec.getIndices();
617+
```
618+
619+
Get the values of non-zero elements
620+
621+
```java
622+
float[] values = vec.getValues();
623+
```
624+
625+
Get an array
626+
627+
```java
628+
float[] arr = vec.toArray();
629+
```
630+
505631
## History
506632

507633
View the [changelog](https://github.com/pgvector/pgvector-java/blob/master/CHANGELOG.md)

0 commit comments

Comments
 (0)