Skip to content

Commit

Permalink
resolve a few issues in ngtpy
Browse files Browse the repository at this point in the history
  • Loading branch information
masajiro committed Feb 26, 2025
1 parent 8f88c12 commit c7b9bb7
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.3.11
2.3.12
7 changes: 5 additions & 2 deletions lib/NGT/Index.h
Original file line number Diff line number Diff line change
Expand Up @@ -1127,7 +1127,7 @@ class GraphIndex : public Index,
NGT::SearchContainer sc(searchQuery, *query);
#ifdef NGT_REFINEMENT
auto expansion = searchQuery.getRefinementExpansion();
if (expansion < 1.0) {
if (expansion < 1.0 || !refinementObjectSpaceIsAvailable()) {
GraphIndex::search(sc);
searchQuery.workingResult = std::move(sc.workingResult);
} else {
Expand Down Expand Up @@ -1575,6 +1575,9 @@ class GraphIndex : public Index,
ObjectSpace &getObjectSpace() { return *objectSpace; }
#ifdef NGT_REFINEMENT
ObjectSpace &getRefinementObjectSpace() { return *refinementObjectSpace; }
bool refinementObjectSpaceIsAvailable() {
return refinementObjectSpace != 0 && !refinementObjectSpace->getRepository().empty();
}
#endif
void setupPrefetch(NGT::Property &prop);

Expand Down Expand Up @@ -2163,7 +2166,7 @@ class GraphAndTreeIndex : public GraphIndex, public DVPTree {
NGT::SearchContainer sc(searchQuery, *query);
#ifdef NGT_REFINEMENT
auto expansion = searchQuery.getRefinementExpansion();
if (expansion < 1.0) {
if (expansion < 1.0 || !refinementObjectSpaceIsAvailable()) {
GraphAndTreeIndex::search(sc);
searchQuery.workingResult = std::move(sc.workingResult);
} else {
Expand Down
9 changes: 9 additions & 0 deletions python/src/ngtpy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,9 @@ class Index : public NGT::Index {
defaultRadius = FLT_MAX;
defaultEdgeSize = -1; // -1: use edge_size_for_search in the profile
defaultExpectedAccuracy = -1.0;
#ifdef NGT_REFINEMENT
defaultResultExpansion = 0.0;
#endif
}

static void create(
Expand Down Expand Up @@ -515,7 +518,9 @@ class Index : public NGT::Index {
defaultRadius = radius >= 0.0 ? radius : defaultRadius;
defaultEdgeSize = edgeSize >= -2 ? edgeSize : defaultEdgeSize;
defaultExpectedAccuracy = expectedAccuracy > 0.0 ? expectedAccuracy : defaultExpectedAccuracy;
#ifdef NGT_REFINEMENT
defaultResultExpansion = resultExpansion >= 0.0 ? resultExpansion : defaultResultExpansion;
#endif
}

size_t getNumOfDistanceComputations() { return numOfDistanceComputations; }
Expand Down Expand Up @@ -565,6 +570,7 @@ class Optimizer : public NGT::GraphOptimizer {

};

#ifdef NGTQ_QBG
class QuantizedIndex : public NGTQG::Index {
public:
QuantizedIndex(
Expand Down Expand Up @@ -1130,6 +1136,7 @@ class QuantizedBlobIndex : public QBG::Index {
size_t defaultFunctionSelector;
#endif
};
#endif // NGTQ_QBG

PYBIND11_MODULE(ngtpy, m) {
m.doc() = "ngt python";
Expand Down Expand Up @@ -1254,6 +1261,7 @@ PYBIND11_MODULE(ngtpy, m) {
py::arg("num_of_sample_objects") = -1,
py::arg("max_num_of_edges") = -1);

#ifdef NGTQ_QBG
py::class_<QuantizedIndex>(m, "QuantizedIndex")
.def(py::init<const std::string &, size_t, bool, bool, bool>(),
py::arg("path"),
Expand Down Expand Up @@ -1328,6 +1336,7 @@ PYBIND11_MODULE(ngtpy, m) {
, py::arg("function_selector") = 0
#endif
);
#endif // NGTQ_QBG

py::class_<BatchResults>(m, "BatchResults")
.def(py::init<>())
Expand Down

0 comments on commit c7b9bb7

Please # to comment.