File tree Expand file tree Collapse file tree 2 files changed +11
-1
lines changed
Expand file tree Collapse file tree 2 files changed +11
-1
lines changed Original file line number Diff line number Diff line change @@ -201,7 +201,7 @@ template <> struct string_traits<pgvector::SparseVector> {
201201 cb (inner.substr (start));
202202 }
203203
204- return pgvector::SparseVector (dimensions, indices, values);
204+ return pgvector::SparseVector (dimensions, std::move ( indices), std::move ( values) );
205205 }
206206
207207 static std::string_view to_buf (std::span<char > buf, const pgvector::SparseVector& value, ctx c = {}) {
Original file line number Diff line number Diff line change @@ -28,6 +28,16 @@ class SparseVector {
2828 values_ = values;
2929 }
3030
31+ // / @private
32+ SparseVector (int dimensions, std::vector<int >&& indices, std::vector<float >&& values) {
33+ if (values.size () != indices.size ()) {
34+ throw std::invalid_argument (" indices and values must be the same length" );
35+ }
36+ dimensions_ = dimensions;
37+ indices_ = std::move (indices);
38+ values_ = std::move (values);
39+ }
40+
3141 // / Creates a sparse vector from a dense vector.
3242 explicit SparseVector (const std::vector<float >& value) {
3343 dimensions_ = value.size ();
You can’t perform that action at this time.
0 commit comments