add annoy params validate check (#1829)

* fix bug & solve compile warning from annoylib

Signed-off-by: cmli <chengming.li@zilliz.com>

* fix lint error

Signed-off-by: cmli <chengming.li@zilliz.com>

Co-authored-by: cmli <chengming.li@zilliz.com>
pull/1840/head
op-hunter 2020-04-02 09:47:45 +08:00 committed by GitHub
parent 78a7aac6dc
commit 6e7fb831bd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 25 additions and 8 deletions

View File

@ -119,6 +119,7 @@ Please mark all change in change log and use the issue from GitHub
- \#1598 Server down during mixed operations - \#1598 Server down during mixed operations
- \#1601 External link bug in HTTP doc - \#1601 External link bug in HTTP doc
- \#1609 Refine Compact function - \#1609 Refine Compact function
- \#1808 Building index params check for Annoy
## Feature ## Feature
- \#216 Add CLI to get server info - \#216 Add CLI to get server info

View File

@ -299,9 +299,9 @@ BinIVFConfAdapter::CheckTrain(Config& oricfg, const IndexMode mode) {
bool bool
ANNOYConfAdapter::CheckTrain(Config& oricfg, const IndexMode mode) { ANNOYConfAdapter::CheckTrain(Config& oricfg, const IndexMode mode) {
static int64_t MIN_NTREES = 0; static int64_t MIN_NTREES = 1;
// too large of n_trees takes much time, if there is real requirement, change this threshold. // too large of n_trees takes much time, if there is real requirement, change this threshold.
static int64_t MAX_NTREES = 16384; static int64_t MAX_NTREES = 1024;
CheckIntByRange(knowhere::IndexParams::n_trees, MIN_NTREES, MAX_NTREES); CheckIntByRange(knowhere::IndexParams::n_trees, MIN_NTREES, MAX_NTREES);

View File

@ -967,7 +967,7 @@ public:
memcpy(_get(_n_nodes + (S)i), _get(_roots[i]), _s); memcpy(_get(_n_nodes + (S)i), _get(_roots[i]), _s);
_n_nodes += _roots.size(); _n_nodes += _roots.size();
if (_verbose) showUpdate("has %d nodes\n", _n_nodes); if (_verbose) showUpdate("has %ld nodes\n", _n_nodes);
if (_on_disk) { if (_on_disk) {
_nodes = remap_memory(_nodes, _fd, _s * _nodes_size, _s * _n_nodes); _nodes = remap_memory(_nodes, _fd, _s * _nodes_size, _s * _n_nodes);
@ -1105,7 +1105,7 @@ public:
_loaded = true; _loaded = true;
_built = true; _built = true;
_n_items = m; _n_items = m;
if (_verbose) showUpdate("found %lu roots with degree %d\n", _roots.size(), m); if (_verbose) showUpdate("found %lu roots with degree %ld\n", _roots.size(), m);
return true; return true;
} }
@ -1144,7 +1144,7 @@ public:
_loaded = true; _loaded = true;
_built = true; _built = true;
_n_items = m; _n_items = m;
if (_verbose) showUpdate("found %lu roots with degree %d\n", _roots.size(), m); if (_verbose) showUpdate("found %lu roots with degree %ld\n", _roots.size(), m);
return true; return true;
} }
@ -1215,7 +1215,7 @@ protected:
} }
_nodes_size = new_nodes_size; _nodes_size = new_nodes_size;
if (_verbose) showUpdate("Reallocating to %d nodes: old_address=%p, new_address=%p\n", new_nodes_size, old, _nodes); if (_verbose) showUpdate("Reallocating to %ld nodes: old_address=%p, new_address=%p\n", new_nodes_size, old, _nodes);
} }
} }
@ -1266,7 +1266,7 @@ protected:
bool side = D::side(m, n->v, _f, _random); bool side = D::side(m, n->v, _f, _random);
children_indices[side].push_back(j); children_indices[side].push_back(j);
} else { } else {
showUpdate("No node for index %d?\n", j); showUpdate("No node for index %ld?\n", j);
} }
} }
@ -1317,7 +1317,7 @@ protected:
std::priority_queue<pair<T, S> > q; std::priority_queue<pair<T, S> > q;
if (search_k <= 0) { if (search_k <= 0) {
search_k = n * _roots.size(); search_k = std::max(n * _roots.size(), (size_t )_n_items * 5 / 100);
} }
for (size_t i = 0; i < _roots.size(); i++) { for (size_t i = 0; i < _roots.size(); i++) {

View File

@ -27,6 +27,7 @@
#include <fiu-local.h> #include <fiu-local.h>
#include <algorithm> #include <algorithm>
#include <cmath> #include <cmath>
#include <limits>
#include <regex> #include <regex>
#include <string> #include <string>
@ -265,6 +266,13 @@ ValidationUtil::ValidateIndexParams(const milvus::json& index_params,
} }
break; break;
} }
case (int32_t)engine::EngineType::ANNOY: {
auto status = CheckParameterRange(index_params, knowhere::IndexParams::n_trees, 1, 1024);
if (!status.ok()) {
return status;
}
break;
}
} }
return Status::OK(); return Status::OK();
} }
@ -302,6 +310,14 @@ ValidationUtil::ValidateSearchParams(const milvus::json& search_params,
} }
break; break;
} }
case (int32_t)engine::EngineType::ANNOY: {
auto status = CheckParameterRange(search_params, knowhere::IndexParams::search_k,
std::numeric_limits<int64_t>::min(), std::numeric_limits<int64_t>::max());
if (!status.ok()) {
return status;
}
break;
}
} }
return Status::OK(); return Status::OK();
} }