Console ↗

Span

Find every passage matching a description in the string values of the supplied state.

Define a question

Supply type: "span" and instructions as text, an object or an array. Omit criteria. Describe the target and its boundaries. A single request can combine Span with Choice, Score, Noul or Box.

{
  "model": "ngila-judge",
  "state": {
    "minutes": [
      "📋 The meeting was chaired by Alice Johnson.",
      "The report was prepared by Robert Miller."
    ]
  },
  "questions": {
    "names": {
      "type": "span",
      "instructions": "Find all personal names in the meeting notes. Return the full name of each person."
    },
    "mentions_date": {
      "type": "noul",
      "instructions": "Do the notes give the meeting date?"
    }
  }
}

Read the matches

This example answer contains two names. The outer confidence estimates whether matching text exists anywhere in state. Each returned match also carries its own confidence. An empty spans array means the model selected no passages.

{
  "type": "span",
  "spans": [
    {
      "path": "/minutes/0",
      "start": 29,
      "end": 42,
      "text": "Alice Johnson",
      "confidence": 0.9524
    },
    {
      "path": "/minutes/1",
      "start": 27,
      "end": 40,
      "text": "Robert Miller",
      "confidence": 0.9895
    }
  ],
  "confidence": 0.9917
}

Resolve source locations

A JSON Pointer identifies the string value in the original state. The empty pointer selects the root string. Decode ~1 as a slash and ~0 as a tilde inside each path component. Array indices are zero-based. Matches refer to text values only. Keys, instructions and pixels have no text offsets.

Slice by Unicode code point

Start is inclusive and end is exclusive. In Python, source[start:end] yields the returned text. In JavaScript, convert the string to code points first so emoji before the match are counted correctly.

const source = state.minutes[0];
const {start, end, text} = answer.spans[0];
console.log(Array.from(source).slice(start, end).join("") === text);

Use matches in an application

Group matches by path before highlighting them. For redaction, edit each source string in descending offset order. Evaluate missed matches as well as incorrect boundaries on representative data before choosing a threshold.

Run the meeting notes example in Playground →