Skip to content

Commit 1259dfa

Browse files
committed
Added reference section to readme [skip ci]
1 parent a54fe7f commit 1259dfa

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed

README.md

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -728,6 +728,54 @@ Use `vector_ip_ops` for inner product and `vector_cosine_ops` for cosine distanc
728728

729729
See a [full example](examples/bun/example.js)
730730

731+
## Reference
732+
733+
### Sparse Vectors
734+
735+
Create a sparse vector from an array
736+
737+
```javascript
738+
const vec = new SparseVector([1, 0, 2, 0, 3, 0]);
739+
```
740+
741+
Or a map of non-zero elements
742+
743+
```javascript
744+
const vec = new SparseVector({0: 1, 2: 2, 4: 3}, 6);
745+
// or
746+
const map = new Map();
747+
map.set(0, 1);
748+
map.set(2, 2);
749+
map.set(4, 3);
750+
const vec = new SparseVector(map, 6);
751+
```
752+
753+
Note: Indices start at 0
754+
755+
Get the number of dimensions
756+
757+
```javascript
758+
const dim = vec.dimensions;
759+
```
760+
761+
Get the indices of non-zero elements
762+
763+
```javascript
764+
const indices = vec.indices;
765+
```
766+
767+
Get the values of non-zero elements
768+
769+
```javascript
770+
const values = vec.values;
771+
```
772+
773+
Get an array
774+
775+
```javascript
776+
const arr = vec.toArray();
777+
```
778+
731779
## History
732780

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

0 commit comments

Comments
 (0)