popoto.transfer.export¶
popoto.transfer.export
¶
Export a model's records to JSON Lines.
The driver holds no knowledge of any concrete field or mixin type. Auxiliary state is collected through two duck-typed passes:
- Field level -- iterate
_meta.fieldsand callexport_stateon each field. State is keyed by field name. - Model level -- walk
type(instance).__mro__and callexport_stateon any class that defines it as its own attribute. State is keyed by the class name.
Both passes test for the presence of the protocol member, never for membership of a named class, so a field or model mixin Popoto does not yet have participates with no change here.
DEFAULT_CHUNK_SIZE = 500
module-attribute
¶
Keys hydrated per round trip.
Query.keys() is a single unbatched SMEMBERS and get_many_objects
pipelines every HGETALL at once, so without chunking a large model would
hydrate entirely before a byte is written. Chunking bounds peak memory to one
chunk of instances. The key set itself is still resolved in one shot -- a known
ceiling, not solved here.
field_provenance(model_field)
¶
Return {provider, model, dimensions} for a field that has a provider.
Duck-typed on the presence of a provider attribute that exposes
dimensions; no concrete field class is named. Popoto stores no
provider or model identity alongside an embedding today, so this
fingerprint exists only in the export file. Import compares it against the
destination's provider and refuses a mismatch by default -- the difference
between a wrong vector space that errors and one that lands silently.
Returns:
| Type | Description |
|---|---|
'dict | None'
|
The provenance dict, or |
'dict | None'
|
A field whose provider cannot be resolved yields |
'dict | None'
|
rather than nothing, so the ambiguity is carried rather than hidden. |
Source code in src/popoto/transfer/export.py
collect_embedding_provenance(model_class)
¶
Return per-field provider fingerprints for every provider-backed field.
Source code in src/popoto/transfer/export.py
collect_field_policies(model_class)
¶
Return the per-field roundtrip_policy roll-up for the manifest.
Source code in src/popoto/transfer/export.py
collect_mixin_policies(model_class)
¶
Return the per-model-level-mixin roundtrip_policy roll-up.
Duck-typed on a class declaring roundtrip_policy or export_state
in its own __dict__, so a third-party model mixin with independent
Redis state appears in the report with no change here. Model itself
declares neither, so a model with no mixins yields {}.
Source code in src/popoto/transfer/export.py
export_records(model_class, *q_objects, stream=None, chunk_size=DEFAULT_CHUNK_SIZE, **filters)
¶
Export a model's records as JSON Lines.
Writes a manifest line followed by one line per record. Filter arguments
are forwarded verbatim to model_class.query.filter(...); with no
arguments the model's full key set is exported. An unknown filter
parameter raises QueryException from the query layer rather than being
quietly ignored.
Export is deliberately not a point-in-time snapshot. The key set is
resolved once and hydrated in chunks, so a record deleted in between is
counted as :attr:ExportResult.vanished and omitted, and a record created
afterwards is simply absent. matched_count is recorded at resolution
time so the gap is visible.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_class
|
The Model class to export. |
required | |
*q_objects
|
|
()
|
|
stream
|
'TextIO | None'
|
A text file-like object to write to. When |
None
|
chunk_size
|
int
|
Keys hydrated per round trip. Bounds peak memory. |
DEFAULT_CHUNK_SIZE
|
**filters
|
Plain keyword filters forwarded to |
{}
|
Returns:
| Name | Type | Description |
|---|---|---|
An |
ExportResult
|
class: |
Raises:
| Type | Description |
|---|---|
QueryException
|
If a filter parameter matches no known field. |
Example
with open("memories.jsonl", "w") as fh: result = export_records(Memory, project_key="ai", stream=fh) print(result.summary())
Source code in src/popoto/transfer/export.py
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 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 | |