Skip to content

Commit 2e97a6a

Browse files
committed
Added reference section to readme [skip ci]
1 parent 392a3b5 commit 2e97a6a

1 file changed

Lines changed: 71 additions & 0 deletions

File tree

README.md

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,77 @@ pg_query($db, 'CREATE INDEX ON items USING ivfflat (embedding vector_l2_ops) WIT
209209

210210
See a [full example](examples/pgsql/example.php)
211211

212+
## Reference
213+
214+
### Vectors
215+
216+
Create a vector from an array
217+
218+
```php
219+
$vec = new Vector([1, 2, 3]);
220+
```
221+
222+
Get an array
223+
224+
```php
225+
$arr = $vec->toArray();
226+
```
227+
228+
### Half Vectors
229+
230+
Create a half vector from an array
231+
232+
```php
233+
$vec = new HalfVector([1, 2, 3]);
234+
```
235+
236+
Get an array
237+
238+
```php
239+
$arr = $vec->toArray();
240+
```
241+
242+
### Sparse Vectors
243+
244+
Create a sparse vector from an indexed array
245+
246+
```php
247+
$vec = new SparseVector([1, 0, 2, 0, 3, 0]);
248+
```
249+
250+
Or an associative array of non-zero elements
251+
252+
```php
253+
$elements = [0 => 1, 2 => 2, 4 => 3];
254+
$vec = new SparseVector($elements, 6);
255+
```
256+
257+
Note: Indices start at 0
258+
259+
Get the number of dimensions
260+
261+
```php
262+
$dim = $vec->dimensions();
263+
```
264+
265+
Get the indices of non-zero elements
266+
267+
```php
268+
$indices = $vec->indices();
269+
```
270+
271+
Get the values of non-zero elements
272+
273+
```php
274+
$values = $vec->values();
275+
```
276+
277+
Get an array
278+
279+
```php
280+
$arr = $vec->toArray();
281+
```
282+
212283
## Upgrading
213284

214285
### 0.1.4

0 commit comments

Comments
 (0)