Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
M
MariaDB
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
nexedi
MariaDB
Commits
9b427691
Commit
9b427691
authored
Jun 06, 2024
by
Sergei Golubchik
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
mhnsw: remove EXTEND_CANDIDATES and KEEP_PRUNED_CONNECTIONS
parent
2aa5f7ff
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
7 additions
and
27 deletions
+7
-27
sql/vector_mhnsw.cc
sql/vector_mhnsw.cc
+7
-27
No files found.
sql/vector_mhnsw.cc
View file @
9b427691
...
@@ -210,9 +210,6 @@ static int cmp_vec(const FVector *target, const FVectorNode *a, const FVectorNod
...
@@ -210,9 +210,6 @@ static int cmp_vec(const FVector *target, const FVectorNode *a, const FVectorNod
return
0
;
return
0
;
}
}
const
bool
KEEP_PRUNED_CONNECTIONS
=
true
;
// XXX why?
const
bool
EXTEND_CANDIDATES
=
true
;
// XXX or false?
static
int
select_neighbors
(
MHNSW_Context
*
ctx
,
size_t
layer
,
static
int
select_neighbors
(
MHNSW_Context
*
ctx
,
size_t
layer
,
const
FVectorNode
&
target
,
const
FVectorNode
&
target
,
const
List
<
FVectorNode
>
&
candidates_unsafe
,
const
List
<
FVectorNode
>
&
candidates_unsafe
,
...
@@ -246,20 +243,6 @@ static int select_neighbors(MHNSW_Context *ctx, size_t layer,
...
@@ -246,20 +243,6 @@ static int select_neighbors(MHNSW_Context *ctx, size_t layer,
pq
.
push
(
&
candidate
);
pq
.
push
(
&
candidate
);
}
}
if
(
EXTEND_CANDIDATES
)
{
for
(
const
FVectorNode
&
candidate
:
candidates
)
{
for
(
const
FVectorNode
&
extra_candidate
:
candidate
.
get_neighbors
(
layer
))
{
if
(
visited
.
find
(
&
extra_candidate
))
continue
;
visited
.
insert
(
&
extra_candidate
);
pq
.
push
(
&
extra_candidate
);
}
}
}
DBUG_ASSERT
(
pq
.
elements
());
DBUG_ASSERT
(
pq
.
elements
());
neighbors
.
push_back
(
pq
.
pop
(),
&
ctx
->
root
);
neighbors
.
push_back
(
pq
.
pop
(),
&
ctx
->
root
);
...
@@ -279,13 +262,10 @@ static int select_neighbors(MHNSW_Context *ctx, size_t layer,
...
@@ -279,13 +262,10 @@ static int select_neighbors(MHNSW_Context *ctx, size_t layer,
neighbors
.
push_back
(
vec
,
&
ctx
->
root
);
neighbors
.
push_back
(
vec
,
&
ctx
->
root
);
}
}
if
(
KEEP_PRUNED_CONNECTIONS
)
while
(
pq_discard
.
elements
()
&&
neighbors
.
elements
<
max_neighbor_connections
)
{
{
while
(
pq_discard
.
elements
()
&&
neighbors
.
push_back
(
pq_discard
.
pop
(),
&
ctx
->
root
);
neighbors
.
elements
<
max_neighbor_connections
)
{
neighbors
.
push_back
(
pq_discard
.
pop
(),
&
ctx
->
root
);
}
}
}
return
0
;
return
0
;
...
@@ -550,8 +530,8 @@ int mhnsw_insert(TABLE *table, KEY *keyinfo)
...
@@ -550,8 +530,8 @@ int mhnsw_insert(TABLE *table, KEY *keyinfo)
ref_ptr
=
graph
->
field
[
1
]
->
val_str
(
&
ref_str
);
ref_ptr
=
graph
->
field
[
1
]
->
val_str
(
&
ref_str
);
FVectorNode
start_node
(
&
ctx
,
ref_ptr
->
ptr
());
FVectorNode
start_node
(
&
ctx
,
ref_ptr
->
ptr
());
//
TODO(cvicentiu) use a random start node in last layer.
//
XXX may be *all* nodes in the last layer? there should be few
//
XXX or may be *all* nodes in the last layer? there should be few
//
xxx could boost recall, if needed
if
(
start_nodes
.
push_back
(
&
start_node
,
&
ctx
.
root
))
if
(
start_nodes
.
push_back
(
&
start_node
,
&
ctx
.
root
))
return
HA_ERR_OUT_OF_MEM
;
return
HA_ERR_OUT_OF_MEM
;
...
@@ -635,14 +615,14 @@ int mhnsw_first(TABLE *table, KEY *keyinfo, Item *dist, ulonglong limit)
...
@@ -635,14 +615,14 @@ int mhnsw_first(TABLE *table, KEY *keyinfo, Item *dist, ulonglong limit)
longlong
max_layer
=
graph
->
field
[
0
]
->
val_int
();
longlong
max_layer
=
graph
->
field
[
0
]
->
val_int
();
List
<
FVectorNode
>
candidates
;
// XXX List? not Queue by distance?
List
<
FVectorNode
>
candidates
;
List
<
FVectorNode
>
start_nodes
;
List
<
FVectorNode
>
start_nodes
;
String
ref_str
,
*
ref_ptr
=
graph
->
field
[
1
]
->
val_str
(
&
ref_str
);
String
ref_str
,
*
ref_ptr
=
graph
->
field
[
1
]
->
val_str
(
&
ref_str
);
FVectorNode
start_node
(
&
ctx
,
ref_ptr
->
ptr
());
FVectorNode
start_node
(
&
ctx
,
ref_ptr
->
ptr
());
// TODO(cvicentiu) use a random start node in last layer.
// XXX or may be *all* nodes in the last layer? there should be few
// XXX or may be *all* nodes in the last layer? there should be few
// xxx could boost recall, if needed
if
(
start_nodes
.
push_back
(
&
start_node
,
&
ctx
.
root
))
if
(
start_nodes
.
push_back
(
&
start_node
,
&
ctx
.
root
))
return
HA_ERR_OUT_OF_MEM
;
return
HA_ERR_OUT_OF_MEM
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment