ó
    À‘´j¯ý  ã                  ó  • S r SSKJr  SSKrSSKrSSKrSSKrSSKrSSKJ	r	  SSK
JrJrJr  SSKJr  \R                   " 5         \R"                  " \R$                  SS9  SS	KJr  SS
KJr  SSKJrJr  SSKJrJr  SSKJrJrJ r J!r!  SSK"J#r#  SSK$J%r%  SSK&J'r'  \'" 5       RP                  RR                  r*Sr+1 Skr,S.S jr-S/S jr.S0S jr/S1S jr0S2S jr1S3S jr2S4S jr3S5S jr4S6S jr5S7S8S jjr6      S9S jr7        S:S jr8S;S jr9S<S  jr:S=S! jr;S>S" jr<S?S# jr=S@S$ jr>SAS% jr?SBSCS& jjr@          SDS' jrA      SES( jrBSFS) jrCSGS* jrD      SH                     SIS+ jjrESBSJS, jjrF\GS-:X  a  \F" 5         gg)Kuí  Ingest quber *fusion* output into the pgvector playground schema.

The package's only ingester. It requires the source PDF and two artifacts the
quber fusion workflow writes:

  <base>.unified.json  â€” the unified DoclingDocument (spine: reading-order
                         text + headings, each with page + PDF-point bbox)
  <base>.tables.json   â€” the corrected ExtractedTable list (LLM-cleaned
                         markdown, title, units, page, normalized regions)

The PDF is hashed for the document row and rendered for the footnote lookup
agent. The fusion report and three figure-run artifacts are optional inputs,
described below.

Mapping to the RAG schema, by chunk_type:
  - text         <- unified.json `texts` (bbox normalized to top-left 0..1),
                    and in the grouped stream one record per binding group
  - picture      <- unified.json `pictures` that carry a description or values
                    and are not a logo, icon or watermark
  - figure_values <- one record per page of figure values no picture claims
  - table        <- tables.json, plus SoM-missed docling tables. A tables.json
                    chunk leads with its section heading and header lines,
                    then the cell-id HTML grid (the markdown when the table has
                    no grid), then its footnote block. Its region is already
                    normalized top-left 0..1.
  - line_item    <- one record per printed line of a gridded table that
                    carries a header depth

Grounding is cell-level: each table's `corrected_grid` supplies one
GroundedCell per markdown cell â€” text, a box normalized 0..1 top-left, a
provenance status, and the status inspector's note where one was taken. The
table chunk's content is an HTML table with an id on every cell
(`<td id="t<table>-<row>-<col>">`), so the agent can cite individual cells and
the app resolves them to overlays. Every
cell is served regardless of status; a cell whose box could not be traced
falls back to a box read off its boxed neighbours, then to the table's region,
and keeps its status/note so the UI can flag it. A table without a
`corrected_grid` gets no cell groundings. Its chunk is its markdown with no
cell ids, so it can be cited only as a whole table.

Footnotes attach to the chunks that reference them. Each table's and each
figure's markers are resolved in tier order: in-crop pairs, then a
reading-order scan, then the demand-driven lookup agent. A marker the
correction agent judged a cross-reference to a named section resolves to a
pointer at that heading rather than to definition text. The resolved text is
appended as a footnote block â€” on the whole-table chunk (all notes, plus
unmarked general notes), on each line record whose rendered rows carry the
marker, and on each picture chunk. The block is kept out of the embedding. It
stays in the stored content, so keyword search matches it. Unresolved markers,
unreferenced definitions, and unplaced markers land as tableFlag groundings,
quoted verbatim.

The fusion report (`<base>.fusion.json`), when given, matches each SoM table to
its docling table. That match gives the table chunk its fused caption lines and
section heading, places the table in the reading order so its footnote scan
starts after it and stops at the next table, and gives a footnote text that
directly follows the docling table a parent link to the SoM table's chunk. A
table with no match, which includes every scanned table, falls back to its own
caption, title, subtitle and units, takes no local section heading, gets no
footnote parent link, and scans every line from its page onward for footnotes.
The report also names any docling table the Set-of-Mark engine missed
(`som_miss`). Those tables exist only in the unified document, so they are
ingested from there as plain table chunks â€” docling's own cell text,
table-level grounding â€” rather than dropped.

The figure run (`quber.core.figures.orchestrator`) writes the three optional
artifacts. Its scanned
tables (`<base>.scanned-tables.json`) are `ExtractedTable`s like any other and
join the table engine's own, so a table read off a page image is chunked,
grounded and footnoted by the same code. Its run record (`<base>.figures.json`)
names the parse tables those replaced, and the parse's reading of a replaced
table is then not ingested beside the scan's.

Its figure values (`<base>.figure-values.json`) carry the
reconciled per-value reading of each figure with per-value provenance. Each
value becomes a grounding of its own â€” ref id `fv-<n>`, its reconciliation
status and note, and the value's box on the page (already normalized top-left
0..1; a value with no box of its own borrows its picture's). The values are
also listed as `[fv-<n>]`-tagged plain text lines, on the picture chunk they
belong to or, for a value with no picture, on its page's figure_values
record. The answering model cites a plotted value by that id as precisely as
a table cell. A value whose picture is a logo, icon or watermark is listed on
no chunk and exists only as its grounding.
é    )ÚannotationsN)ÚPath)ÚAnyÚOptionalÚSequence)ÚloggerÚINFO)Úlevel)ÚFootnoteDef)Ú
SCAN_BLOCK)ÚFOOTNOTE_MARKS_FIELDÚFOOTNOTES_FIELD)ÚFigureValueÚFigureValueRun)ÚFootnoteResolutionÚabsorb_lookupÚcanonical_markerÚresolve_footnotes)Údb)Úembed_document)Úget_settingsz
Footnotes:
>   ÚiconÚlogoÚ	watermarkc                ó  • U (       d  gU R                  S5      (       d@  [        U 5      R                  5       (       d"  [        R                  " SUR
                  5        g[        R                  " [        X5      R                  5       5      $ )uù  An optional artifact, read if it is there.

The figure run writes its scanned-tables file only when it read a table off
a page image, and its figure-values file whenever the value step ran,
which needs the page cells beside the parse, even if it read no values. A
document never put through the figure run has none of its artifacts. A
local path that does not exist is not an error â€” it says the run produced
nothing of that kind. An s3:// URI is fetched without that check, so a
missing object raises.
Nús3://z!no {} to read; the run wrote none)
Ú
startswithr   Úexistsr   ÚinfoÚnameÚjsonÚloadsÚ_fetchÚ	read_text©ÚsrcÚdests     Ú</home/mande/repo/quber/src/quber/playground/ingest_fusion.pyÚ_fetch_optionalr)   Œ   s^   € ö ØØ�>‰>˜'×"Ñ"¬4°«9×+;Ñ+;×+=Ñ+=Ü�ŠÐ7¸¿¹ÔCØÜ�:Š:”f˜SÓ'×1Ñ1Ó3Ó4Ð4ó    c           	     ó  • UR                   R                  SSS9  U R                  S5      (       a&  [        R                  " SSSU [        U5      /SSS9  U$ UR                  [        U 5      R                  5       5        U$ )NT)ÚparentsÚexist_okr   ÚawsÚs3Úcp)ÚcheckÚcapture_output)	ÚparentÚmkdirr   Ú
subprocessÚrunÚstrÚwrite_bytesr   Ú
read_bytesr%   s     r(   r#   r#   Ÿ   sq   € Ø‡K�K×Ñ˜d¨TÐÑ2Ø
‡~�~�g×ÑÜ�Š˜˜t T¨3´°D³	Ð:À$ÐW[Ò\ð €Kð 	×Ñœ˜c›×-Ñ-Ó/Ô0Ø€Kr*   c                ó†   • U (       a0  U(       a)  U R                  5       UR                  5       :w  a  U  SU 3$ U=(       d    U $ )u  The section vocabulary a chunk rides with: the page's opening heading
joined with the heading in effect at the chunk.

A presentation page opens with its subject â€” 'Commercial Portfolio
Geographic Diversification' â€” and then prints panel labels the parse also
calls headings ('U.S.', 'Europe', 'Australia'). Carrying only the latest
heading strips the page's subject from every chunk below the first panel
label, and a question phrased in the subject's words then never ranks the
chunk. Both ride along; when they agree, one.
õ    â€” ©Úlower)Úpage_headingÚheadings     r(   Ú
_governingr@   ¨   s;   € ö ž L×$6Ñ$6Ó$8¸G¿M¹M»OÓ$KØ�˜u W IÐ.Ð.Ø×"�lÐ"r*   c                ód   • US:H  =(       a%    U R                  5       =(       a    [        U 5      U:H  $ )u|  Is this text the page printing its own number and nothing else?

The page's furniture layer is where the parse puts what it takes for page
decoration, but its guess is unreliable in the direction that matters: on a
financial deck that layer also holds the footnote definitions that qualify
the figures, so it cannot be excluded wholesale. A page number is the one
thing in it that can be named exactly rather than guessed at â€” a furniture
text whose whole content, read as an integer, is the number of the page it
sits on. Anything that fails to match is kept, so a deck whose printed
numbering runs off the page index loses nothing.
Ú	furniture)ÚisdigitÚint)ÚtextÚpageÚcontent_layers      r(   Ú_is_page_numberrH   ¸   s(   € ð ˜KÑ'×P¨D¯L©L«N×P¼sÀ4»yÈDÑ?PÐPr*   c           
     ó  • U R                  S5      =(       d    0 R                  [        5      =(       d    /  Vs/ s HE  nUR                  S5      (       d  M  [        UR                  SS5      UR                  SS5      S9PMG     sn$ s  snf )z?The notes an agent read off the page this figure is printed on.ÚmetarE   ÚmarkerÚ ©rK   rE   )Úgetr   r   )ÚpicÚns     r(   Ú_picture_notesrQ   Ç   st   € ð —7‘7˜6“?×( b×-Ñ-¬oÓ>×DÀ"ÐDóâDˆAØ�5‰5��=ó 	HŒ˜1Ÿ5™5 ¨2Ó.°Q·U±U¸6À2Ó5FÔGÙDñð ùò s   ¹BÁ.Bc                ó€   • [        U R                  S5      =(       d    0 R                  [        5      =(       d    / 5      $ )zÍThe footnote reference markers an agent read off this figure.

Each carries what it points at, so a cross-reference to a named part of the
document is never hunted among the lines printed near the figure.
rJ   )ÚlistrN   r   )rO   s    r(   Ú_picture_marksrT   Ð   s-   € ô �#—'‘'˜&“/×' R×,Ñ,Ô-AÓB×IÀrÓJÐJr*   c           	     óè   • U (       d
  [        5       $ U R                  S/ 5       VVVs1 s H9  nUR                  S/ 5        H  nUR                  S5      nU(       d  M  UiM!     M;     snnn$ s  snnnf )aA  The parse tables a scanned table replaced, from the figure run's record.

The fusion report names a table the table engine missed, so the ingest reads
that table out of the parse. Where the figure run has since replaced the
parse's reading with the scan's, reading it out of the parse again would
state one region twice.
ÚscansÚtablesÚ	table_ref)ÚsetrN   )r6   ÚscanÚtableÚrefs       r(   Ú_superseded_refsr]   Ù   si   € ö Ü‹uˆð —G‘G˜G RÔ(õâ(ˆDØ—X‘X˜h¨×+ˆEØ—I‘I˜kÓ*ˆCÜ÷	 	á+ñ 	Ù(óð ùô s   ¨2A-Á
A-c                óÖ   • U R                  S5      =(       d    0 nUR                  S5      =(       d    0 R                  S5      =(       d    / nU(       a  US   R                  SS5      $ S$ )zEThe parse's top predicted class for a picture, or '' if unclassified.rJ   ÚclassificationÚpredictionsr   Ú
class_namerL   )rN   )rO   rJ   Úpredss      r(   Ú_picture_classrc   ì   sT   € à�7‰7�6‹?× ˜b€DØ�h‰hÐ'Ó(×.¨B×3Ñ3°MÓB×IÀr€EÞ-2ˆ5�‰8�<‰<˜ bÓ)Ð:¸Ð:r*   c                ó6   • U(       a  SU  SU SU 3$ SU  SU 3$ )u³  One value line the answering model can cite.

The `[fv-n]` tag is the citation contract: the model quotes the id and the
app resolves it to that value's own grounding box, so the overlay is the
printed value rather than whatever chunk carried the line. Every chunk
that serves figure values builds its lines here â€” the tag must never be
reimplemented per chunk kind, because a line without it can only be cited
at chunk granularity.
Ú[z] z: © )Úfidr    Úvalues      r(   Ú_cited_lineri   ó   s1   € ö *.ˆQˆsˆe�2�d�V˜2˜e˜WÐ%ÐE°Q°s°e¸2¸e¸WÐ3EÐEr*   c                óð  • [        U 5      [        ;   a  gU R                  S5      =(       d    0 R                  S5      =(       d    0 R                  S5      =(       d    SnUR                  5       nU(       a€  / nU HX  u  pVSR	                  S UR
                  UR                  4 5       5      nUR                  [        XWUR                  5      5        MZ     U(       a  US-   OSS	R	                  U5      -   nU$ )
aÚ  What a picture says, or '' when it says nothing worth retrieving.

A chart's plotted values live in the description the page scan wrote, which
names the axes, the units, the legend and every plotted figure, so a
picture carrying one is a retrievable record like any other.

`values` are this picture's reconciled figure values, each with its
grounding ref id. They are appended as an id-tagged line per value, so the
answering model can cite a plotted value by id, as it cites a grid cell,
and the app resolves it to an overlay.

Excluded: a watermark, an icon, a logo. They are identity marks repeated on
every page with nothing inside to read. A picture with no description and
no values is excluded too, having nothing to say.
rL   rJ   ÚdescriptionrE   Ú c              3  ó6   #   • U  H  o(       d  M  Uv •  M     g 7f©Nrf   )Ú.0Úps     r(   Ú	<genexpr>Ú _picture_text.<locals>.<genexpr>  s   é € Ð@Ò': !»aŸA™AÒ':ùó   ‚
�	z	
Values:
zValues:
Ú
)
rc   ÚEXCLUDED_PICTURE_CLASSESrN   ÚstripÚjoinÚlabelÚseriesÚappendri   rh   )rO   Úvaluesrk   rE   Úlinesrg   Úvr    s           r(   Ú_picture_textr~      sÅ   € ô  �cÓÔ6Ó6ØØ—G‘G˜F“O×) r×.Ñ.¨}Ó=×CÀ×HÑHÈÓP×VÐTV€KØ×ÑÓ€DÞØˆÛ‰FˆCØ—8‘8Ñ@¨¯©°·±Ñ':Ó@Ó@ˆDØ�L‰Lœ S°·±Ó8Ö9ñ ö )-��}Ò$°+ÀÇÁÈ5ÓAQÑQˆØ€Kr*   c           	     ó€  • 0 nU  HD  u  p4UR                   (       a  M  UR                  UR                  / 5      R                  X445        MF     / n[	        U5       Hà  n/ nX&    Hc  u  p4SR                  S UR                  UR                  UR                  4 5       5      nUR                  [        X8UR                  5      5        Me     SR                  U5      n	UR                  US5      n
U
(       a)  U
R                  5       U	R                  5       ;  a  U
 SU	 3n	UR                  SU 3SUS-
  SU	S45        Mâ     U$ )	u  One searchable record per page of figure values no picture claims.

An anchored value rides its picture chunk's searchable text, unless the
picture is a logo, icon or watermark: that picture has no chunk, and its
values are not collected here either, so they exist only as grounding
rows. An unanchored value has no chunk to ride and its grounding row alone
is invisible to retrieval â€” a printed number the index never hears of.
Each page's unanchored values become one record of id-tagged label-value
lines under the page's opening heading, id `figure-values-p<page>`. The id
tags are built by `_cited_line`, as `_picture_text` builds a picture's
values: the answering model cites the value's own
`fv-<n>` id, which resolves to that value's tight box rather than the
record's. The record itself carries NO box, deliberately: a citation of
the record alone names the page, and the only rectangles ever drawn are
the values' own. A synthetic union box was tried and rendered as a
misleading figure-sized highlight over the tight one.
r;   c              3  ó6   #   • U  H  o(       d  M  Uv •  M     g 7frn   rf   )ro   Úparts     r(   rq   Ú,_unanchored_value_records.<locals>.<genexpr><  s   é € Ð\Ò1S¨ÓW[§¡Ò1Sùrs   rt   rL   úfigure-values-pÚfigure_valuesé   N)Úpicture_refÚ
setdefaultrF   rz   Úsortedrw   Úchart_titlerx   ry   ri   rh   rN   r=   )r„   Úpage_first_headingÚby_pagerg   r}   ÚrecordsÚpage1r|   r    ÚcontentÚsections              r(   Ú_unanchored_value_recordsr�     s  € ð* 9;€GÛ‰ˆØ�}�}‰}Ø×Ñ˜qŸv™v rÓ*×1Ñ1°3°(Ö;ñ  ð OQ€GÜ˜–ˆØˆØ”n‰FˆCð —<‘<Ñ\°!·-±-ÀÇÁÈ!Ï(É(Ñ1SÓ\Ó\ˆDØ�L‰Lœ S°·±Ó8Ö9ñ	 %ð
 —)‘)˜EÓ"ˆØ$×(Ñ(¨°Ó3ˆÞ�w—}‘}“¨g¯m©m«oÓ=Ø ˜	  w iÐ0ˆGØ�‰˜/¨%¨Ð1°?ÀEÈAÁIÈtÐU\Ð^bÐcÖdñ !ð €Nr*   c                óJ  • U(       d  gU R                  S/ 5       H…  nUR                  S5      U:X  d  M  UR                  S5      =(       d    0 /S   nUR                  S5      (       d    gUR                  SS5      nUR                  US	5      u  pg[        US   Xg5      s  $    g)
zKThe parse picture's own normalized box, for a value with no box of its own.NÚpicturesÚself_refÚprovr   ÚbboxÚpage_nor…   ©ç      ð?r˜   )rN   Ú
_norm_bbox)ÚdocÚsizesr†   rO   r”   r�   ÚwÚhs           r(   Ú_picture_bboxrž   F  s“   € ö ØØ�w‰w�z 2Ö&ˆØ�7‰7�:Ó +Õ-Ø—G‘G˜F“O×+¨ t¨QÑ/ˆDØ—8‘8˜F×#Ñ#ÙØ—H‘H˜Y¨Ó*ˆEØ—9‘9˜U JÓ/‰DˆAÜ˜d 6™l¨AÓ1Ò1ñ 'ð r*   c                ó  ^^^^• S Vs0 s H  oU R                  U/ 5      _M     snm/ m[        5       mSUUUU4S jjmU R                  S0 5      R                  S5      =(       d    /  H  nT" UR                  SS5      5        M     T(       d  / $ S Hh  n[        [        TU   5      5       HJ  nSU S	U 3nUT;  d  M  [        R
                  " S
US9  TR                  U5        TR                  U5        ML     Mj     T$ s  snf )aw  Every item ref in the document, in reading order.

Descends the whole tree. An item's own children are visited straight after
it, so a table's footnotes and a picture's labels keep their place in the
flow instead of being unreachable.

Any text, table or picture the document holds but never links into the
tree is appended at the end, so an item is dropped only by a rule that
names it, never by an accident of where it sits. Returns an empty list when
the artifact carries no body tree. The caller then walks the texts array
alone, in its own order, so no picture or group is ingested and no table
gets a reading-order position.
)ÚtextsrW   r’   Úgroupsc                óŒ  >• U (       a  U T	;   a  g T	R                  U 5        U R                  S5      R                  S5      u  pnTR                  U/ 5      n U[	        U5         nTR                  U 5        UR                  S5      =(       d    /  H  nT
" UR                  SS5      5        M     g ! [
        [        4 a     g f = f)Nú#/Ú/Úchildrenú$refrL   )ÚaddÚlstripÚ	partitionrN   rD   Ú
ValueErrorÚ
IndexErrorrz   )r\   ÚkindÚ_ÚidxÚitemsÚitemÚchildÚoutÚpoolsÚseenÚvisits          €€€€r(   rµ   Ú"_reading_order_refs.<locals>.visiti  s­   ø€ Þ�c˜T“kØØ�‰�ŒØ—z‘z $Ó'×1Ñ1°#Ó6‰ˆ�Ø—	‘	˜$ Ó#ˆð	Øœ˜S›‘?ˆDð 	�
‰
�3ŒØ—X‘X˜jÓ)×/¨RÒ/ˆEÙ�%—)‘)˜F BÓ'Ö(ò 0øô œJÐ'ó 	Ùð	ús   ÁB0 Â0CÃCÚbodyr¥   r¦   rL   )r    rW   r’   r£   r¤   zG{ref} is in the document but linked into no parent; ingesting it anyway©r\   )r\   r7   ÚreturnÚNone)rN   rY   ÚrangeÚlenr   Úwarningrz   r§   )	rš   r¬   r±   Úir\   r²   r³   r´   rµ   s	        @@@@r(   Ú_reading_order_refsr¿   W  s÷   û€ ñ 2[Ó[Ò1Z¨�3—7‘7˜4 Ó$Ò$Ñ1ZÑ[€EØ€CÜ“U€D÷)ò )ð& —‘˜ Ó$×(Ñ(¨Ó4×:¸Ò:ˆÙˆe�i‰i˜ Ó#Ö$ñ ;æØˆ	Û/ˆÜ”s˜5 ™;Ó'Ö(ˆAØ�t�f˜A˜a˜S�/ˆCØ˜$�Ü—’Ø]Ðcfòð —
‘
˜3”Ø—‘˜–ó )ñ 0ð €JùòI \s   ‰Dc                ó8  • 0 nU R                  S5      =(       d    0 R                  5        Hk  u  p#UR                  S0 5      n[        UR                  SS5      5      =(       d    S[        UR                  SS5      5      =(       d    S4U[        U5      '   Mm     U$ )z>page_no -> (width, height) from the DoclingDocument pages map.ÚpagesÚsizeÚwidthr   r˜   Úheight)rN   r¯   ÚfloatrD   )rš   r²   Úkr}   rÂ   s        r(   Ú_page_sizesrÇ   Œ  s   € à*,€CØ—‘˜Ó!×' R×.Ñ.Ö0‰ˆØ�u‰u�V˜RÓ ˆÜ˜TŸX™X g¨qÓ1Ó2×9°c¼5ÀÇÁÈ(ÐTUÓAVÓ;W×;^Ð[^Ð_ˆŒC�‹F‹ñ 1ð €Jr*   c           
     ó„  • U R                  S5      U R                  S5      pCU R                  S5      U R                  S5      peUb	  Ub  Ub  Uc  gU R                  SS5      nUS:X  a  X%-
  U-  X&-
  U-  p˜OXR-  Xb-  p˜[        SX1-  5      [        S[        X‰5      5      [        S	XA-  5      [        S	[        X‰5      5      S
.$ )zÆNormalize a docling prov bbox to top-left origin, 0..1.

docling boxes are PDF points with coord_origin BOTTOMLEFT, so t/b are
measured up from the page bottom (t > b). Flip Y to a top-left origin.
ÚlÚrÚtÚbNÚcoord_originÚ
BOTTOMLEFTg        r˜   ©ÚleftÚtopÚrightÚbottom)rN   ÚmaxÚmin)
Ú	prov_bboxÚpage_wÚpage_hrÐ   rÒ   Útop_ptÚ	bottom_ptÚoriginrÑ   rÓ   s
             r(   r™   r™   •  sÅ   € ð —-‘- Ó$ i§m¡m°CÓ&8ˆ%Ø!Ÿ™ cÓ*¨I¯M©M¸#Ó,>ˆIØ�|�u‘}¨©¸)Ñ:KØØ�]‰]˜>¨<Ó8€FØ�ÓØ‘¨&Ñ0°6Ñ3EÈÑ2O‰Và‘o yÑ'9ˆVä�C˜™Ó'Ü�3œ˜CÓ(Ó)Ü�S˜%™.Ó)Ü�cœ3˜sÓ+Ó,ñ	ð r*   c                óf   • U R                  SS5      R                  SS5      R                  SS5      $ )NÚ&z&amp;Ú<z&lt;Ú>z&gt;©Úreplace©Úss    r(   Ú_escrä   ¬  s-   € Ø�9‰9�S˜'Ó"×*Ñ*¨3°Ó7×?Ñ?ÀÀVÓLÐLr*   c                ó0   • U b  U R                  SS5      $ S$ )z�Strip NUL characters: Postgres text fields reject 0x00. They reach us
from PDF text layers that encode glyphs like cover-page checkboxes as NUL.NÚ rL   rà   râ   s    r(   Ú_pg_textrç   °  s   € ð %&¡Mˆ1�9‰9�V˜RÓ Ð;°tÐ;r*   c                óÞ   • U R                  [        5      S   n [        R                  " SSU 5      n[        R                  " SSU5      n[        R                  " SSU5      R	                  5       $ )zŒThe text a reader reads: tags dropped, cells separated by ' | '. The
footnote block is cut before embedding. It stays in the stored content.r   z</td><td[^>]*>ú | z<[^>]+>rl   z[ \t]+)ÚsplitÚFOOTNOTE_HEADERÚreÚsubrv   )rŽ   rE   s     r(   Ú_embed_viewrî   ¶  sX   € ð �m‰mœOÓ,¨QÑ/€GÜ�6Š6Ð# U¨GÓ4€DÜ�6Š6�*˜c 4Ó(€DÜ�6Š6�)˜S $Ó'×-Ñ-Ó/Ð/r*   c                ó¢  • U(       aé  / nUR                  S5      =(       d    /  HÀ  n[        U[        5      (       a  UR                  SS5      O
[        U5      nUR	                  S5      (       d  MM  [        UR                  SS5      S   5      nU[        U5      :  a*  X&   R                  S5      =(       d    SR                  5       OSnU(       d  M¯  UR                  U5        MÂ     U(       a  U$ U R                  S5      U R                  S	5      U R                  S
5      U R                  S5      4 Vs/ s H  oˆ(       d  M  UPM     sn$ s  snf )a9  The header lines of a table chunk: the caption nodes fusion attached to
the table's docling item, in order (the sentence that introduces the table,
its printed name, its units), read from the unified document so the chunk
says what the fused document says. A table with no fused item falls back to
its own fields.Úcaptionsr¦   rL   ú#/texts/r¤   r…   rE   ÚcaptionÚtitleÚsubtitleÚunits)
rN   Ú
isinstanceÚdictr7   r   rD   Úrsplitr¼   rv   rz   )	rË   r°   r    r|   r\   Úcrefr®   rE   rp   s	            r(   Ú_table_headrú   ¿  s  € ö ØˆØ—8‘8˜JÓ'×-¨2Ò-ˆCÜ*4°S¼$×*?Ñ*?�3—7‘7˜6 2Ô&ÄSÈÃXˆDØ—?‘? :×.Ñ.ÙÜ�d—k‘k # qÓ)¨!Ñ,Ó-ˆCØ=@Ä3ÀuÃ:Ó=M�E‘J—N‘N 6Ó*×0¨b×7Ñ7Ô9ÐSUˆDßˆtØ—‘˜TÖ"ñ .ö ØˆLØŸ™˜iÓ(¨!¯%©%°«.¸!¿%¹%À
Ó:KÈQÏUÉUÐSZË^Ñ\ÓbÒ\�!Ó`a�AÑ\ÑbÐbùÒbs   Ä5
EÅEc                óî   ^ ^• / n[        U5       HL  u  pEU(       a  X$   OUmSR                  UU 4S j[        U5       5       5      nUR                  SU S35        MN     SSR                  U5      -   S-   $ )a�  Render a corrected_grid as an HTML table with an id on every cell.

Ids follow `t<table_index>-<row>-<col>` so they are unique per document,
short enough for the agent to cite verbatim, and resolve directly back to
the grid position they came from. `row_offsets` supplies the true row
number of each rendered row when `grid` is a subset (a line-item record
rendering header + one line keeps the line's real ids).
rL   c              3  óˆ   >#   • U  H7  u  pS T ST SU S[        UR                  S5      =(       d    S5       S3	v •  M9     g7f)z	<td id="tÚ-z">rE   rL   z</td>N)rä   rN   )ro   ÚcÚcellrÊ   Útable_indexs      €€r(   rq   Ú_grid_html.<locals>.<genexpr>à  sI   øé € ð 
â)‘�ð ˜�} A a S¨¨!¨¨B¬t°D·H±H¸VÓ4D×4JÈÓ/KÐ.LÈEÕRÚ)ùs   ƒ?Az<tr>z</tr>z<table>
rt   z	
</table>)Ú	enumeraterw   rz   )r   ÚgridÚrow_offsetsÚrowsrÆ   ÚrowÚtdsrÊ   s   `      @r(   Ú
_grid_htmlr  Ô  su   ù€ ð €DÜ˜D–/‰ˆÞ)ˆKŠN¨qˆØ�g‰gõ 
ä$ Sœ>ó
ó 
ˆð 	�‰�d˜3˜%˜uÐ%Ö&ñ "ð ˜Ÿ™ 4›Ñ(¨<Ñ7Ð7r*   c                óä  • U  Vs/ s H5  n[        U5      U:”  d  M  XB   R                  S5      (       d  M.  XB   S   PM7     nnX    Vs/ s H  ofR                  S5      (       d  M  US   PM!     nnU  VVs/ s H(  oD  H  ofR                  S5      (       d  M  US   PM!     M*     nnnU(       d  U(       d  gU(       a$  [        S U 5       5      [        S U 5       5      p©OU(       a
  US   US   p©OgU(       a$  [        S U 5       5      [        S U 5       5      pËO?U(       a7  U(       a0  [        S	 U 5       5      US
   :”  a  US
   [        S U 5       5      pËOgX›X¬4$ s  snf s  snf s  snnf )u²  Approximate box for an unboxed cell, read off its boxed neighbors.

The column's x-extent (union of boxes in column c) crossed with the row's
y-extent (union of boxes in row r) marks the empty spot where the cell
sits. A fully unboxed row falls back to the band between the table's top
edge and the first boxed row â€” the header area. Returns None when either
axis cannot be derived; the caller falls back to the whole table region.
ÚboxNc              3  ó*   #   • U  H	  oS    v •  M     g7f©r   Nrf   ©ro   rÌ   s     r(   rq   Ú!_cell_vicinity.<locals>.<genexpr>ù  s   é € Ð'¢3˜a�q–T¢3ùó   ‚c              3  ó*   #   • U  H	  oS    v •  M     g7f©é   Nrf   r  s     r(   rq   r  ù  s   é € Ð,?º3°a¨q®Tº3ùr  r   r  c              3  ó*   #   • U  H	  oS    v •  M     g7f©r…   Nrf   r  s     r(   rq   r  ÿ  s   é € Ð(¢4˜a�q–T¢4ùr  c              3  ó*   #   • U  H	  oS    v •  M     g7f©é   Nrf   r  s     r(   rq   r  ÿ  s   é € Ð-AºD°q°®dºDùr  c              3  ó*   #   • U  H	  oS    v •  M     g7fr  rf   r  s     r(   rq   r     s   é € Ð 4ªt¨! 1¦ªtùr  r…   c              3  ó*   #   • U  H	  oS    v •  M     g7fr  rf   r  s     r(   rq   r    s   é € Ð3ªd¨ !¦ªdùr  )r¼   rN   rÕ   rÔ   )r  rÊ   rþ   Úregionr  Úcolrÿ   ÚrowbÚallbÚx1Úx2Úy1Úy2s                r(   Ú_cell_vicinityr"  è  s/  € ñ %)Ó
O¢D˜S¬C°«H°q©L‹=¸S¹V¿Z¹ZÈ×=N‹=ˆ3‰6�%Œ=¡D€CÐ
OØ$(¢GÓ?¢G˜D¯x©x¸¯‹KˆD�ŒK¡G€DÐ?Ù#'ÔK¢4˜C³C¨D¿8¹8ÀE¿?‹KˆD�ŒK±C‰K¡4€DÑKÞ–4ØÞ
ÜÑ'¡3Ó'Ó'¬Ñ,?¹3Ó,?Ó)?‰BÞ	Ø˜‘˜F 1™I‰BàÞÜÑ(¡4Ó(Ó(¬#Ñ-A¹DÓ-AÓ*A‰BÞ	–DœSÑ 4©tÓ 4Ó4°v¸a±yÓ@Ø˜‘œCÑ3©dÓ3Ó3‰BàØ�BÐÐùò# PùÚ?ùÛKs'   …E"œE"¶E"Á	E'Á&	E'Á6E,ÂE,c                ó  • U(       d  gU  VVs/ s H(  o"  H  o3R                  S5      (       d  M  US   PM!     M*     nnnU(       a  [        S U 5       5      US   ::  a  gUS   US   US   [        S U 5       5      4$ s  snnf )a5  The table's header area: from the region's top edge down to the top of
the first boxed row. Dropped printed text lives there by definition, so it
is the honest vicinity for a dropped-text flag. None without a region, when
no cell is boxed, or when the first boxed row starts at or above the
region's top edge.Nr
  c              3  ó*   #   • U  H	  oS    v •  M     g7fr  rf   r  s     r(   rq   Ú_header_band.<locals>.<genexpr>  s   é € Ð*¢T ˜–t¢Tùr  r…   r   r  c              3  ó*   #   • U  H	  oS    v •  M     g7fr  rf   r  s     r(   rq   r%    s   é € Ð0Dºt¸!°1¶ºtùr  )rN   rÕ   )r  r  r  rÿ   r  s        r(   Ú_header_bandr'    s|   € ö ØÙ#'ÔK¢4˜C³C¨D¿8¹8ÀE¿?‹KˆD�ŒK±C‰K¡4€DÑKÞ”3Ñ*¡TÓ*Ó*¨f°Q©iÓ7ØØ�1‰I�v˜a‘y &¨¡)¬SÑ0D¹tÓ0DÓ-DÐEÐEùó Ls
   ŽB °B c                ó†  ^• 0 mU R                  S5      =(       d    0 R                  S/ 5       Hm  nUR                  S5      =(       d    SR                  5       nU(       d  M4  UR                  SS5      nUR                  SS5      nUTR                  U0 5      U'   Mo     SR                  U4S	 j[	        T5       5       5      $ )
z=Reconstruct a docling table's content as pipe-separated rows.ÚdataÚtable_cellsrE   rL   Ústart_row_offset_idxr   Ústart_col_offset_idxrt   c              3  óv   >^#   • U  H-  mS R                  UU4S j[        TT   5       5       5      v •  M/     g7f)ré   c              3  ó4   >#   • U  H  nTT   U   v •  M     g 7frn   rf   )ro   rþ   rÊ   r  s     €€r(   rq   Ú0_docling_table_text.<locals>.<genexpr>.<genexpr>!  s   øé € ÐD²O¨q  Q¡¨¦
²Oùs   ƒN)rw   rˆ   )ro   rÊ   r  s    @€r(   rq   Ú&_docling_table_text.<locals>.<genexpr>!  s+   ùé € Ð[ÊlÈ�U—Z‘ZÕD´F¸4À¹7´OÓD×DÐDÊlùs   „59)rN   rv   r‡   rw   rˆ   )rË   rÿ   rE   rÊ   rþ   r  s        @r(   Ú_docling_table_textr1    s¡   ø€ à&(€DØ—‘�v“×$ "×)Ñ)¨-¸Ö<ˆØ—‘˜Ó ×& B×-Ñ-Ó/ˆÞÙØ�H‰HÐ+¨QÓ/ˆØ�H‰HÐ+¨QÓ/ˆØ$(ˆ�‰˜˜2Ó˜qÓ!ñ =ð �9‰9Ô[ÌfÐUYÌlÓ[Ó[Ð[r*   c                ó  • UR                  5       (       d  U $  SSKnSSKnSSKJn  SSKJn  U" 5       nU" [        U5      SSX"S-   S9n/ n	U HB  n
UR                  5       nU
R                  US	S
9  U	R                  UR                  5       5        MD     UR                  UR                  U R                  X’5      5      nUc  U $ [%        XR&                  5      $ ! [         a!  n[         R"                  " SX-S9  U s SnA$ SnAff = f)u  The demand-driven last tier: ask the lookup agent to find the still-
unresolved markers on the rendered pages following the table. Any failure
(no PDF, no credentials, a failed call) leaves the markers unresolved in
the exception record â€” the lookup never takes an ingest down.r   N)Úconvert_from_path)ÚPydanticAIFootnoteLookupé–   Úpngr  )ÚdpiÚfmtÚ
first_pageÚ	last_pageÚPNG)ÚformatzCpage {p}: footnote lookup unavailable; markers stay unresolved: {e})rp   Úe)r   ÚasyncioÚioÚ	pdf2imager3  Úquber.agents.footnote_lookupr4  r7   ÚBytesIOÚsaverz   Úgetvaluer6   ÚlookupÚ
unresolvedÚ	Exceptionr   r½   r   Úfound)Ú
resolutionÚpdf_pathr�   r>  r?  r3  r4  ÚagentÚimagesÚpngsÚimageÚbufÚreportÚexcs                 r(   Ú_lookup_unresolvedrR  $  sì   € ð
 �?‰?×ÑØÐðÛÛå/åIá(Ó*ˆÙ"¤3 x£=°c¸uÐQVÐjkÑbkÑlˆØˆÛˆEØ—*‘*“,ˆCØ�J‰J�s 5ˆJÑ)Ø�K‰K˜Ÿ™›Ö'ñ ð —‘˜UŸ\™\¨*×*?Ñ*?ÀÓMÓNˆð �~ØÐÜ˜§\¡\Ó2Ð2øô ó Ü�ŠÐ\Ð`eÒmØÕûðús   ™B%C Ã
DÃ"C>Ã8DÃ>Dc
                ó=  ^•• U	S:H  n
[        U[        U  S3-  5      n[        R                  " [        U[        U  S3-  5      R	                  5       5      n[        R                  " [        U[        U  S3-  5      R	                  5       5      nU(       a8  [        R                  " [        U[        U  S3-  5      R	                  5       5      OSn[        U[        U  S3-  5      nUR                  U=(       d    / 5        [        [        U[        U  S3-  5      5      n[        U5      n[        U[        U  S	3-  5      nU(       aD  [        [        R                  " U5      R                  5       VVs/ s H  u  nnS
U 3U4PM     snnO/ n0 nU HF  u  nnUR                  (       d  M  UR                  UR                  / 5      R                  UU45        MH     / n/ n0 n0 nU(       am  UR!                  S/ 5       HW  nUR!                  S/ 5      nUR!                  S/ 5       H,  nU(       d  M  US   UU'   UR                  US   SU 35        M.     MY     UR!                  S/ 5      nUR!                  S/ 5      n UR!                  S/ 5      n![#        U5      n"U"=(       d(    [%        ['        U5      5       V#s/ s H  n#SU# 3PM
     sn#n$Sn%0 n&/ n'0 n(/ n)/ n*0 n+Sn,/ n-/ n.[)        5       n/U$ GH!  n0U0R+                  S5      (       Gao  U
(       d  M$  [-        U0R/                  SS5      S   5      n1U1['        U!5      :  a  U!U1   O0 n2U2R!                  S5      [0        :w  a  U2R!                  S5      S:w  a  Mˆ  / n3U2R!                  S/ 5       GH  n4U4R!                  S5      =(       d    Sn5U5R+                  S5      (       d  M6  U[-        U5R/                  SS5      S   5         n6U6R!                  S5      =(       d    SR3                  5       n7U7(       d  Mˆ  U6R!                  S5      S:X  aU  U7n%U6R!                  S5      =(       d    0 /S   R!                  S S5      n8U*R                  U7U845        U+R                  U8U75        U3R                  U5U6U745        GM	     U3(       d  GM±  U/R5                  S! U3 5       5        U3S   S   R!                  S5      =(       d    0 /S   n9U9R!                  S S5      n:UR!                  U:S"5      u  n;n<U3 V=V6V>V?V@s/ s HX  u  n=n6n>U6R!                  S5      =(       d    0 /S   n?U?R!                  S#5      (       d  M=  [7        U?S#   U;U<5      n@U@(       d  MV  W@PMZ     nAn?n>n6n=n@UA(       aG  [9        S$ WA 5       5      [9        S% UA 5       5      [;        S& UA 5       5      [;        S' UA 5       5      S(.OSnBU3 H  u  n=nCn7U'R                  U7U:45        M     S)R=                  S* U3 5       5      nD[?        U+R!                  U:S5      U%5      m•T•(       a)  T•RA                  5       WDRA                  5       ;  a  T• S+WD 3nDUR                  U2R!                  S,5      =(       d    U0SU:S-
  WBWDS45        GMŠ  U0U/;   a  GM“  U0R+                  S5      (       aC  U%U&U0'   ['        U'5      U(U0'   U)R                  U05        U-R                  ['        U'5      5        U0n,GMì  U0R+                  S-5      (       Gaá  U [-        U0R/                  SS5      S   5         nE[C        UEUR!                  UER!                  S,5      =(       d    S5      =(       d    UR!                  U0/ 5      5      nDUD(       d  GMz  WER!                  S5      =(       d    0 /S   n9U9R!                  S S5      n:UR!                  U:S"5      u  n;n<U9R!                  S#5      (       a  [7        U9R!                  S#0 5      U;U<5      OSnBU
(       a  [?        U+R!                  U:S5      U%5      OU%m•T•(       a)  T•RA                  5       WDRA                  5       ;  a  T• S+WD 3nD[E        WE5      nF[G        UE5      nGUF(       d  WG(       aB  U-R                  ['        U'5      5        U.R                  ['        U5      WFWGU:['        U'5      45        UR                  WER!                  S,5      =(       d    U0S.U:S-
  WBWDS45        GMä  U0R+                  S5      (       d  GMý  [-        U0R/                  SS5      S   5      nHUH['        U5      :¼  a  GM-  UWH   n6U6R!                  S5      =(       d    SR3                  5       n7U6R!                  S5      nIU6R!                  S5      =(       d    0 /S   n9U9R!                  S S5      n:WIS:X  a3  U7n%U7(       a%  U*R                  U7U:45        U+R                  U:U75        Sn,GMÔ  U7(       a  WIS/:X  a  GMä  [I        U7U:U6R!                  S05      =(       d    S5      (       a  GM  U'R                  U7U:45        WIS1:X  a  UR!                  U,=(       d    S5      OSnJWIS1:w  a  Sn,UR!                  U:S"5      u  n;n<U9R!                  S#5      (       a  [7        U9R!                  S#0 5      U;U<5      OSnBU
(       a  [?        U+R!                  U:S5      U%5      OU%m•T•(       a)  T•RA                  5       U7RA                  5       ;  a  T• S+U7 3OU7nDUR                  U6R!                  S,5      =(       d    U0SU:S-
  WBWDWJ45        GM$     0 nK0 nLU. HZ  u  nMnFnGn:nNWKR                  U:/ 5      R                  UG5        WLR                  U:[)        5       5      R5                  S2 UF 5       5        M\     [)        5       nOU. GHþ  u  nPnFnGn:nQUF Vs/ s H-  nUR!                  S35      (       d  M  UR!                  S3S5      PM/     nRnUR(       d	  WG(       d  MT  U- V?s/ s H  n?U?WQ:”  d  M  U?PM     nSn?US(       a  WSS   O
['        U'5      nTU'WQUT nUWF Vs1 s H5  nUR!                  S45      S5:X  d  M  [K        UR!                  S3S5      5      iM7     nVnWG VWs1 s H  nW[K        UWRL                  5      iM     nXnW[O        WG5      WKR!                  U:/ 5       VWs/ s H   nW[K        UWRL                  5      WX;  d  M  WWPM"     snW-   nY[Q        WRUYU:WUU*WV5      nZ[S        UZRT                   V[s/ s H?  n[U[RV                  S6:w  d  [K        W[RL                  5      WX;   a  W[OW[RY                  S7S80S99PMA     sn[[O        WZRZ                  5      [O        UZR\                  5      S:9nZUZRZ                  (       a  [_        WZ[        U  S3-  U:5      nZUWP   u  n0n\n]nBn^nJWZRT                   V[s/ s H  n[U[RL                   S+U[R`                   3PM      n_n[U_(       aF  U0W\W]WBW^[b        -   S)R=                  W_5      -   WJ4UWP'   [d        Rf                  " S;['        U_5      U0U:5        / n`WZR\                   H‹  nW[K        UWRL                  5      naUaWLR!                  U:[)        5       5      ;   d  U:Wa4WO;   a  M@  WORi                  U:Wa45        W`R                  WWRL                   S<UWR`                   3R3                  5       5        M�     WZRZ                   Vs/ s H  nS=U4PM	     snW` Vbs/ s H  nbS>Ub4PM	     snb-   WF Vs/ s HF  nUR!                  S5      =(       d    SR3                  5       (       a  M2  S?UR!                  S3S5      4PMH     sn-   nc[        Uc5       HA  u  ndu  nenb[d        Rj                  " S@U0U:UeUbSA9  UR                  U0 SBUd 3SCW]WBSDU00UeSUb45        MC     GM     UR                  [m        UU+5      5        U HØ  u  nnURn                  =(       d    [q        UUUR                  5      nfURr                  URt                  URv                  UR                  SE.ngUR                  (       d  SFURx                   3WgSD'   UR                  USGURx                  S-
  Wf(       a  [{        Wf5      OSWgUR|                  UR~                  UR€                  45        MÚ     UR!                  SH/ 5       Vhs0 s H  nhUhR!                  S,5      Uh_M     ninh[        U5       GH»  u  n#n6U6R!                  SIS5      n:U6R!                  SJ5      =(       d    U6R!                  SK5      njSnBUj(       a  Wju  nknlnmnnUkUlUmUnS(.nBU6R!                  SL5      =(       d    / noUo(       a  [ƒ        U#Wo5      OU6R!                  SM5      n^[…        U6WiR!                  UR!                  U#S5      5      U5      npU&R!                  UR!                  U#S5      S5      m•U
(       a,  [?        U+R!                  U6R!                  SIS5      S5      T•5      m•T•(       a,  [‡        U•4SN jWp 5       5      (       a  WpR‰                  ST•5        U6R!                  SO5      =(       d    / nFU6R!                  SP5      =(       d    /  Vqs/ s H8  nq[‹        Uq[Œ        5      (       a
  [�        SWqSQ9O[Ž        R                  " Wq5      PM:     nrnqWF Vs/ s H  nUR!                  S3S5      PM     sn[O        U6R!                  SR5      =(       d    / 5      -   nRUR!                  U#S5      nsU(R!                  Us5      nQUQb?  U)R‘                  Ws5      ntUtS-   ['        U)5      :  a  U(U)WtS-         O
['        U'5      nTU'WQUT nUOU' Vus/ s H  nuUuS   U::¼  d  M  WuPM     nUnuWF Vs1 s H5  nUR!                  S45      S5:X  d  M  [K        UR!                  S3S5      5      iM7     nVn[Q        WRWrU:WUU*UV5      nZUZRZ                  (       a  [_        WZ[        U  S3-  U:5      nZWZRT                   V[s/ s H  n[U[RL                   S+U[R`                   3PM      sn[Wr VWs/ s HC  nWUWRL                  (       a  M  WWR`                  R3                  5       (       d  M7  WWR`                  PME     snW-   nvW^(       a  S)R=                  WpW^/-   5      OS)R=                  Wp5      nDWv(       a  WD[b        S)R=                  Wv5      -   -  nDUR                  SU# 3S6U:S-
  WBWDS45        U6R!                  SS5      nwWo(       a-  [‹        Ww[,        5      (       d  [d        Rj                  " STU#U:SU9  GO<Wo(       Ga4  Snx[%        Ww['        Wo5      5       GH  n[WoU[   ny[“        SV Uy 5       5      (       d  M"  [“        SW WySS  5       5      (       d  W[nxM@  [O        [%        Ww5      5      Wxb  Wx/O/ -   W[/-   nz[ƒ        U#Uz Vds/ s H  ndWoUd   PM
     sndWzSX9n{S)R=                  WpU{/-   5      n|[)        Uz5      n}/ n~[)        5       nWF H¤  nUR!                  SY5      W};  a  M  [K        UR!                  S3S5      5      naUa(       a  WaW;   a  MD  WRi                  Wa5        WZR•                  UR!                  S3S5      5      n€U€(       d  M  W~R                  UR!                  S35       S+W€ 35        M¦     W~(       a  W|[b        S)R=                  W~5      -   -  n|Wy V�s/ s H   n�U�R!                  SZ5      (       d  M  W�SZ   PM"     nAn�UA(       aG  [9        S[ WA 5       5      [9        S\ UA 5       5      [;        S] UA 5       5      [;        S^ UA 5       5      S(.OWBn‚UR                  S_U# S`W[ 3SaU:S-
  U‚W|SU# 345        GM     [        Wo5       H¿  u  n[ny[        Uy5       Hª  u  nƒn�U�R!                  SZ5      =(       d    [—        WoW[WƒWj5      nfUf(       a  WfS   UfS   UfSb   UfSc   S(.OWBn„UR                  S_U# SdW[ SdWƒ 3SeU:S-
  U„U[UƒSU# 3Sf.W�R!                  Sg5      U�R!                  Sh5      U�R!                  S5      =(       d    S45        M¬     MÁ     [™        WoWj5      n…U…(       a  W…S   U…S   U…Sb   U…Sc   S(.OWBn†[        U6R!                  Si5      =(       d    / 5       H-  u  ndn‡UR                  S_U# SjUd 3SCU:S-
  W†SDSU# 30SkSU‡45        M/     WZRZ                   Vs/ s H  nS=U4PM	     snWZR\                   VWs/ s H.  nWS>UWRL                   S<UWR`                   3R3                  5       4PM0     snW-   WF Vs/ s H+  nUR!                  SY5      b  M  S?UR!                  S3S5      4PM-     sn-   nˆ[        Uˆ5       HH  u  ndu  nenb[d        Rj                  " SlU#U:UeUbSm9  UR                  S_U# SBUd 3SCU:S-
  WBSDSU# 30UeSUb45        MJ     GM¾     U(       Ga  UR!                  S/ 5       VV‰s1 s H6  nUR!                  S45      Sn:X  d  M  UR!                  S/ 5        H  n‰U‰iM     M8     nŠnn‰UR!                  SH/ 5       V6s0 s H  n6U6R!                  S,5      U6_M     n‹n6[›        WŠU-
  5       GHj  n‰W‹R!                  U‰5      n6U6c  [d        Rj                  " SoW‰Sp9  M/  [�        U65      nDUD(       d  [d        Rj                  " SqW‰Sp9  MX  U6R!                  S5      =(       d    0 /S   n9U9R!                  S S5      n:U&R!                  W‰S5      m•U
(       a  [?        U+R!                  U:S5      T•5      m•T•(       a)  T•RA                  5       WDRA                  5       ;  a  T• S)WD 3nDUR!                  U:S"5      u  n;n<U9R!                  S#5      (       a  [7        U9R!                  S#0 5      U;U<5      OSnBUR                  SrW‰ 3S6U:S-
  UBWDS45        [d        Rf                  " SsU‰U:St9  GMm     U(       a)  [Ÿ        U U V[s/ s H  n[[¡        U[Su   5      PM     sn[5      O/ nŒUR!                  Sv0 5      n�U=(       d    W�R!                  Sw5      =(       d    U  S3n['        U5      =(       d    SnŽ[¢        R¤                  " UR§                  5       5      R©                  5       n�[ª        R¬                  " 5        n�U�R¯                  SxU 45        U�R¯                  SyU U�UUŽSz45      R±                  5       nyUyc   eWyS   n‘[³        UWŒS{S|9 Ho  u  u  n0n\n]nBnDnJn’W�R¯                  S}W‘U0U\U][        R´                  " UB5      [·        UD5      U’UJ45        U�R¯                  S~U‘U0U\U][        R´                  " UB5      45        Mq     U Ha  u  n0n\n]nBngnen“n”W�R¯                  SW‘U0U\U][        R´                  " UB5      [        R´                  " Ug5      Ue[·        U“5      [·        U”5      4	5        Mc     SSS5        [d        R¸                  " S€U ['        U5      [»        S� U 5       5      [»        S‚ U 5       5      [»        Sƒ U 5       5      ['        U5      S„9  ['        U5      $ s  snnf s  sn#f s  sn@n?n>n6n=f s  snf s  sn?f s  snf s  snWf s  snWf s  sn[f s  sn[f s  snf s  snbf s  snf s  snhf s  snqf s  snf s  snuf s  snf s  sn[f s  snWf s  sndf s  sn�f s  snf s  snWf s  snf s  sn‰nf s  sn6f s  sn[f ! , (       d  f       GN= f)…uµ  `chunking` selects the ingestion stream. `flat` (the default) serves
every printed line on its own: a stat panel's label lands in one chunk
and its number in another, and each text and picture chunk is tagged
with only the most recent heading the walk passed â€” nothing is bundled.
A table chunk carries a heading only when the fusion report matches it
to a docling table the walk reached, so a scanned table carries none. Technically: every group is a transparent wrapper,
single-heading ride-along. `grouped`: a binding group â€” a
key_value_area or a scan block â€” is served as one chunk so a label
travels with its number, and every chunk rides with the page's opening
heading joined to the local one. A per-page figure_values record carries
the page's opening heading in both streams. The upload app picks the
stream per track (`TRACKS` in `quber.playground.app`): the dpt-2 track
ingests flat, the dpt-3 track, its default, ingests grouped.
Úgroupedz.pdfz.unified.jsonz.tables.jsonz.fusion.jsonNz.scanned-tables.jsonz.figures.jsonz.figure-values.jsonzfv-ÚmatchesÚdocling_table_refsÚsom_indicesr   z	#/tables/r    r’   r¡   rñ   rL   z	#/groups/r¤   r…   r    rx   Úkey_value_arear¥   r¦   rE   Úsection_headerr”   r–   c              3  ó*   #   • U  H	  u  po1v •  M     g 7frn   rf   )ro   ÚmrefÚ_tÚ_texts       r(   rq   Úingest.<locals>.<genexpr>ã  s   é € Ð"Gºw©O¨D°e¤4ºwùr  r—   r•   c              3  ó*   #   • U  H	  oS    v •  M     g7f)rÐ   Nrf   r  s     r(   rq   r^  ñ  s   é € Ð9²5¨a &¦	²5ùr  c              3  ó*   #   • U  H	  oS    v •  M     g7f)rÑ   Nrf   r  s     r(   rq   r^  ò  s   é € Ð7²¨A žx²ùr  c              3  ó*   #   • U  H	  oS    v •  M     g7f)rÒ   Nrf   r  s     r(   rq   r^  ó  s   é € Ð ;²U° 7¦²Uùr  c              3  ó*   #   • U  H	  oS    v •  M     g7f)rÓ   Nrf   r  s     r(   rq   r^  ô  s   é € Ð!=²u°! H¦+²uùr  rÏ   rt   c              3  ó*   #   • U  H	  u  po3v •  M     g 7frn   rf   )ro   Ú_mrefr\  rE   s       r(   rq   r^  û  s   é € ÐDºG©¨°D¤ºGùr  r;   r“   z#/pictures/Úpicturerò   rG   Úfootnotec              3  ó†   #   • U  H7  oR                  S 5      (       d  M  [        UR                  S S5      5      v •  M9     g7f)rK   rL   N)rN   r   )ro   Úms     r(   rq   r^  P  s2   é € ð 5
Ú;@°aÇEÁEÈ(ÇOÓ1Ô˜QŸU™U 8¨RÓ0×1Ð1º5ùs
   ‚AŸ"ArK   r¬   r�   r[   ÚsourceÚsibling)Úupdate)ÚresolvedrF  Úunreferencedz/Attached {} footnote(s) to picture {} (page {})rl   Úfootnote_unresolvedÚfootnote_unreferencedÚfootnote_marker_unplacedz'picture {r} (page {p}): {status}: {q!r})rÊ   rp   ÚstatusÚqz-fn-Ú	tableFlagÚchunk_id)rx   ry   Úchartr†   rƒ   ÚfigureValuerW   rF   Úcontent_regionÚ
som_regionÚcorrected_gridÚmarkdownc              3  óf   >#   • U  H&  nTR                  5       UR                  5       ;  v •  M(     g 7frn   r<   )ro   rp   r�   s     €r(   rq   r^  Ý  s"   øé € ÐJÂTÀ˜7Ÿ=™=›?°!·'±'³)Ö;ÂTùs   ƒ.1Úfootnote_marksÚ	footnotesrM   Úfootnote_refsÚheader_rowsu“   table {i} (page {p}): gridded but carries no header depth â€” structure correction absent; serving the whole-table record only, no per-line records)r¾   rp   c              3  óp   #   • U  H,  oR                  S 5      =(       d    SR                  5       v •  M.     g7f©rE   rL   N©rN   rv   ©ro   rÿ   s     r(   rq   r^  (  s(   é € ÐLÊÀŸH™H VÓ,×2°×9Ñ9×;Ð;Êùó   ‚46c              3  óp   #   • U  H,  oR                  S 5      =(       d    SR                  5       v •  M.     g7fr�  r‚  rƒ  s     r(   rq   r^  .  s(   é € ÐPÊÀŸH™H VÓ,×2°×9Ñ9×;Ð;Êùr„  )r  r  r
  c              3  ó*   #   • U  H	  oS    v •  M     g7fr  rf   r  s     r(   rq   r^  K  s   é € Ð#8²%¨Q a¦D²%ùr  c              3  ó*   #   • U  H	  oS    v •  M     g7fr  rf   r  s     r(   rq   r^  L  s   é € Ð"7²¨A Q¦4²ùr  c              3  ó*   #   • U  H	  oS    v •  M     g7fr  rf   r  s     r(   rq   r^  M  s   é € Ð$9²5¨a q¦T²5ùr  c              3  ó*   #   • U  H	  oS    v •  M     g7fr  rf   r  s     r(   rq   r^  N  s   é € Ð%:²E¨q¨¦d²Eùr  rË   z-line-Ú	line_itemr  r  rý   Ú	tableCell)r  r  rt  rq  ÚnoteÚdropped_textz	-dropped-Úheader_text_droppedz%table {i} (page {p}): {status}: {q!r})r¾   rp   rq  rr  Úsom_missz?fusion report names {ref} but the unified doc has no such tabler¸   z0SoM-missed table {ref} has no cell text; skippedz	#/doclingz3Ingesting SoM-missed docling table {ref} (page {p}))r\   rp   é   rÛ   Úfilenamez7DELETE FROM ade_playground.documents WHERE doc_key = %sz¦INSERT INTO ade_playground.documents
               (doc_key, content_hash, filename, page_count, ade_version)
               VALUES (%s, %s, %s, %s, %s) RETURNING idzquber-fusionT)ÚstrictzÄINSERT INTO ade_playground.chunks
                   (document_id, chunk_id, chunk_type, page, bbox, content, embedding, parent_chunk_id)
                   VALUES (%s, %s, %s, %s, %s, %s, %s, %s)zãINSERT INTO ade_playground.groundings
                   (document_id, ref_id, ref_type, page, bbox, position)
                   VALUES (%s, %s, %s, %s, %s, NULL)
                   ON CONFLICT (document_id, ref_id) DO NOTHINGa  INSERT INTO ade_playground.groundings
                   (document_id, ref_id, ref_type, page, bbox, position, status, note, cell_text)
                   VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s)
                   ON CONFLICT (document_id, ref_id) DO NOTHINGzZIngested {key}: {n} chunks ({t} text, {tb} table, {ln} line item), {cells} cell groundingsc              3  ó:   #   • U  H  oS    S:X  d  M  S v •  M     g7f)r…   rE   Nrf   ©ro   rÊ   s     r(   rq   r^  õ  s   é € Ð3š�A a¡D¨F¡N�a‰ašùó   ‚’	c              3  ó:   #   • U  H  oS    S:X  d  M  S v •  M     g7f)r…   r[   Nrf   r”  s     r(   rq   r^  ö  s   é € Ð5š'�Q q¡T¨W¡_�q‰qš'ùr•  c              3  ó:   #   • U  H  oS    S:X  d  M  S v •  M     g7f)r…   rŠ  Nrf   r”  s     r(   rq   r^  ÷  s   é € Ð9š'�Q q¡T¨[Ñ%8�q‰qš'ùr•  )ÚkeyrP   rË   ÚtbÚlnÚcells)^r#   ÚDATA_DIRr!   r"   r$   r)   Úextendr]   rÇ   r  r   Úmodel_validater{   r†   r‡   rz   rN   r¿   r»   r¼   rY   r   rD   rø   r   rv   rk  r™   rÕ   rÔ   rw   r@   r=   r~   rT   rQ   rH   r   rK   rS   r   r   rl  ri  Ú
model_copyrF  rm  rR  rE   rë   r   r   r§   r½   r�   r
  rž   rx   ry   r‰   rF   r÷   rq  rŒ  rh   r  rú   ÚallÚinsertrö   r7   r   ÚindexÚanyÚtext_forr"  r'  rˆ   r1  r   rî   ÚhashlibÚsha256r9   Ú	hexdigestr   ÚconnectÚexecuteÚfetchoneÚzipÚdumpsrç   ÚsuccessÚsum)–Údoc_keyÚunified_jsonÚtables_jsonÚ
source_pdfÚfusion_jsonÚscanned_tables_jsonÚfigures_jsonÚfigure_values_jsonr‘  ÚchunkingrT  Ú	pdf_localrš   rW   rP  ÚscannedÚ
supersededr›   Ú	value_runrP   r}   r„   Úvalues_by_picturerg   rŒ   Ú	cell_rowsÚsom_docling_refÚdocling_to_somrh  ÚrefsÚsiÚ	all_textsÚall_picturesÚ
all_groupsÚorderr¾   Ú	walk_refsr?   Útable_headingsÚordered_textsÚtable_positionsÚtable_sequenceÚheadingsrŠ   Úlast_table_refÚowner_positionsÚpicture_notesÚgrouped_membersÚref_idÚgidxÚgroupÚmembersr±   r[  rË   rE   Úmpager”   r�   rœ   r�   rd  r]  rp   rÌ   Úboxesr•   r\  rŽ   rO   ÚmarksÚdefsr®   rx   r3   Ú	page_defsÚpage_markersÚ_iÚ_pÚorphans_seenr¢  ÚposÚmarkersÚlaterÚendÚtrailingÚsection_keysÚdÚown_keysÚpoolrI  rÊ   Úref_typeÚpage0r·   ÚnotesÚorphansr˜  ÚquotedÚflagsrÆ   rq  r
  Úpositionr™  Úunified_tablesr  r  r   r  r!  r  ÚheadÚfÚfdefsÚown_refÚseqÚxÚtable_notesÚdepthÚ	label_rowr  r  Ú	line_htmlÚline_contentÚrows_setÚ
line_notesÚ	seen_keysÚ	note_textrÿ   Ú	line_bboxrþ   Ú	cell_bboxÚbandÚ	band_bboxÚfragmentÚfootnote_flagsr\   Úmissed_refsÚby_refÚvectorsrJ   Ú
page_countÚcontent_hashÚconnÚdoc_idÚvecrŒ  Ú	cell_textr�   s–                                                                                                                                                        @r(   Úingestr  C  sÈ  ø€ ð4 ˜)Ñ#€GÜ�z¤8°°	¸Ð.>Ñ#>Ó?€IÜ
�*Š*”V˜L¬(¸°yÀÐ5NÑ*NÓO×YÑYÓ[Ó
\€CÜ�ZŠZœ˜{¬H¸'¸À,Ð7OÑ,OÓP×ZÑZÓ\Ó]€Fö ô 	�
Š
”6˜+¤x°W°I¸\Ð2JÑ'JÓK×UÑUÓWÔXàð ô Ð1´8ÀÀ	ÐI]Ð>^Ñ3^Ó_€GØ
‡M�M�'—-˜RÔ ô "¤/°,ÄÈgÈYÐVcÐKdÑ@dÓ"eÓf€JÜ˜Ó€Eô  Ð 2´HÀ'ÀÐJ]Ð?^Ñ4^Ó_€Iö ô %.¬n×.KÒ.KÈIÓ.V×.]Ñ.]Ô$^Ô_Ò$^™D˜A˜qˆC�ˆsˆ)�Q‹Ñ$^Ó_àð ð
 CEÐÛ‰ˆˆQØ�=�=‰=Ø×(Ñ(¨¯©¸Ó;×BÑBÀCÈÀ8ÖLñ  ð OQ€Gàeg€Ið ')€OØ%'€NÞØ—‘˜I rÖ*ˆAØ—5‘5Ð-¨rÓ2ˆDØ—e‘e˜M¨2Ö.�ß�4Ø*.¨q©'�O BÑ'Ø"×-Ñ-¨d°1©g¸À2À$Ð7GÖHó /ñ +ð —‘˜ Ó$€IØ—7‘7˜: rÓ*€LØ—‘˜ 2Ó&€JÜ Ó$€EØ×H´%¼¸I»Ô2GÓHÒ2G¨Q˜H Q C›.Ñ2GÑH€IØ€Gð &(€Nð
 ,.€MØ&(€OØ "€NØ&(€Hð *,Ðð %)€Nð "$€Oð PR€Mô !$£€OÜˆØ×Ñ˜[×)Ò)ö ÙÜ�v—}‘} S¨!Ó,¨QÑ/Ó0ˆDØ(,¬s°:«Ó(>�J˜tÒ$ÀBˆEØ�y‰y˜Ó ¤JÓ.°5·9±9¸WÓ3EÐIYÓ3YÙØˆGØŸ™ :¨r×2�Ø—y‘y Ó(×.¨B�Ø—‘ z×2Ñ2ÙØœc $§+¡+¨c°1Ó"5°aÑ"8Ó9Ñ:�ØŸ™˜f›×+¨×2Ñ2Ó4�ÞÙð
 —5‘5˜“>Ð%5Ó5Ø"�GØŸU™U 6›]×2¨r¨d°AÑ6×:Ñ:¸9ÀaÓH�EØ—O‘O T¨5 MÔ2Ø&×1Ñ1°%¸Ô>Ø—‘  a¨˜×/ñ# 3ö$ ÚØ×"Ñ"Ñ"G¹wÓ"GÔGØ˜A‘J˜q‘M×%Ñ% fÓ-×5°"°°qÑ9ˆDØ—H‘H˜Y¨Ó*ˆEØ—9‘9˜U JÓ/‰DˆAˆqñ (/÷â'.‘O�E˜1˜eØŸ5™5 ›=×0¨R¨D°!Ñ4�AØ—5‘5˜—=ó ô % Q v¡Y°°1Ó5�AÜ÷ Ù'.ð ô ö ô  Ñ9±5Ó9Ó9ÜÑ7±Ó7Ó7Ü Ñ ;±UÓ ;Ó;Ü!Ñ!=±uÓ!=Ó=ò	ð ð ó $+‘��r˜4Ø×$Ñ$ d¨E ]Ö3ñ $+à—i‘iÑD¹GÓDÓDˆGÜ Ð!3×!7Ñ!7¸¸rÓ!BÀGÓLˆGÞ˜7Ÿ=™=›?°'·-±-³/ÓAØ$˜I U¨7¨)Ð4�Ø�N‰N˜EŸI™I jÓ1×;°V¸VÀUÈQÁYÐPTÐV]Ð_cÐdÔeÚØ�_Ó$ÚØ×Ñ˜[×)Ñ)Ø%,ˆN˜6Ñ"Ü&)¨-Ó&8ˆO˜FÑ#Ø×!Ñ! &Ô)Ø×"Ñ"¤3 }Ó#5Ô6Ø#ˆNÚØ×Ñ˜]×+Ò+Øœs 6§=¡=°°aÓ#8¸Ñ#;Ó<Ñ=ˆCÜ#ØÐ&×*Ñ*¨3¯7©7°:Ó+>×+DÀ"ÓE×jÐIZ×I^ÑI^Ð_eÐgiÓIjóˆGö ÚØ—G‘G˜F“O×+¨ t¨QÑ/ˆDØ—H‘H˜Y¨Ó*ˆEØ—9‘9˜U JÓ/‰DˆAˆqØ=A¿X¹XÀf×=MÑ=M”:˜dŸh™h v¨rÓ2°A°qÔ9ÐSWˆDÞPW”jÐ!3×!7Ñ!7¸¸rÓ!BÀGÔLÐ]dˆGÞ˜7Ÿ=™=›?°'·-±-³/ÓAØ$˜I U¨7¨)Ð4�Ü" 3Ó'ˆEÜ! #Ó&ˆDÞžØ×&Ñ&¤s¨=Ó'9Ô:ð ×$Ñ$¤c¨'£l°E¸4ÀÌÈMÓHZÐ%[Ô\Ø�N‰N˜CŸG™G JÓ/×9°6¸9ÀeÈaÁiÐQUÐW^Ð`dÐeÔfÚØ× Ñ  ×,Ñ,ÚÜ�&—-‘-  QÓ'¨Ñ*Ó+ˆØ”#�i“.Ó ÚØ�c‰NˆØ—‘�f“×# ×*Ñ*Ó,ˆØ—‘�g“ˆØ—‘�f“×% "  qÑ)ˆØ—‘˜ AÓ&ˆØÐ$Ó$ØˆGÞØ—‘  u Ô.Ø"×-Ñ-¨e°TÔ:Ø!ˆNÚÞ�u 	Ó)ÚÜ˜4 ¨¯©¨oÓ(>×(DÀ"×EÑEÚØ×Ñ˜d E˜]Ô+Ø=BÀjÓ=P�×#Ñ# N×$8°bÔ9ÐVZˆØ�JÓØ!ˆNØ�y‰y˜ 
Ó+‰ˆˆ1Ø9=¿¹À&×9IÑ9IŒz˜$Ÿ(™( 6¨2Ó.°°1Ô5ÈtˆÞLS”*Ð/×3Ñ3°E¸2Ó>ÀÔHÐY`ˆÞ-4¸¿¹»ÐPT×PZÑPZÓP\Ó9\�W�I˜U 4 &Ñ)Ðbfˆà�‰˜Ÿ™˜jÓ)×3¨V°V¸UÀQ¹YÈÈgÐW]Ð^×_ñC ðZ /1€IØ(*€LÛ&3Ñ"ˆˆE�4˜ Ø×Ñ˜U BÓ'×.Ñ.¨tÔ4Ø×Ñ ¤s£uÓ-×4Ñ4ñ 5
Ù;@ó5
ö 	
ñ '4ô *-«€LÜ*7Ñ&ˆˆu�d˜E 3Ù05ÓI²¨1¸¿¹¸x¿Ó&�1—5‘5˜ 2Ö&±ˆÐIÞžtÙÙ+Ó7šO�q¨q°3©w—™OˆÐ7Þˆe�AŠh¤S¨Ó%7ˆØ   SÐ)ˆÙGLÓkÂuÀ!ÐPQ×PUÑPUÐV\ÓP]ÐajÑPjÓ=Ô(¨¯©¨x¸Ó)<Ö=ÁuˆÐkñ 9=Ó=º°1Ô$ Q§X¡XÖ.¹ˆÐ=Ü�D‹zØ —}‘} U¨BÔ/ó
Ú/�!Ô3CÀAÇHÁHÓ3MÐU]Ñ3]�AÑ/ñ
ñ 
ˆô ' w°°e¸XÀxÐQ]Ó^ˆ
ô
 (ð
 $×,Ò,ó	ò -�Að —8‘8˜wÓ&Ô*:¸1¿8¹8Ó*DÈÓ*Pñ à—\‘\¨(°IÐ)>�\Ð?ò@ñ -ñ	ô ˜J×1Ñ1Ó2Ü˜j×5Ñ5Ó6ñ	
ˆ
ð × × Ü+¨J¼ÀgÀYÈdÐCSÑ8SÐUZÓ[ˆJØ6=¸e±nÑ3ˆ�˜%  t¨VØ5?×5HÒ5HÓIÒ5H°�A—H‘H�:˜U 1§6¡6 (Ó+Ñ5HˆÐIÞàØØØØ”Ñ&¨¯©°5Ó)9Ñ9ØðˆG�E‰Nô �KŠKÐIÌ3ÈuË:ÐW]Ð_dÔeð  ˆØ×(Ô(ˆAÜ" 1§8¡8Ó,ˆCØ�l×&Ñ& u¬c«eÓ4Ó4¸À¸ÈÓ8TÙØ×Ñ˜e S˜\Ô*Ø�N‰N˜aŸh™h˜Z q¨¯©¨Ð1×7Ñ7Ó9Ö:ñ )ð 2<×1FÒ1FÓGÒ1F¨AÐ# QÓ'Ñ1FÑGÙ?FÓGºw°VÐ'¨Ó0¹wÑGñHñ óâ�AØŸ™˜g›×,¨"×3Ñ3×5ó BÐ+¨Q¯U©U°8¸RÓ-@ÓAÙññð 	ô $-¨UÖ#3ÑˆAÑ�˜Ü�NŠNØ9¸VÀuÐU[Ð_eòð ×ÑØ�8˜4 ˜sÐ# [°%¸À
ÈFÐ?SÐU[Ð]aÐciÐjöô	 $4ñ_ +8ðn ‡N�NÔ,¨]Ð<NÓOÔPó  ‰ˆˆQØ�e‰e×?”} S¨%°·±Ó?ˆà—W‘WØ—h‘hØ—]‘]ØŸ=™=ñ	
ˆð �}�}Ø%4°Q·V±V°HÐ#=ˆH�ZÑ Ø×ÑàØØ—‘˜‘
Þ ”�S”	 dØØ—‘Ø—‘Ø—‘ð	ö	
ñ  ð. 8;·w±w¸xÈÔ7LÓMÒ7L°�b—f‘f˜ZÓ(¨"Ò,Ñ7L€NÐMÜ˜&×!‰ˆˆ1Ø—‘�f˜aÓ ˆØ—‘Ð'Ó(×?¨A¯E©E°,Ó,?ˆØˆÞØ#‰NˆB��B˜Ø r°BÀ"ÑEˆDð �u‰uÐ%Ó&×,¨"ˆÞ&*Œz˜!˜TÔ"°·±°jÓ0AˆÜ˜1˜n×0Ñ0°×1DÑ1DÀQÈÓ1KÓLÈiÓXˆØ ×$Ñ$ _×%8Ñ%8¸¸BÓ%?ÀÓDˆÞÜ Ð!3×!7Ñ!7¸¿¹¸fÀaÓ8HÈ"Ó!MÈwÓWˆGÞ”sÔJÁTÓJ×JÑJØ�K‰K˜˜7Ô#ð —‘Ð&Ó'×-¨2ˆð —e‘e˜KÓ(×.¨BÐ.ó
â.�ô /9¸¼C×.@Ñ.@ŒK˜r¨Ò*Äk×F`ÒF`ÐabÓFcÒcÙ.ð 	ð 
ñ 16Ó6²¨1�1—5‘5˜ 2Ö&±Ñ6¼¸a¿e¹eÀOÓ>T×>ZÐXZÓ9[Ñ[ˆð "×%Ñ% a¨Ó,ˆØ×!Ñ! 'Ó*ˆØ‰?Ø ×&Ñ& wÓ/ˆCð ˜‘7œS Ó0Ó0ð   ¨s°Q©wÑ 7Ò8ä˜Ó'ð ð
 % S¨Ð-‰Há#0ÓB¢=˜a°A°a±D¸E±MŸ¡=ˆHÐBÙGLÓkÂuÀ!ÐPQ×PUÑPUÐV\ÓP]ÐajÑPjÓ=Ô(¨¯©¨x¸Ó)<Ö=ÁuˆÐkÜ& w°°u¸hÈÐR^Ó_ˆ
Ø× × Ü+¨J¼ÀgÀYÈdÐCSÑ8SÐUZÓ[ˆJð <F×;NÒ;NÓOÒ;N°a˜!Ÿ(™(˜ 5¨¯©¨Ó1Ñ;NÑOÙ!óS
Ú!�q¨¯­‹F°a·f±f·l±l·n‹FˆA�FŒF™EñS
ñ 
ˆö /3�$—)‘)˜D D 6™MÔ*¸¿	¹	À$»ˆÞØ”¨¯©°;Ó)?Ñ?Ñ?ˆGØ�‰˜) A 3˜¨°%¸!±)¸TÀ7ÈDÐQÔRð$ —‘�mÓ$ˆÞœ
 5¬#×.Ñ.Ü�NŠNð^àØô	÷ Ø'+ˆIÜ˜5¤# d£)×,�Ø˜1‘g�ÜÑLÉÓL×LÑLÙô
 ÑPÈÈAÈBÉÓP×PÑPØ !�IÙÜœE %›LÓ)¸IÑ<Q¨i©[ÐWYÑZÐ^_Ð]`Ñ`�Ü& q¹DÓ*AºD°q¨4°¬7¹DÑ*AÈtÑT�	Ø#Ÿy™y¨°°Ñ);Ó<�ô ˜t›9�Ø(*�
Ü&)£e�	Û�AØ—u‘u˜U“|¨8Ó3Ù Ü*¨1¯5©5°¸2Ó+>Ó?�CÞ #¨Ó"2Ù Ø—M‘M #Ô&Ø *× 3Ñ 3°A·E±E¸(ÀBÓ4GÓ H�Iß �yØ"×)Ñ)¨Q¯U©U°8«_Ð,=¸UÀ9À+Ð*NÖOñ ö Ø ¤O°d·i±iÀ
Ó6KÑ$KÑK�LÙ14ÓH²¨¸¿¹À¿›˜˜eœ±�ÐHö ô !$Ñ#8±%Ó#8Ó 8Ü"Ñ"7±Ó"7Ó7Ü!$Ñ$9±5Ó$9Ó!9Ü"%Ñ%:±EÓ%:Ó":ò	ð ð ð —‘Ø˜˜˜6 ! Ð% {°E¸A±I¸yÈ,ÐZcÐdeÐcfÐXgÐh÷ñ[ -ôl   –o‰FˆAˆsÜ$ Sž>‘��4Ø—h‘h˜u“o×K¬¸¸aÀÀFÓ)K�æZ]˜S ™V¨C°©F¸SÀ¹VÈsÐSTÉvÒVÐcgð ð × Ñ à˜A˜3˜a ˜s ! A 3˜Ø#Ø ™	Ø!Ø !¨!¸9ÀQÀC¸ÑIØŸ™ Ó*ØŸ™ Ó(ØŸ™ Ó(×.¨Bð	öó *ñ &ô. ˜D &Ó)ˆÞ^b˜T !™W¨T°!©W¸tÀA¹wÐRVÐWXÑRYÒZÐhlˆ	Ü$ Q§U¡U¨>Ó%:×%@¸bÖA‰KˆAˆxØ×Ñà˜�s˜) A 3Ð'ØØ˜A‘IØØ 9¨Q¨C Ð1Ø)ØØð	öñ Bð  2<×1FÒ1FÓGÒ1F¨AÐ# QÓ'Ñ1FÑGØR\×RiÒRiÓjÒRiÈQÐ'¨A¯H©H¨:°Q°q·v±v°hÐ)?×)EÑ)EÓ)GÓHÑRiÑjñkáJOÓhÊ%ÀQÐST×SXÑSXÐY^ÓS_Ó@Ð*¨A¯E©E°(¸BÓ,?Ó@É%Ñhñið 	ô
 $-¨^Ö#<ÑˆAÑ�˜Ü�NŠNÐBÀaÈ5ÐY_ÐciÒjØ×Ñà˜�s˜$˜q˜c�NØØ˜A‘IØØ 9¨Q¨C Ð1ØØØð	öô $=ñ} "÷^ ð —Z‘Z 	¨2Ô.ô
â.�Ø�u‰u�V‹} 
Ñ*ó ð —u‘uÐ1°2×6�ó ñ 7ñ Ù.ð 	ñ 
ð 14·±¸À"Ô0EÓFÒ0E¨1�!—%‘%˜
Ó# QÒ&Ñ0EˆÐFÜ˜+¨
Ñ2×3ˆCØ—
‘
˜3“ˆAØ‰yÜ—’Ð`ÐfiÒjÙÜ)¨!Ó,ˆGÞÜ—’ÐQÐWZÒ[ÙØ—E‘E˜&“M×) b T¨1Ñ-ˆDØ—H‘H˜Y¨Ó*ˆEØ$×(Ñ(¨¨bÓ1ˆGÞÜ$Ð%7×%;Ñ%;¸EÀ2Ó%FÈÓP�Þ˜7Ÿ=™=›?°'·-±-³/ÓAØ$˜I R¨ yÐ1�Ø—9‘9˜U JÓ/‰DˆAˆqØ=A¿X¹XÀf×=MÑ=M”:˜dŸh™h v¨rÓ2°A°qÔ9ÐSWˆDà�N‰N˜i¨ uÐ-¨w¸À¹	À4ÈÐRVÐWÔXÜ�KŠKÐMÐSVÐZ_Õ`ñ) 4ö4 PWŒn˜WÁ'Ó&JÂ'¸Q¤{°1°Q±4Ö'8Á'Ñ&JÔKÐ\^€GØ�7‰7�8˜RÓ €DØ×C˜4Ÿ8™8 JÓ/×C°g°Y¸dÐ3C€HÜ�U“×#˜t€JÜ—>’> )×"6Ñ"6Ó"8Ó9×CÑCÓE€Lä	�ŠŒ˜Ø�‰ÐNÐQXÐPZÔ[Ø�l‰lð;ð �l H¨j¸.ÐIó	
÷
 ‰(‹*ð 	ð ‰ÐˆØ�Q‘ˆäEHÈÐRYÐbfÔEgÑAÑ<ˆV�X˜u d¨G°V¸cØ�L‰Lð>ð ˜ ¨5´$·*²*¸TÓ2BÄHÈWÓDUÐWZÐ\bÐcô	ð �L‰LðCð ˜ ¨5´$·*²*¸TÓ2BÐCöñ Fhó" QZÑLˆF�H˜e T¨8°V¸TÀ9Ø�L‰LðCð
 ØØØÜ—J’J˜tÓ$Ü—J’J˜xÓ(ØÜ˜T“NÜ˜YÓ'ð
öñ QZ÷9 
ô^ ‡N‚NØdØÜ
ˆg‹,Ü
Ñ3™Ó3Ó
3ÜÑ5™'Ó5Ó5ÜÑ9™'Ó9Ó9Ü�)‹nòô ˆw‹<ÐùóM 	`ùòN IùöXùò^ Jùò 8ùò lùò >ùò
ùòùò Jùò< HùÚGùòùòX Nùò8
ùò 7ùò$ CùÚkùò Pùò S
ùò\ +Bùò, Iùòz HùÚjùÚhùó(
ùò Gùò6 'K÷ 
ŽúsN  Å1AwÊ5Aw$Ô<Aw)ÕAw)ÕAw)îAw2î)Aw2ï
Aw7ï#Aw7ðAw<ð(Aw<ñAxòAxò-AxóAAx
ö%Axú/AxûAxû1AxüAxÁBAx$ÁH7?Ax)ÁI<Ax.ÁL(Ax3ÁL9Ax3ÁMAx8ÁM"Ax8ÁO	%Ax=ÁO4AyÁPAyÁP.AyÁU>AyÁZAyÁZ-	AyÁbAyÁb&5AyÁc#AyÁc=AyÁfAy Áf0 Ay Ág'Ay&ÁnAy+
ÁqD(Ay0Áy0
Ay?c                ó,  • SS K nUR                  SS9nUR                  SSSS9  UR                  SSS	S9  UR                  S
SSS9  UR                  SSSS9  UR                  SS SS9  UR                  SS SS9  UR                  SS SS9  UR                  SS SS9  UR                  SS SS9  UR                  SSS/SSS9  UR                  SSS S!9  UR                  U 5      nUR                  (       a+  [
        R                  " 5         [        R                  " S"5        [        UR                  UR                  UR                  UR                  UR                  UR                  UR                   UR"                  UR$                  UR&                  S#9
  g )$Nr   z?Ingest quber fusion output into the playground pgvector schema.)rk   z	--doc-keyTz#opaque storage key for the document)ÚrequiredÚhelpz--unified-jsonz.local path or s3:// URI to <base>.unified.jsonz--tables-jsonz-local path or s3:// URI to <base>.tables.jsonz--pdfz)local path or s3:// URI to the source PDFz--fusion-jsonztlocal path or s3:// URI to <base>.fusion.json; enables ingesting SoM-missed docling tables from the unified document)Údefaultr  z--scanned-tables-jsonz�local path or s3:// URI to <base>.scanned-tables.json; the tables the figure run read off a page image, ingested alongside the table engine'sz--figures-jsonz“local path or s3:// URI to <base>.figures.json; names the parse tables a scanned table replaced, so the parse's reading of them is not ingested tooz--figure-values-jsonz‰local path or s3:// URI to <base>.figure-values.json; the reconciled figure values, grounded per value and listed on their picture chunksz
--filenamez,original PDF filename, kept for presentationz
--chunkingÚflatrT  uå   ingestion stream: flat serves every printed line as its own chunk â€” the dpt-2 stream's byte-stable behavior (default); grouped is the dpt-3 track's â€” binding groups served as one chunk, page heading joined into the ride-along)Úchoicesr  r  z--init-schemaÚ
store_truez#(re)create the schema before ingest)Úactionr  zApplied schema)r³  r´  rµ  r¶  r‘  r·  )ÚargparseÚArgumentParserÚadd_argumentÚ
parse_argsÚinit_schemar   Úapply_schemar   r­  r  r¯  r°  r±  Úpdfr³  r´  rµ  r¶  r‘  r·  )Úargvr  rp   Úargss       r(   Úmainr  ý  sµ  € Ûà×ÑÐ,mÐÐn€AØ‡N�N�;¨Ð4Y€NÑZØ‡N�NÐ#¨dÐ9i€NÑjØ‡N�N�?¨TÐ8g€NÑhØ‡N�N�7 TÐ0[€NÑ\Ø‡N�NØØð>ð ñ ð ‡N�NØØðRð ñ ð ‡N�NØØðUð ñ ð ‡N�NØØðOð ñ ð ‡N�N�<¨Ð4b€NÑcØ‡N�NØØ˜Ð#Øð%ð	 ñ ð ‡N�N�?¨<Ð>c€NÑdØ�<‰<˜Ó€Dà××Ü
�ŠÔÜ�ŠÐ'Ô(Ü
Ø�‰Ø×ÑØ×ÑØ�‰Ø×$Ñ$Ø ×4Ñ4Ø×&Ñ&Ø×2Ñ2Ø—‘Ø—‘ór*   Ú__main__)r&   úOptional[str]r'   r   r¹   úOptional[dict])r&   r7   r'   r   r¹   r   )r>   r7   r?   r7   r¹   r7   )rE   r7   rF   rD   rG   r7   r¹   Úbool)rO   r÷   r¹   zlist[FootnoteDef])rO   r÷   r¹   ú
list[dict])r6   r!  r¹   zset[str])rO   r÷   r¹   r7   )rg   r7   r    r7   rh   r7   r¹   r7   )rf   )rO   r÷   r{   ú!Sequence[tuple[str, FigureValue]]r¹   r7   )r„   r$  rŠ   zdict[int, str]r¹   z>list[tuple[str, str, int, Optional[dict], str, Optional[str]]])rš   r÷   r›   údict[int, tuple[float, float]]r†   r   r¹   úOptional[dict[str, float]])rš   r÷   r¹   ú	list[str])rš   r÷   r¹   r%  )rÖ   zdict[str, Any]r×   rÅ   rØ   rÅ   r¹   r&  )rã   r7   r¹   r7   )rã   r   r¹   r   )rŽ   r7   r¹   r7   )rË   r÷   r°   r!  r    r#  r¹   r'  rn   )r   rD   r  úlist[list[dict]]r  zOptional[list[int]]r¹   r7   )
r  r(  rÊ   rD   rþ   rD   r  úOptional[tuple]r¹   ú+Optional[tuple[float, float, float, float]])r  r(  r  r)  r¹   r*  )rË   r÷   r¹   r7   )rI  r   rJ  r   r�   rD   r¹   r   )NNNNNr  )r¯  r7   r°  r7   r±  r7   r²  r7   r³  r   r´  r   rµ  r   r¶  r   r‘  r   r·  r7   r¹   rD   )r  zOptional[list[str]]r¹   rº   )HÚ__doc__Ú
__future__r   r¥  r!   rì   r5   ÚsysÚpathlibr   Útypingr   r   r   Úlogurur   Úremover§   ÚstderrÚquber.agents.llm_clientr   Úquber.core.figures.dpt3.blocksr   Úquber.core.figures.graftr   r   Úquber.core.figures.modelsr   r   Úquber.core.fusion.footnotesr   r   r   r   Úquber.playgroundr   Úquber.playground.embeddingr   Úquber.settingsr   Ú
playgroundÚdata_dirrœ  rë   ru   r)   r#   r@   rH   rQ   rT   r]   rc   ri   r~   r�   rž   r¿   rÇ   r™   rä   rç   rî   rú   r  r"  r'  r1  rR  r  r  Ú__name__rf   r*   r(   Ú<module>r>     s6  ðñSõj #ã Û Û 	Û Û 
Ý ß *Ñ *å ð ‡‚„Ø ‡
‚
ˆ3�:‰:˜VÒ $å /Ý 5ß Jß A÷ó õ  Ý 5Ý 'á‹>×$Ñ$×-Ñ-€ð #€ò 9Ð ô5ô&ô#ô QôôKôô&;ô
Föð:&Ø4ð&à&ð&ð Dô&ðRØ	ðØ4ðØCPðàôô"2ôjôô.Mô<ô0ôcö*8ð(Ø
ðØ"ðØ'*ðØ4Cðà0ôð>FØ
ðFØ$3ðFà0ôFô 
\ô3ðH "&Ø)-Ø"&Ø(,Ø"Øðw
Øðw
àðw
ð ðw
ð ð	w
ð
 ðw
ð 'ðw
ð  ðw
ð &ðw
ð ðw
ð ðw
ð 	õw
öt;ð| ˆzÓÙ…Fð r*   