popoto.transfer.import_¶
popoto.transfer.import_
¶
Import records from a JSON Lines export produced by :mod:popoto.transfer.
Keys are always preserved. Records are saved one at a time -- deliberately not
through bulk_create -- because an external pipeline makes save() return
the pipeline for every record and destroys per-record observability, which the
reconciliation ledger depends on.
BATCH_SIZE = 500
module-attribute
¶
Records per conflict-check / reconciliation batch.
import_records(model_class, stream, on_conflict='error', on_write_gate='reject', on_embedding_mismatch='error')
¶
Import records from a JSON Lines export into model_class.
Keys are always preserved, so re-running an import converges rather than
duplicating, and every Relationship value and application-level key
pointer keeps pointing at the same record.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_class
|
The destination Model class. |
required | |
stream
|
TextIO
|
A text file-like object positioned at the manifest line. |
required |
on_conflict
|
str
|
What to do when the destination already holds a key.
|
'error'
|
on_write_gate
|
str
|
|
'reject'
|
on_embedding_mismatch
|
str
|
|
'error'
|
Returns:
| Name | Type | Description |
|---|---|---|
An |
ImportReport
|
class: |
ImportReport
|
skipped, rejected, errored, or partial, with a reason per non-landed |
|
ImportReport
|
record. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If a policy argument is not one of its allowed values. |
ModelException
|
If the manifest is missing, the format version is
unsupported, the model name does not match, an embedding
provenance mismatch is refused, or |
Note
Import is not atomic across records and assumes the destination is not
under concurrent write for this model. The recovery path for an
interrupted run is to re-run with on_conflict="overwrite".
Example
with open("memories.jsonl") as fh: report = Memory.import_records(fh, on_conflict="overwrite") print(report.summary())
Source code in src/popoto/transfer/import_.py
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 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 | |