Previewing how a document type cuts a document
Before a site ingests its documents, document_preview_cli shows how a document type's configuration would cut one
of them: how many chunks, where each begins, how long each is and the context line each would carry when it is
embedded. A strategy tuned against a real file costs a few seconds here and nothing in the Node; tuned after a bulk
load, it costs a re-ingest of every document of the type (see Which changes are worth a targeted
re-ingest).
The command cuts with the function the Node ingests with, so what it shows is what would be stored. It connects to nothing, stores nothing and writes no Activity Log entry, so it can be run on any machine that holds the configuration, whether the Node is running or not. It never prints a document's text, only its lengths, its locators and its context lines.
python3 -m engine.document_preview_cli --config node.json sop sop-110.md # exits 0
Give it the configuration file the Node itself runs, the name of a type in its document_types section (or in the
starter catalogue, if the section is absent) and a UTF-8 text or markdown file. The configuration used below has three
types:
{
"document_types": {
"sop": {
"description": "A procedure.",
"strategy": { "name": "heading_sections", "heading_depth": 2, "min_chars": 10 },
"context": "{document_number} {title} — {heading_path}:",
"identity": { "first_line": "(?P<document_number>SOP-\\d+)\\s+(?P<title>.+)" }
},
"design_note": {
"description": "Notes around a drawing; every revision is kept.",
"revisions": { "policy": "keep", "previous": "leave" },
"strategy": { "name": "heading_sections", "heading_depth": 2, "min_chars": 10 },
"context": "{title} rev {revision_label} — {heading_path}:"
},
"design_note_strict": {
"description": "Notes around a drawing; a newer revision must say where it applies.",
"revisions": { "policy": "keep", "previous": "leave" },
"require_effective_range": true,
"strategy": { "name": "heading_sections", "heading_depth": 2, "min_chars": 10 },
"context": "{title} rev {revision_label} — {heading_path}:"
}
}
}
and the file is this procedure:
SOP-110 Seal Housing
# Seal housing
Torque the cover bolts to 40 Nm in a star pattern, in two passes, starting from the bolt nearest the drain port.
## Cleaning
Wipe the seal seat with isopropyl alcohol and let it dry fully before the seal is handled.
To try the command on documents of every common kind before a site's own arrive, see the sample document set.
What it prints
Document type sop: strategy heading_sections, configuration 4eb8a681b295
Stored as sop-110.md; title 'Seal Housing', number SOP-110, revision -
3 chunks (smallest 20, largest 128, mean 83 characters)
0 locator (preamble) text 20 chars context 'SOP-110 Seal Housing:'
1 locator Seal housing text 128 chars context 'SOP-110 Seal Housing — Seal housing:'
2 locator Seal housing > Cleaning text 103 chars context 'SOP-110 Seal Housing — Seal housing > Cleaning:'
Held to the embedding length limit of 6000 characters.
The Node would ingest this document.
Each chunk line gives the chunk's sequence number, its locator (the place in the document a later instruction
claim would point at, or - for a strategy that stamps none), the length of its text and its context line. The
last lines say whether the Node would take the document.
The embedding length limit is read from the configuration's embedding section (max_input_chars). A configuration
with no embedding section leaves it unchecked and the report says so.
A title, number and revision label come from the options below, or, for the title and number, from the type's
identity rule over the first line, as they do when a sender gives none. --document-id defaults to the file's
name; a file source uses the file's path below its directory.
| Option | Default | Meaning |
|---|---|---|
--config |
required | The Node's configuration file. |
--node-type-dir |
node-types/mes |
The directory of the Node Type the configuration is for. |
--shared-config-dir |
none | The directory of shared configuration fragments, if the configuration uses any. |
--document-id |
the file's name | The document's id, as a provider would give it. |
--title |
none | A title, as a sender would give one. A title that is given is not read from the first line. |
--document-number |
none | A document number, as a sender would give one. |
--revision-label |
none | The revision label. A type that keeps each revision needs one. |
--newer-revision |
off | An earlier revision of this document is on file, so a type that keeps each revision judges this one's effective range (see A newer revision's range). |
--effective-range |
off | The sender gives a unit, date or Mfg Order range. Only with --newer-revision. |
--json |
off | Print one JSON object instead of text. |
The two arguments that follow the options are the type's name and the file.
A newer revision's range
The command connects to nothing, so it cannot see whether an earlier revision of the document is on file. It judges a kept revision's effective range only when told, with --newer-revision, and says in the report when it did not.
Told, it does what the Node does for a newer revision that arrives with no range (and no --effective-range):
- A type with
require_effective_rangerefuses it witheffective_range: required ...naming the document and revision (exit 1). - Any other kept type stores it with an assumed start, which the command reports as the finding
no_effective_range(exit 3).
The command does not read the range from the file; --effective-range says the sender gives one. A type that replaces its revisions refuses both options (exit 2), since they mean nothing to it.
python3 -m engine.document_preview_cli --config node.json --revision-label B --newer-revision design_note_strict sop-110.md # exits 1
python3 -m engine.document_preview_cli --config node.json --revision-label B --newer-revision --effective-range design_note_strict sop-110.md # exits 0
python3 -m engine.document_preview_cli --config node.json --revision-label B --newer-revision design_note sop-110.md # exits 3
What the Node would refuse
The command refuses what ingestion refuses, names each rule the way ingestion's report does, and exits non-zero:
revision_label: required: the type keeps each revision and no--revision-labelwas given.source_document_id: contains_at_sign,revision_label: contains_at_sign: an@joins the id and label of a kept revision, so neither may hold one.text: no_chunks: the file gave no chunk, for example because it is empty.text: chunk_over_embedding_limit: a chunk with its context is longer than the embedding profile accepts. This is judged only when the configuration has anembeddingsection.effective_range: required: a newer revision of a type withrequire_effective_rangehas no range. This is judged only with--newer-revision(see above).
python3 -m engine.document_preview_cli --config node.json design_note sop-110.md # exits 1
python3 -m engine.document_preview_cli --config node.json --revision-label B design_note sop-110.md # exits 0
A fallback is shown, not hidden
A document the type cuts badly can still be ingested, so the report lists what to look at as findings and the command exits with 3. The report prints each finding with its reason.
| Finding | What happened |
|---|---|
no_headings_found |
The type cuts by heading and the text has none, so it is one section with the locator (document). |
boundary_rules_unmatched |
None of a boundary_rules type's patterns matched, so the document is one chunk. |
over_type_maximum |
A chunk is longer than the type's maximum. |
identity_rule_unmatched |
The type's identity rule did not match the first line, so the title and number were not read from it. |
title_taken_from_document_id |
The type has an identity rule and no title was given or read, so the title is the document id. It comes with identity_rule_unmatched when the rule did not match, and alone when the rule matched but names no title group (a rule that reads only the document number). |
no_effective_range |
With --newer-revision: a newer revision with no range, which the Node stores with an assumed start and a warning. |
document_type_blank |
The type given was blank, so it is generic, as it is on intake. |
A rule that matched and read a title, or one that was not consulted because the title and number were given, is not a
finding. A title that was not given, for a type with no identity rule, is not either: the identity line shows what is
used.
Torque the cover bolts to 40 Nm in a star pattern, in two passes. Wipe the seal seat with isopropyl alcohol.
python3 -m engine.document_preview_cli --config node.json sop plain.md # exits 3
Exit codes
The exit code is the command's promise; the text it prints is not, so do not parse it. --json is the form to read
from a program, and its keys may only be added to. The command is part of the public API.
| Code | Meaning |
|---|---|
| 0 | The Node would ingest the document and there is nothing to look at. |
| 1 | The Node would refuse the document; the report names each rule. |
| 2 | The request could not be used: a configuration, type, file or option that is refused, or a file that is not UTF-8 text. |
| 3 | The Node would ingest the document, with findings. |
python3 -m engine.document_preview_cli --config node.json --json sop sop-110.md # exits 0
The JSON has these keys:
verdict:would_ingest,would_ingest_with_findingsorwould_refuse.document_type,strategy,configuration_fingerprint,stored_document_idandidentity.embedding_limit_charsandchunk_count.chunks: each withsequence,locator,text_charsandcontext.findingsandrefused.range_judged: false for a kept type's revision when--newer-revisionwas not given.
Nothing here replaces the offline check, which proves a configuration is well formed. This command shows what a well formed configuration does to a document.
Release: v0.11.0