diff --git a/src/searchgraph/neighborhood.jl b/src/searchgraph/neighborhood.jl index 9f49a62..b6751be 100644 --- a/src/searchgraph/neighborhood.jl +++ b/src/searchgraph/neighborhood.jl @@ -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 @@ -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) diff --git a/src/searchgraph/optbs.jl b/src/searchgraph/optbs.jl index 547c1c8..3365f58 100644 --- a/src/searchgraph/optbs.jl +++ b/src/searchgraph/optbs.jl @@ -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 """ @@ -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 diff --git a/test/testsearchgraph.jl b/test/testsearchgraph.jl index e1d09fd..28f3f1d 100644 --- a/test/testsearchgraph.jl +++ b/test/testsearchgraph.jl @@ -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)