feat(interface): add artifact-free online entity detection
Priority Level
Medium
Is your feature request related to a problem?
NeMo Anonymizer's supported API is designed around dataset workflows. Applications that need to inspect a small number of in-memory text records currently have to construct the full Data Designer-backed pipeline, create intermediate artifacts, and wait for optional LLM validation and augmentation.
That shape does not fit request-time integrations such as observability sanitizers. In representative testing, the full pipeline took 116.9 seconds cold and 39.9 seconds warm. A detector-only path completed representative batches in a few seconds, but there is no stable reusable API for calling that path directly and receiving source-anchored spans.
Describe the solution you'd like
Add a small asynchronous online detection API owned by Anonymizer. It should:
- accept ordered typed in-memory text records;
- call the existing OpenAI-compatible GLiNER endpoint through one reusable HTTP client;
- use bounded concurrency and a caller-configurable per-request timeout;
- return record-correlated entity spans anchored to the caller's exact source text;
- validate response structure, completion status, offsets, scores, requested labels, and overlap handling before returning;
- distinguish endpoint/timeout failures from invalid detector responses;
- avoid Data Designer execution and intermediate dataset artifacts; and
- keep source text and detector response bodies out of public error messages and chained exceptions.
The result deliberately omits raw entity values. A caller that needs one can derive it from the original text and the validated half-open offsets. The first API covers detector-only online inspection. LLM validation, augmentation, replacement, and full dataset anonymization remain on the existing pipeline unless separately designed and qualified.
Acceptance criteria
- [ ] Public inputs validate endpoint, model, labels, threshold, timeout, and concurrency.
- [ ] One detector instance reuses a persistent asynchronous HTTP client.
- [ ] Input record order and caller IDs are preserved.
- [ ] Returned spans use validated offsets into the caller's exact source text and do not trust detector-echoed text.
- [ ] Empty text is handled without an unnecessary detector request.
- [ ] Task creation and active requests are bounded, including across concurrent calls on one detector instance.
- [ ] Cancellation propagates normally and a failed record cancels unfinished sibling work.
- [ ] Timeout, transport, HTTP, malformed-response, and unsafe-span failures are typed; their messages and chained exceptions contain no source text.
- [ ] The API creates no parquet files, seed files, or Anonymizer artifact directories.
- [ ] Focused tests cover concurrency, ordering, authentication, lifecycle/client ownership, cancellation, and invalid responses.
- [ ] Existing file-backed and full-pipeline APIs remain compatible.
- [ ] Public documentation explains that detector-only output has different accuracy characteristics from the full pipeline.
Out of scope
- NeMo Relay event or codec handling.
- Mutating provider or tool traffic.
- A new hosted Anonymizer service.
- Full-pipeline latency changes.
- A new lightweight wheel; packaging can follow once the API boundary is accepted.
Related work
- #282 fixes canonical source values for the existing pipeline.
- #284 adds typed in-memory records.
- #286 is the draft NeMo Relay integration that would consume this API.