Skip to content

Commit 1bb9978

Browse files
committed
Improved reference section [skip ci]
1 parent 9e19377 commit 1bb9978

File tree

1 file changed

+50
-2
lines changed

1 file changed

+50
-2
lines changed

README.md

Lines changed: 50 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,10 +82,58 @@ Use `std::optional<pgvector::Vector>` if the value could be `NULL`
8282

8383
## Reference
8484

85-
Convert a vector to a `std::vector<float>`
85+
### Vectors
86+
87+
Create a vector from a `std::vector<float>`
88+
89+
```cpp
90+
auto vec = pgvector::Vector({1, 2, 3});
91+
```
92+
93+
Convert to a `std::vector<float>`
94+
95+
```cpp
96+
auto float_vec = static_cast<std::vector<float>>(vec);
97+
```
98+
99+
### Half Vectors
100+
101+
Create a half vector from a `std::vector<float>`
102+
103+
```cpp
104+
auto vec = pgvector::HalfVector({1, 2, 3});
105+
```
106+
107+
Convert to a `std::vector<float>`
108+
109+
```cpp
110+
auto float_vec = static_cast<std::vector<float>>(vec);
111+
```
112+
113+
### Sparse Vectors
114+
115+
Create a sparse vector from a `std::vector<float>`
116+
117+
```cpp
118+
auto vec = pgvector::SparseVector({1, 0, 2, 0, 3, 0});
119+
```
120+
121+
Get the number of dimensions
122+
123+
```cpp
124+
int dim = vec.dimensions();
125+
```
126+
127+
Get the indices of non-zero elements
128+
129+
```cpp
130+
auto indices = vec.indices();
131+
```
132+
133+
Get the values of non-zero elements
86134

87135
```cpp
88-
auto float_vec = static_cast<std::vector<float>>(embedding);
136+
auto values = vec.values();
89137
```
90138

91139
## History

0 commit comments

Comments
 (0)