1
0
mirror of https://github.com/MariaDB/server.git synced 2025-08-07 00:04:31 +03:00

mhnsw: make the search less greedy

introduced a generosity factor that makes the search less greedy.
it dramatically improves the recall by making the search a bit slower
(for the same recall one can use half the M and smaller ef).

had to add Queue::safe_push() method that removes one of the
furthest elements (not necessarily the furthest) in the queue
to keep it from overflowing.
This commit is contained in:
Sergei Golubchik
2024-07-24 22:31:36 +02:00
parent 885eb19823
commit 26e599cd32
2 changed files with 15 additions and 5 deletions

View File

@@ -44,6 +44,11 @@ public:
Element *top() const { return (Element*)queue_top(&m_queue); }
void push(const Element *element) { queue_insert(&m_queue, (uchar*)element); }
void safe_push(const Element *element)
{
if (is_full()) m_queue.elements--; // remove one of the furthest elements
queue_insert(&m_queue, (uchar*)element);
}
Element *pop() { return (Element *)queue_remove_top(&m_queue); }
void clear() { queue_remove_all(&m_queue); }
void propagate_top() { queue_replace_top(&m_queue); }