Perception

Ground

client.documents.ground(source, *, targets, **options)

ParameterTypeRequiredDescription
sourcestr | UrlSource | WorkspaceFileSource | ParseResultSourceYesThe document to search.
targetslist[dict]Yes1 to 30 quotes to find. See targets.
optionsdictNoHow many matches, and whether to link previews. See options.

semantic belongs on each target; there is no top-level semantic. Ground takes neither page_ranges nor parse_mode.

Each dict option takes these keys:

targets

One entry per quote, each a dict:

KeyTypeDefaultDescription
targets[].idstrRequiredYour id for the quote, echoed on its result.
targets[].textstrRequiredThe quote to find.
targets[].hintstrNoneNearby text that tells a repeated quote apart.
targets[].page_hintslist[int]NoneOne-based pages to search first.
targets[].sheetstrNoneThe workbook tab to search. Ignored for other sources.
targets[].semanticboolFalseDeprecated. True fails that target with semantic_mode_deprecated on PDF, Word and PowerPoint sources.

options

KeyTypeDefaultDescription
options.max_matchesint10The locations to return per target, from 1 to 50.
options.minimum_semantic_scorefloatNoneFrom 0 to 1. Drops weaker semantic matches. It does nothing on PDF, Word and PowerPoint.
options.include_previewsboolFalseLink a cropped image for each visual hit.
ground.py
from nace_sdk import NaceClient

with NaceClient() as client:
    job = client.documents.ground(
        "https://example.com/report.pdf",
        targets=[
            {"id": "total", "text": "1,200.50"},
            {"id": "signer", "text": "Jane Smith", "hint": "Signed on behalf of the supplier"},
            {"id": "late_fee", "text": "Late payment fee"},
        ],
        wait_seconds=60,
    )
    if job.status != "succeeded":
        job = client.jobs.wait(job.job_id)

for target in job.result["targets"]:
    print(target["id"], target["status"], target["matches"][:1])

job.result is a plain dict:

  • Each target has id, status and matches.
  • Each match has rank, matched_text, match_method, confidence, cropped_image_url and location.
  • location has a kind that decides its other keys:
    • page_region: page, polygons
    • text_span: page, char_start, char_end
    • sheet_range: sheet, a1_range
    • row_range: start_row, end_row, column
    • json_pointer: pointer
    • jsonl_record: row_offset, column
    • audio_range: start_ms, end_ms

See Matches.

On this page