MCPcopy Create free account
hub / github.com/NGT-labs/NGT / batchSearch

Method batchSearch

python/src/ngtpy.cpp:427–467  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

425 }
426
427 void batchSearch(
428 py::array_t<float> queries,
429 BatchResults &results,
430 size_t size,
431 bool withDistance = true
432 ) {
433 const py::buffer_info &qinfo = queries.request();
434 const std::vector<long int> &qshape = qinfo.shape;
435 auto nOfQueries = qshape[0];
436 size_t dimension = qshape[1];
437 auto *queryPtr = static_cast<float*>(qinfo.ptr);
438 size = size > 0 ? size : defaultNumOfSearchObjects;
439
440 results.results.clear();
441 results.resultList.clear();
442 results.results.resize(nOfQueries);
443 results.size = 0;
444
445#pragma omp parallel for schedule(dynamic)
446 for (int idx = 0; idx < nOfQueries; idx++) {
447 float *qptr = queryPtr + idx * dimension;
448 std::vector<float> qvector(static_cast<float*>(qptr), static_cast<float*>(qptr) + dimension);
449 NGT::SearchQuery sc(qvector);
450 sc.setSize(size);
451 sc.setRadius(defaultRadius);
452 sc.setExpectedAccuracy(defaultExpectedAccuracy);
453 sc.setEpsilon(defaultEpsilon);
454 sc.setEdgeSize(defaultEdgeSize);
455#ifdef NGT_REFINEMENT
456 sc.setRefinementExpansion(defaultResultExpansion); // set refinement expansion.
457#endif
458 if (treeIndex) {
459 NGT::Index::search(sc);
460 } else {
461 NGT::Index::searchUsingOnlyGraph(sc);
462 }
463 results.results[idx] = std::move(sc.getWorkingResult());
464 }
465 results.size = results.results.size();
466 return;
467 }
468
469 void remove(size_t id) {
470 id = zeroNumbering ? id + 1 : id;

Callers

nothing calls this directly

Calls 10

setSizeMethod · 0.80
setRadiusMethod · 0.80
setExpectedAccuracyMethod · 0.80
setEpsilonMethod · 0.80
setEdgeSizeMethod · 0.80
searchFunction · 0.50
clearMethod · 0.45
resizeMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected