Stages API
scinr.newton.stages.run_preprocess
async
Convert raw source files to intermediate JSON using the converters module.
Also stores raw files (binary) and converted pages in MongoDB via the
storage layer when a backend is configured (STORAGE_BACKEND env var).
Parameters
input_raw: Path to the folder containing raw source files (PDF, DOCX, XLSX, etc.). output_dir: Path to the output folder where intermediate JSON files will be written. If None, converted documents are only available in memory; no files are written to disk. context_instructions: Optional free-text context about the documents being processed.
Returns
tuple[StageResult, list[IntermediateDocument]] A StageResult with counts and errors, and a list of IntermediateDocument objects (one per successfully converted file).
Source code in src/scinr/newton/stages/preprocess.py
scinr.newton.stages.run_extraction
async
run_extraction(
input_folder=None,
output_folder=None,
intermediate_documents=None,
parallel_docs=1,
)
Process intermediate JSON files or IntermediateDocument objects through the LLM extraction pipeline and produce Document objects.
Exactly one of input_folder or intermediate_documents must be provided. If output_folder is given, the extracted Document JSON is also written to disk (mirroring subdirectory structure). If not, documents only exist in memory.
Parameters
input_folder: Path to the directory containing input JSON files from Stage 0 (searched recursively). Mutually exclusive with intermediate_documents. output_folder: Path to the directory where extraction output files will be written. If None, extraction output is only available in memory. intermediate_documents: List of IntermediateDocument objects from run_preprocess() (in-memory mode). Mutually exclusive with input_folder. parallel_docs: Maximum number of documents to process concurrently.
Returns
tuple[StageResult, list[Document]] A StageResult with counts and errors, and a list of Document objects (one per successfully extracted document).
Source code in src/scinr/newton/stages/extraction.py
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 | |
scinr.newton.stages.run_ingestion
async
Load extracted documents into Neo4j.
Accepts documents either from disk (via output_folder or files) or
directly as in-memory :class:~models.document_structure.Document objects
(via documents). Exactly one source must be provided.
Parameters
output_folder:
Path to the directory containing extract-*.json files. Used when
neither files nor documents is provided.
files:
Explicit list of JSON extraction file paths to ingest. Takes priority
over output_folder when both are given.
documents:
List of in-memory Document objects from run_extraction() (in-memory
mode). When provided, output_folder and files are ignored.
update_mode:
If True, wipe existing structure of the latest version and re-insert
without creating a new version.
Returns
StageResult Stage result with one DocumentResult per ingested document.
Raises
ValueError If no source is provided.
Source code in src/scinr/newton/stages/ingestion.py
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 | |
scinr.newton.stages.run_annotation
async
run_annotation(
document_name,
manual=False,
model_class=None,
parallel_docs=1,
only_unannotated=False,
context_instructions_override=None,
)
Run the annotation stage for an already-ingested document.
In normal mode delegates to :func:annotation.agent.run_annotation_agent.
In manual mode delegates to :func:annotation.agent.run_manual_annotation,
assigning model_class to every qualifying StructureNode without invoking
the LLM.
Parameters
document_name: Name of the document node already present in Neo4j. manual: If True, run in manual override mode instead of the LLM agent. model_class: CamelCase model class name required when manual is True. parallel_docs: Maximum number of leaf documents to annotate concurrently when document_name refers to a folder. only_unannotated: When True, only process StructureNodes without a :HAS_MODEL_DECISION relationship. Ignored when manual is True. context_instructions_override: When provided, use this context string instead of fetching from Neo4j.
Returns
StageResult Stage result with per-document annotation counts and errors.
Raises
ValueError If document_name is empty, or if manual is True but model_class is not provided.
Source code in src/scinr/newton/stages/annotation.py
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 | |
scinr.newton.stages.run_entity_extraction
async
Run the entity extraction agent for an already-annotated document.
Delegates to :func:entity_extraction.agent.run_entity_extraction_agent.
Parameters
document_name: Name of the document node already annotated in Neo4j. parallel_docs: Maximum number of leaf documents to extract concurrently when document_name refers to a folder. only_unextracted: When True, only process StructureNodes without a :HAS_EXTRACTION relationship.
Returns
StageResult Stage result with per-document extraction counts and errors.
Raises
ValueError If document_name is empty.
Source code in src/scinr/newton/stages/entity_extraction.py
scinr.newton.stages.run_tabular_pipeline
async
run_tabular_pipeline(
input_raw,
update_mode=False,
parallel_docs=1,
tabular_extensions=None,
tabular_delimiter=None,
)
Ingest all tabular files (CSV/XLSX/XLS) in input_raw directly into Neo4j.
Bypasses Stages 0-4 entirely. For each file: 1. Reads headers + 5-row preview. 2. Makes one LLM call to decide the extraction model. 3. Makes one LLM call to map columns to model fields. 4. Writes Table + Row StructureNode subgraph to Neo4j directly.
Parameters
input_raw: Folder containing raw tabular files (searched recursively). update_mode: If True, wipe existing Table/Row subgraph and re-insert. parallel_docs: Maximum number of files to process concurrently. tabular_extensions: Set of file extensions to treat as tabular. Defaults to {'.csv', '.xlsx', '.xls'} when None. tabular_delimiter: Field delimiter for CSV files. When None, uses the default delimiter of the tabular agent.
Returns
StageResult Stage result with per-document ingestion counts and errors.
Source code in src/scinr/newton/stages/tabular.py
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 | |