find(), which returns the exists probability and one relevance score per
line.

- Tag each line with an ID so Jev can point to it.
- Use a
Choicequestion to rank those line IDs by how well they answer the query. - In the same request, use a
Noulquestion to check whether the document contains an answer at all.
Setup
Run in Colab
Runs as published without an API key.
Python file
This page as one .py file, to run locally.
Open in playground
Edit one request and run it live. Needs a TypeSafe account.
uv run semantic_find.py installs the dependencies for you.
The code replays saved answers, so it runs as published without an API key. To change a
request, create a TypeSafe API key and set
TYPESAFE_API_KEY; in Colab, add it in the Secrets panel.
The first block imports typesafe_sdk, reads TYPESAFE_API_KEY and creates the client:
Step 1: tag every line with an ID
The test document is GitHub’s Terms of Service, split into 218 clauses, so every search result points to one quotable line.DOCUMENT now looks like this:
Step 2: ask where the answer is
AChoice question returns a probability for every option. Use the line IDs as the
options.
None because the document already contains the text for each
ID. The query goes in instructions; the state stays unchanged between searches.
A
Choice question accepts up to 255 options, so this recipe searches documents of
up to 255 lines in one request. Past that, search in two passes: one Choice question picks
a window
of lines, and a second ranks the lines inside it. Step 3: check whether an answer exists
Choice probabilities always add up to 1, so some line ranks first even when the document doesn’t answer the question.Step 4: send both questions in one request
Both questions go in onesystem_one call, so the document is sent once.
relevance list keeps one score per line, in document order.
Step 5: read the result
Theexists probability becomes one of three verdicts, the middle one for partial
answers. The ranking prints as a bar chart.
Step 6: run the search
Ask two questions that have direct answers, one that has a partial answer, and one that has no answer.What the scores mean
The first two queries return direct answers and the source lines needed to verify them.- Arbitration: The Terms never mention arbitration. The top line, at 0.80, is the
governing-law clause, which sends disputes to the courts in San Francisco.
existsis 0.65, so the result is partially addressed. - Class action: The Terms never mention class actions. The ranking still puts the
governing-law clause first, at 0.23, because a ranking always has a top line.
existsis 0.05, so the result is not in this document.
exists score tells you whether the result
answers the question.
To search your own document, load its lines into LINES; every other line of the script
works off LINES.

