24 Document Ai

Document AI

Much of what a business knows sits in documents nobody has time to read: a report of 400 pages, a year of board minutes, the recording of a meeting. Much of its integration work is someone typing an invoice into a form. Document AI is where you do both with Kloker. Read turns a document into text and answers your questions over all of it, however long it is. Extraction says what a kind of document should come out as, so that every invoice of that kind fills in the same JSON document. Both are thin pages over Kloker Document, Klok's service in the solution KLK003, and an integration uses the same service.

  • In the menu: Run → Document AI (/document-ai), with the tabs Read and Extraction
  • For: the developers and admins of the tenant or of one of its domains, and platform staff. An extraction configuration is saved by the tenant's admins and developers and by the admins and developers of its domain; everyone else with the page sees it read-only.
  • Reads: Kloker Document's API (klok-api-ai) for the files, the tasks, the kept texts and the results, always in the tenant you work in; tenant klok's ODL for the extraction configurations; the datamodel library when a configuration fills in a datamodel

What You See

Tab What it shows What you may do there
Read The document, your prompts and how it is read. While it runs, how far it has come. Afterwards the answers, the figures (pages read, tokens used, whether a kept text was used) and the transcript page by page, with what every picture, chart and diagram shows and means Read, Stop, Run the prompts again, The whole text
Extraction The tenant's configurations: what each fills in, its domain, how many prompts it has and when it was saved. A configuration's page has Target, Fields, Reading and Test New configuration, Suggest prompts, Test this draft, Save, Remove

Kloker reads a PDF, a Word, ODT or PowerPoint file, an e-book (EPUB, MOBI, AZW3, FB2), a batch of images or a recording. A long document is cut into parts of at most 190,000 tokens, each prompt runs on every part, and the answers are combined into one unless you ask to keep them apart.

What is kept, and who sees it. The file is kept seven days. The text and the result are kept 90 days unless you choose otherwise. Everyone in the tenant with the same file and the same reading options shares the text, so nobody pays for the same reading twice; Only you keeps the text and the task yours alone. Another tenant never reaches any of it. Every model is Kloker, on Klok's own servers.

Walkthrough: Ask About A Long Document

  1. Run → Document AI → Read. Choose the file. Several images are read as one document, in the order you chose them.
  2. Write what you want to know, one prompt per question. Kloker reasons before it answers; Kloker-nothink is faster.
  3. Press Read and follow Progress. You may leave the page: the address holds the task, so you can come back or send it to a colleague.
  4. Read the answers. A long document also shows the answer of each part, with the pages it covers.
  5. Check the transcript for the page that matters. If a table came out wrong, open How it is read, write a prompt for that page or raise the resolution, and press Read again with the file: only what changed is read again.
  6. Run the prompts again asks new questions over the text already read. No file is sent and no page is read, so only the prompts cost anything.

Walkthrough: Fill In A JSON Document From An Invoice

  1. Extraction → New configuration. Name it. On Target, choose a datamodel from the library, paste a JSON Schema, or paste one filled example and make the schema from it.

  2. On Fields, press Suggest prompts and let Kloker write a prompt per field. What it writes goes into your draft, ringed and listed, and nothing is saved until you do. Say in your own words where a value stands when that matters: The amount to pay, VAT included, usually at the bottom of the last page. A list of rows is one prompt; an object can be one too.

  3. On Reading, say what the documents are and how numbers and dates are written.

  4. On Test, choose a real invoice and press Test this draft. The draft runs as it stands, unsaved. Every field shows its value, its status and the quote and page it came from. If a value is wrong, What was read shows whether the fault is in the reading or in the prompt. Change a prompt and test again.

  5. Save. An integration now names the configuration by its id and gets this document from every invoice.

A value is never guessed. One that cannot be the field's type is reported with what the model wrote, and when the parts of a long document disagree, the page says so and lists what they said. Have someone check the results for a while before an integration acts on them on its own (Designing An AI Solution).

What Happens In Git

Nothing on these pages writes to Git. A reading is a task with a result, and a configuration is working material that changes no running flow until a request names it, so it is a record in an ODL rather than a merge request. Where a team wants it in Git, a configuration can be kept there.

In klok.dev Where it lands Approved by By hand
Read, Run the prompts again A task in Kloker Document; the file, the text and the result in Klok's storage, under your tenant — POST /v1/documents/read, or klok document read
Test this draft The same, with the whole draft in the request; nothing else is stored — POST /v1/documents/extract with extraction, or klok document extract --spec
Save, Remove The configuration as a KlokAiExtractionConfigV1 record in tenant klok's ODL with the id <tenant>.<slug>, conditional on the version you read Nobody; every save is a new version Tenant klok's admins: a PUT on klok-api-odl. Any other tenant: send the specification in the request instead of a configuration
A configuration kept in a repository Marked as managed by that commit; klok.dev shows it read-only Merged in that repository —

See What klok.dev Does In Git for every page.

Who Does What

Automation Kloker You
Kloker Document checks the file before the first model call, keeps each page as it is read so a retry resumes, cuts long texts, checks every value against the field's type and the schema, and removes what has passed its keep-time Reads the pages, answers the prompts, fills in the fields with structured output, and writes suggested prompts into your draft on request. It never saves, never tests and never changes the schema or the target Choose the documents and the questions, decide what counts in a prompt, test on real documents, save, and check the results

See You, The Automation And Kloker.

How It Connects

Going Deeper