Skip to content

Commit

Permalink
Vec insert and search working on a multi-layer
Browse files Browse the repository at this point in the history
  • Loading branch information
cvicentiu committed Feb 23, 2024
1 parent e254387 commit 2f6b2b3
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
2 changes: 1 addition & 1 deletion sql/sql_base.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9897,7 +9897,7 @@ int TABLE::hlindex_first(uint nr, Item *item, ulonglong limit)

DBUG_ASSERT(hlindex->in_use == in_use);

return mhnsw_first(this, item, limit);
return mhnsw_first(this, key_info + s->keys, item, limit);
}

int TABLE::hlindex_next()
Expand Down
11 changes: 7 additions & 4 deletions sql/vector_mhnsw.cc
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ class FVector: public FVectorRef
MYF(0));
if (!this->ref)
return true;
this->vec= (float *)(ref + ref_length);
this->vec= (float *)(this->ref + ref_length);
ref_len= ref_length;
vec_len= vec_length;
memcpy(this->ref, ref, ref_len);
Expand Down Expand Up @@ -477,7 +477,7 @@ int mhnsw_insert(TABLE *table, KEY *keyinfo)
const uint EF_CONSTRUCTION = 10; // max candidate list size to connect to.
const uint MAX_INSERT_NEIGHBOUR_CONNECTIONS = 10;
const uint MAX_NEIGHBORS_PER_LAYER = 10;
const double NORMALIZATION_FACTOR = 0.2;
const double NORMALIZATION_FACTOR = 1.2;

if ((err= h->ha_rnd_init(1)))
return err;
Expand Down Expand Up @@ -615,15 +615,17 @@ static int cmp_node_distances(void *, Node *a, Node *b)
int mhnsw_first(TABLE *table, KEY *keyinfo, Item *dist, ulonglong limit)
{
TABLE *graph= table->hlindex;
MY_BITMAP *old_map= dbug_tmp_use_all_columns(table, &table->read_set);
// TODO(cvicentiu) onlye one hlindex now.
Field *vec_field= keyinfo->key_part->field;
String buf, *res= vec_field->val_str(&buf);
Item_func_vec_distance *fun= (Item_func_vec_distance *)dist;
String buf, *res= fun->arguments()[1]->val_str(&buf);
FVector target;
handler *h= table->file;

//TODO(scope_exit)
int err;
if ((err= h->ha_rnd_init(1)))
if ((err= h->ha_rnd_init(0)))
return err;

if ((err= graph->file->ha_index_init(0, 1)))
Expand Down Expand Up @@ -685,6 +687,7 @@ int mhnsw_first(TABLE *table, KEY *keyinfo, Item *dist, ulonglong limit)
err= mhnsw_next(table);
graph->file->ha_index_end();

dbug_tmp_restore_column_map(&table->read_set, old_map);
return err;
}

Expand Down

0 comments on commit 2f6b2b3

Please sign in to comment.