Java · Filtered Search

Filtered Search

import cloud.unum.usearch.*; 3.0.0-rc.1 · cabb6603

Ask your coding agent about this page, or add the docs server to it

curl -s 'https://www.unum.cloud/docs/usearch/java/filtered-search.md' | claude -p "How would this fit my code?"

§ Callbacks

A java.util.function.Predicate<Key> on the search, multiply, attention and MaxSim configs decides which candidate keys a walk may report, and a Progress on every long verb hears its advance and cancels it by answering false, which the call reports as Status.CANCELLED. An insertion is all-or-nothing, so its progress handler cannot cancel it. Each runs as an upcall straight into your object, the predicate on the executor’s threads together and the progress handler never concurrently. Neither may throw: an exception escaping a callback terminates the process. A Predicate<Key> answers one key at a time, asked as candidates are scored, while a BatchPredicate answers an array of keys into an array of admissions, each starting as false, and is asked once per traversal round, for a handler that pays per call, such as a lookup in an external database. predicate(batch, PredicateCost.CHEAP) asks it as candidates arrive instead.

DenseSearchConfig filtered = new DenseSearchConfig(10).predicate(key -> allowed.contains(key));
DenseSearchConfig looked = new DenseSearchConfig(10).predicate((keys, admissions) -> database.admit(keys, admissions));
DenseSearchConfig watched = new DenseSearchConfig(10).progress((completed, total) -> !cancelRequested());
index.save("index.safegraphs", (completed, total) -> { bar.set(completed, total); return true; });

API

Types

ProgressHears how far a long call has advanced, in whatever units it consumes, and decides whether it goes on.
Types.java:2067 ↗
interface Progress

Never called concurrently, and never after the call it was passed to is final.

It must not throw; an exception escaping it terminates the process.

Functions

PhaseProgressWhere a plan stands once a call naming it returned.
Types.java:2127 ↗
record PhaseProgress(
    Phase phase,
    long ordinal,
    long completed,
    long total);

Parameters

phasethe kind of work in hand.
ordinalthis phase's position among the ones the plan runs.
completedunits of this phase done, entries or islands.
totalunits of this phase in all.