Perception

Ground

client.documents.ground(params, options?) finds where each quote appears. It takes the shared parameters and:

ParameterTypeRequiredDescription
targetsArray<{ id, text, hint?, sheet?, semantic?, page_hints? }>Yes1 to 30 quotes to find. See targets.
options{ max_matches?, include_previews?, minimum_semantic_score? }NoHow many matches, and whether to link previews. See options.

Ground takes no page_ranges and no parse_mode, and semantic belongs on each target: a top-level semantic is refused with 422.

Each object option takes these keys:

targets

One entry per quote, each an object:

KeyTypeDefaultDescription
targets[].idstringRequiredYour id for the quote, echoed on its result.
targets[].textstringRequiredThe quote to find.
targets[].hintstringNoneNearby text that tells a repeated quote apart.
targets[].page_hintsArray<number>NoneOne-based pages to search first.
targets[].sheetstringNoneThe workbook tab to search. Ignored for other sources.
targets[].semanticbooleanfalseDeprecated. true fails that target with semantic_mode_deprecated on PDF, Word and PowerPoint sources.

options

KeyTypeDefaultDescription
options.max_matchesnumber10The locations to return per target, from 1 to 50.
options.minimum_semantic_scorenumberNoneFrom 0 to 1. Drops weaker semantic matches. It does nothing on PDF, Word and PowerPoint.
options.include_previewsbooleanfalseLink a cropped image for each visual hit.
ground.ts
const job = await client.documents.ground({
  source: { type: "url", url: "https://example.com/report.pdf", file_name: "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" },
  ],
});
const done = await client.jobs.wait(job.job_id);

job.result is a plain object (unknown in the types):

  • 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