Skip to content

Commit

Permalink
adjustments to the neighborhood api
Browse files Browse the repository at this point in the history
  • Loading branch information
sadit committed Oct 7, 2024
1 parent ed122a5 commit af12cd7
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 8 deletions.
5 changes: 2 additions & 3 deletions src/searchgraph/neighborhood.jl
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ Base.copy(N::Neighborhood;
filter=copy(N.filter)
) = Neighborhood(; logbase, minsize, filter)

function neighborhoodsize(N::Neighborhood, index::SearchGraph)::Int
n = length(index)
function neighborhoodsize(N::Neighborhood, n::Integer)::Int
n == 0 ? 0 : ceil(Int, N.minsize + log(N.logbase, n))
end

Expand All @@ -39,7 +38,7 @@ the given context.
"""
function find_neighborhood(copy_::Function, index::SearchGraph, context::SearchGraphContext, item; hints=index.hints)
neighborhood = context.neighborhood
ksearch = neighborhoodsize(neighborhood, index)
ksearch = neighborhoodsize(neighborhood, length(index))
res = getknnresult(ksearch, context)
if ksearch > 0
search(index.algo, index, context, item, res, hints)
Expand Down
13 changes: 9 additions & 4 deletions src/searchgraph/optbs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,7 @@ function setconfig!(bs::BeamSearch, index::SearchGraph, perf)
end

function runconfig(bs::BeamSearch, index::SearchGraph, ctx::SearchGraphContext, q, res::KnnResult)
search(bs, index, ctx, q, res, index.hints; maxvisits = 4index.algo.maxvisits)
# search(bs, index, q, res, index.hints, caches)
search(bs, index, ctx, q, res, index.hints; maxvisits = 2index.algo.maxvisits)
end

"""
Expand All @@ -107,6 +106,12 @@ SearchGraph's callback for adjunting search parameters
"""
function execute_callback(index::SearchGraph, context::SearchGraphContext, opt::OptimizeParameters)
queries = nothing
optimize_index!(index, context, opt.kind; opt.space,
queries, opt.ksearch, opt.numqueries, opt.initialpopulation, opt.verbose, opt.params)
optimize_index!(index, context, opt.kind;
opt.space,
queries,
ksearch=neighborhoodsize(context.neighborhood, length(index)),
opt.numqueries,
opt.initialpopulation,
opt.verbose,
opt.params)
end
2 changes: 1 addition & 1 deletion test/testsearchgraph.jl
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ end
)
index!(graph, ctx)
@test n == length(db) == length(graph)
optimize_index!(graph, ctx, MinRecall(0.9); queries)
optimize_index!(graph, ctx, MinRecall(0.9); queries, ksearch)
searchtime = @elapsed I, D = searchbatch(graph, ctx, queries, ksearch)
@test size(I) == size(D) == (ksearch, m) == size(goldI)
recall = macrorecall(goldI, I)
Expand Down

0 comments on commit af12cd7

Please sign in to comment.