8000 Added reference section to readme [skip ci] · roskakori/pgvector-python@7846622 · GitHub
[go: up one dir, main page]

Skip to content

Commit 7846622

Browse files
committed
Added reference section to readme [skip ci]
1 parent 12146d7 commit 7846622

File tree

1 file changed

+93
-0
lines changed

1 file changed

+93
-0
lines changed

README.md

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -665,6 +665,99 @@ Item.add_index('embedding vector_l2_ops', using='hnsw')
665665

666666
Use `vector_ip_ops` for inner product and `vector_cosine_ops` for cosine distance
667667

668+
## Reference
669+
670+
### Half Vectors
671+
672+
Create a half vector from a list
673+
674+
```python
675+
vec = HalfVector([1, 2, 3])
676+
```
677+
678+
Or a NumPy array
679+
680+
```python
681+
vec = HalfVector(np.array([1, 2, 3]))
682+
```
683+
684+
Get a list
685+
686+
```python
687+
lst = vec.to_list()
688+
```
689+
690+
Get a NumPy array
691+
692+
```python
693+
arr = vec.to_numpy()
694+
```
695+
696+
### Sparse Vectors
697+
698+
Create a sparse vector from a list
699+
700+
```python
701+
vec = SparseVector([1, 0, 2, 0, 3, 0])
702+
```
703+
704+
Or a NumPy array
705+
706+
```python
707+
vec = SparseVector(np.array([1, 0, 2, 0, 3, 0]))
708+
```
709+
710+
Or a SciPy sparse array
711+
712+
```python
713+
arr = coo_array(([1, 2, 3], ([0, 2, 4],)), shape=(6,))
714+
vec = SparseVector(arr)
715+
```
716+
717+
Or a dictionary of non-zero elements
718+
719+
```python
720+
vec = SparseVector({0: 1, 2: 2, 4: 3}, 6)
721+
```
722+
723+
Note: Indices start at 0
724+
725+
Get the number of dimensions
726+
727+
```python
728+
dim = vec.dimensions()
729+
```
730+
731+
Get the indices of non-zero elements
732+
733+
```python
734+
indices = vec.indices()
735+
```
736+
737+
Get the values of non-zero elements
738+
739+
```python
740+
values = vec.values()
741+
```
742+
743+
Get a list
744+
745+
```python
746+
lst = vec.to_list()
747+
```
748+
749+
Get a NumPy array
750+
751+
```python
752+
arr = vec.to_numpy()
753+
```
754+
755+
Get a SciPy sparse array
756+
757+
```python
758+
arr = vec.to_coo()
759+
```
760+
668761
## History
669762

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

0 commit comments

Comments
 (0)
0