Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions sql/vector_mhnsw.cc
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,8 @@ struct FVector
vec->scale= std::nextafter(vec->scale, FLT_MAX);
for (size_t i= 0; i < vec_len; i++)
vec->dims[i] = static_cast<int16_t>(std::round(get_float(v + i) / vec->scale));
vec->postprocess(vec_len);
vec->fix_tail(vec_len);
vec->abs2= vec->scale * vec->scale * dot_product(vec->dims, vec->dims, vec_len) / 2;
if (metric == COSINE)
{
if (vec->abs2 > 0.0f)
Expand All @@ -113,12 +114,6 @@ struct FVector
return vec;
}

void postprocess(size_t vec_len)
{
fix_tail(vec_len);
abs2= scale * scale * dot_product(dims, dims, vec_len) / 2;
}

#ifdef AVX2_IMPLEMENTATION
/************* AVX2 *****************************************************/
static constexpr size_t AVX2_bytes= 256/8;
Expand Down Expand Up @@ -882,7 +877,12 @@ int FVectorNode::load_from_record(TABLE *graph)
return my_errno= HA_ERR_CRASHED;
FVector *vec_ptr= FVector::align_ptr(tref() + tref_len());
memcpy(vec_ptr->data(), v->ptr(), v->length());
vec_ptr->postprocess(ctx->vec_len);
vec_ptr->fix_tail(ctx->vec_len);
if (ctx->metric == COSINE)
vec_ptr->abs2= 0.5f;
Comment thread
vuvova marked this conversation as resolved.
else
vec_ptr->abs2= vec_ptr->scale * vec_ptr->scale *
vec_ptr->dot_product(vec_ptr->dims, vec_ptr->dims, ctx->vec_len) / 2;

longlong layer= graph->field[FIELD_LAYER]->val_int();
if (layer > 100) // 10e30 nodes at M=2, more at larger M's
Expand Down