Skip to content

Commit 4c89e07

Browse files
committed
Added reference section to readme [skip ci]
1 parent 164c792 commit 4c89e07

1 file changed

Lines changed: 42 additions & 0 deletions

File tree

README.md

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,48 @@ DB.add_index :items, :embedding, type: "hnsw", opclass: "vector_l2_ops"
133133

134134
Use `vector_ip_ops` for inner product and `vector_cosine_ops` for cosine distance
135135

136+
## Reference
137+
138+
### Sparse Vectors
139+
140+
Create a sparse vector from an array
141+
142+
```ruby
143+
vec = Pgvector::SparseVector.new([1, 0, 2, 0, 3, 0])
144+
```
145+
146+
Or a hash of non-zero elements
147+
148+
```ruby
149+
vec = Pgvector::SparseVector.new({0 => 1, 2 => 2, 4 => 3}, 6)
150+
```
151+
152+
Note: Indices start at 0
153+
154+
Get the number of dimensions
155+
156+
```ruby
157+
dim = vec.dimensions
158+
```
159+
160+
Get the indices of non-zero elements
161+
162+
```ruby
163+
indices = vec.indices
164+
```
165+
166+
Get the values of non-zero elements
167+
168+
```ruby
169+
values = vec.values
170+
```
171+
172+
Get an array
173+
174+
```ruby
175+
arr = vec.to_a
176+
```
177+
136178
## History
137179

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

0 commit comments

Comments
 (0)