nucliadb-models 6.8.1.post4983__py3-none-any.whl → 6.8.1.post4988__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of nucliadb-models might be problematic. Click here for more details.

@@ -0,0 +1,424 @@
1
+ # Copyright 2025 Bosutech XXI S.L.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+ #
15
+ from typing import Annotated, Optional, Union
16
+
17
+ from pydantic import BaseModel, Field, StringConstraints
18
+
19
+ from nucliadb_models.common import FieldTypeName
20
+ from nucliadb_models.metadata import Origin
21
+ from nucliadb_models.resource import FieldConversation, FieldFile, FieldLink, FieldText
22
+ from nucliadb_models.search import Image
23
+ from nucliadb_models.security import ResourceSecurity
24
+
25
+
26
+ class ResourceHydration(BaseModel, extra="forbid"):
27
+ title: bool = Field(
28
+ default=True,
29
+ description="Hydrate resource titles",
30
+ )
31
+ summary: bool = Field(
32
+ default=False,
33
+ description="Hydrate resource summaries",
34
+ )
35
+
36
+ origin: bool = Field(
37
+ default=False,
38
+ description="Hydrate resource origin",
39
+ )
40
+
41
+ security: bool = Field(
42
+ default=False,
43
+ description="Hydrate resource security metadata",
44
+ )
45
+
46
+
47
+ class TextFieldHydration(BaseModel, extra="forbid"):
48
+ value: bool = Field(
49
+ default=False,
50
+ description="Hydrate text field values. Field values are similar payloads to the ones used to create them",
51
+ )
52
+ extracted_text: bool = Field(
53
+ default=False,
54
+ description="Hydrate extracted text for text fields",
55
+ )
56
+ # TODO: what else should be interesting to add?
57
+
58
+
59
+ class FileFieldHydration(BaseModel, extra="forbid"):
60
+ value: bool = Field(
61
+ default=False,
62
+ description="Hydrate file field values. Field values are similar payloads to the ones used to create them",
63
+ )
64
+ extracted_text: bool = Field(
65
+ default=False,
66
+ description="Hydrate extracted text for file fields",
67
+ )
68
+ # TODO: what else should be interesting to add?
69
+
70
+
71
+ class LinkFieldHydration(BaseModel, extra="forbid"):
72
+ value: bool = Field(
73
+ default=False,
74
+ description="Hydrate link field values. Field values are similar payloads to the ones used to create them",
75
+ )
76
+ extracted_text: bool = Field(
77
+ default=False,
78
+ description="Hydrate extracted text for link fields",
79
+ )
80
+ # TODO: what else should be interesting to add?
81
+
82
+
83
+ class ConversationFieldHydration(BaseModel, extra="forbid"):
84
+ value: bool = Field(
85
+ default=False,
86
+ description="Hydrate conversation field values. Field values are similar payloads to the ones used to create them",
87
+ )
88
+
89
+ # TODO: add fields to hydrate conversation fields. Think about how to handle
90
+ # splits and fulfill the conversational RAG strategies
91
+
92
+ # TODO: what else should be interesting to add?
93
+
94
+
95
+ class GenericFieldHydration(BaseModel, extra="forbid"):
96
+ value: bool = Field(
97
+ default=False,
98
+ description="Hydrate generic field values. Field values are similar payloads to the ones used to create them",
99
+ )
100
+ extracted_text: bool = Field(
101
+ default=False,
102
+ description="Hydrate extracted text for generic fields",
103
+ )
104
+ # TODO: what else should be interesting to add?
105
+
106
+
107
+ class FieldHydration(BaseModel, extra="forbid"):
108
+ text: Optional[TextFieldHydration] = Field(
109
+ default_factory=TextFieldHydration,
110
+ description="Text fields hydration options",
111
+ )
112
+ file: Optional[FileFieldHydration] = Field(
113
+ default_factory=FileFieldHydration,
114
+ description="File fields hydration options",
115
+ )
116
+ link: Optional[LinkFieldHydration] = Field(
117
+ default_factory=LinkFieldHydration,
118
+ description="Link fields hydration options",
119
+ )
120
+ conversation: Optional[ConversationFieldHydration] = Field(
121
+ default_factory=ConversationFieldHydration,
122
+ description="Conversation fields hydration options",
123
+ )
124
+ generic: Optional[GenericFieldHydration] = Field(
125
+ default_factory=GenericFieldHydration,
126
+ description="Generic fields hydration options",
127
+ )
128
+
129
+
130
+ class NeighbourParagraphHydration(BaseModel, extra="forbid"):
131
+ before: int = Field(
132
+ default=2,
133
+ ge=0,
134
+ description="Number of previous paragraphs to hydrate",
135
+ )
136
+ after: int = Field(
137
+ default=2,
138
+ ge=0,
139
+ description="Number of following paragraphs to hydrate",
140
+ )
141
+
142
+
143
+ class RelatedParagraphHydration(BaseModel, extra="forbid"):
144
+ neighbours: Optional[NeighbourParagraphHydration] = Field(
145
+ default=None,
146
+ description="Hydrate extra paragraphs that surround the original one",
147
+ )
148
+
149
+ # TODO: FEATURE: implement related paragraphs by page
150
+ # page: bool = Field(
151
+ # default=False,
152
+ # description="Hydrate all paragraphs in the same page. This only applies to fields with pages",
153
+ # )
154
+
155
+ # TODO: description
156
+ # XXX: should we let users control the amount of elements?
157
+ parents: bool = False
158
+ # TODO: description
159
+ # XXX: should we let users control the amount of elements?
160
+ siblings: bool = False
161
+ # TODO: description
162
+ # XXX: should we let users control the amount of elements?
163
+ replacements: bool = False
164
+
165
+
166
+ class ImageParagraphHydration(BaseModel, extra="forbid"):
167
+ # The source image is also known as reference or reference_file in the
168
+ # paragraph context. The reference/reference_file is the filename of the
169
+ # source image from which the paragraph has been extracted
170
+ source_image: bool = Field(
171
+ default=False,
172
+ description=(
173
+ "When a paragraph has been extracted from an image (using OCR, inception...), "
174
+ "hydrate the image that represents it"
175
+ ),
176
+ )
177
+
178
+
179
+ class TableParagraphHydration(BaseModel, extra="forbid"):
180
+ # TODO: implement. ARAG uses the label "/k/table" to check whether a
181
+ # paragraph is or a table or not. We can also use info on maindb
182
+ table_page_preview: bool = Field(
183
+ default=False,
184
+ description="Hydrate the page preview for the table. This will only hydrate fields with pages",
185
+ )
186
+
187
+
188
+ class ParagraphPageHydration(BaseModel, extra="forbid"):
189
+ # For some field types (file and link) learning generates previews. A
190
+ # preview is a PDF file representing the content. For a docx for example, is
191
+ # the PDF equivalent. Depending on the field type, the preview can
192
+ # represent, for example, a page in a document or a portion of a webpage.
193
+ page_with_visual: bool = Field(
194
+ default=False,
195
+ description=(
196
+ "When a paragraph has been extracted from a page containing visual "
197
+ "content (images, tables...), hydrate the preview of the paragraph's "
198
+ "page as an image. Not all field types have previews nor visual content"
199
+ ),
200
+ )
201
+
202
+
203
+ class ParagraphHydration(BaseModel, extra="forbid"):
204
+ text: bool = Field(
205
+ default=True,
206
+ description="Hydrate paragraph text",
207
+ )
208
+ image: Optional[ImageParagraphHydration] = Field(
209
+ default=None,
210
+ description="Hydrate options for paragraphs extracted from images (using OCR, inception...)",
211
+ )
212
+ table: Optional[TableParagraphHydration] = Field(
213
+ default=None,
214
+ description="Hydrate options for paragraphs extracted from tables",
215
+ )
216
+
217
+ # TODO: at some point, we should add hydration options for paragraphs from
218
+ # audio and video
219
+
220
+ page: Optional[ParagraphPageHydration] = Field(
221
+ default=None,
222
+ description="Hydrte options for paragraphs within a page. This applies to paragraphs in fields with pages",
223
+ )
224
+
225
+ related: Optional[RelatedParagraphHydration] = Field(
226
+ default=None,
227
+ description="Hydration options for related paragraphs. For example, neighbours or sibling paragraphs",
228
+ )
229
+
230
+
231
+ class Hydration(BaseModel, extra="forbid"):
232
+ resource: Optional[ResourceHydration] = Field(
233
+ default_factory=ResourceHydration,
234
+ description="Resource hydration options",
235
+ )
236
+ field: FieldHydration = Field(
237
+ default_factory=FieldHydration,
238
+ description="Field hydration options",
239
+ )
240
+ paragraph: ParagraphHydration = Field(
241
+ default_factory=ParagraphHydration,
242
+ description="Paragraph hydration options",
243
+ )
244
+
245
+
246
+ ParagraphId = Annotated[
247
+ str,
248
+ StringConstraints(
249
+ pattern=r"^[0-9a-f]{32}/[acftu]/[a-zA-Z0-9:_-]+/[0-9]+-[0-9]+$",
250
+ min_length=32 + 1 + 1 + 1 + 1 + 1 + 3,
251
+ # max field id of 250 and 10 digit paragraphs. More than enough
252
+ max_length=32 + 1 + 1 + 1 + 250 + 1 + 21,
253
+ ),
254
+ ]
255
+
256
+
257
+ class HydrateRequest(BaseModel, extra="forbid"):
258
+ data: list[ParagraphId] = Field(
259
+ description="List of paragraph ids we want to hydrate",
260
+ max_length=50,
261
+ )
262
+ hydration: Hydration = Field(description="Description of how hydration must be performed")
263
+
264
+
265
+ ### Response models
266
+
267
+
268
+ class HydratedResource(BaseModel, extra="forbid"):
269
+ id: str = Field(description="Unique resource id")
270
+ slug: str = Field(description="Resource slug")
271
+
272
+ title: Optional[str] = None
273
+ summary: Optional[str] = None
274
+
275
+ origin: Optional[Origin] = None
276
+
277
+ security: Optional[ResourceSecurity] = None
278
+
279
+ # TODO: add resource labels to hydrated resources
280
+
281
+
282
+ class FieldExtractedData(BaseModel, extra="forbid"):
283
+ text: Optional[str] = None
284
+
285
+
286
+ class SplitFieldExtractedData(BaseModel, extra="forbid"):
287
+ texts: Optional[dict[str, str]] = None
288
+
289
+
290
+ class HydratedTextField(BaseModel, extra="forbid"):
291
+ id: str = Field("Unique field id")
292
+ resource: str = Field("Field resource id")
293
+ field_type: FieldTypeName = FieldTypeName.TEXT
294
+
295
+ value: Optional[FieldText] = None
296
+ extracted: Optional[FieldExtractedData] = None
297
+
298
+
299
+ class HydratedFileField(BaseModel, extra="forbid"):
300
+ id: str = Field("Unique field id")
301
+ resource: str = Field("Field resource id")
302
+ field_type: FieldTypeName = FieldTypeName.FILE
303
+
304
+ value: Optional[FieldFile] = None
305
+ extracted: Optional[FieldExtractedData] = None
306
+
307
+ previews: Optional[dict[str, Image]] = Field(
308
+ default=None,
309
+ title="Previews of specific parts of the field",
310
+ description=(
311
+ "Previews for specific pages of this field. Previews are differents"
312
+ "depending on the file type. For example, for a PDF file, a preview"
313
+ "will be an image of a single page."
314
+ "In this field, previews will be populated according to the hydration"
315
+ "options requested."
316
+ ),
317
+ )
318
+
319
+
320
+ class HydratedLinkField(BaseModel, extra="forbid"):
321
+ id: str = Field("Unique field id")
322
+ resource: str = Field("Field resource id")
323
+ field_type: FieldTypeName = FieldTypeName.LINK
324
+
325
+ value: Optional[FieldLink] = None
326
+ extracted: Optional[FieldExtractedData] = None
327
+
328
+
329
+ class HydratedConversationField(BaseModel, extra="forbid"):
330
+ id: str = Field("Unique field id")
331
+ resource: str = Field("Field resource id")
332
+ field_type: FieldTypeName = FieldTypeName.CONVERSATION
333
+
334
+ value: Optional[FieldConversation] = None
335
+ extracted: Optional[FieldExtractedData] = None
336
+
337
+
338
+ class HydratedGenericField(BaseModel, extra="forbid"):
339
+ id: str = Field("Unique field id")
340
+ resource: str = Field("Field resource id")
341
+ field_type: FieldTypeName = FieldTypeName.TEXT
342
+
343
+ value: Optional[str] = None
344
+ extracted: Optional[FieldExtractedData] = None
345
+
346
+
347
+ class RelatedNeighbourParagraphRefs(BaseModel, extra="forbid"):
348
+ before: Optional[list[str]] = None
349
+ after: Optional[list[str]] = None
350
+
351
+
352
+ class RelatedParagraphRefs(BaseModel, extra="forbid"):
353
+ neighbours: Optional[RelatedNeighbourParagraphRefs] = None
354
+ parents: Optional[list[str]] = None
355
+ siblings: Optional[list[str]] = None
356
+ replacements: Optional[list[str]] = None
357
+
358
+
359
+ class HydratedParagraphImage(BaseModel, extra="forbid"):
360
+ source_image: Optional[Image] = Field(
361
+ default=None,
362
+ description=(
363
+ "Source image for this paragraph. This only applies to paragraphs "
364
+ "extracted from an image using OCR or inception, and if this "
365
+ "hydration option has been enabled in the request"
366
+ ),
367
+ )
368
+
369
+
370
+ class HydratedParagraphTable(BaseModel, extra="forbid"):
371
+ page_preview_ref: Optional[str] = Field(
372
+ default=None,
373
+ description=(
374
+ "Referento to the page preview for this paragraph. The actual "
375
+ "preview will be found in the previews of its field. This only "
376
+ "applies to paragraphs generated from a table and if the "
377
+ "corresponding hydration option has been enabled in the request"
378
+ ),
379
+ )
380
+
381
+
382
+ class HydratedParagraphPage(BaseModel, extra="forbid"):
383
+ page_preview_ref: Optional[str] = Field(
384
+ default=None,
385
+ description=(
386
+ "Reference to the page preview for this paragraph. The actual "
387
+ "preview will be found in the previews of its field. This only "
388
+ "applies to paragraphs extracted from a page containing visual "
389
+ "content and if the corresponding hydration option has been enabled "
390
+ "in the request"
391
+ ),
392
+ )
393
+
394
+
395
+ class HydratedParagraph(BaseModel, extra="forbid"):
396
+ id: str = Field(description="Unique paragraph id")
397
+ field: str = Field(description="Paragraph field id")
398
+ resource: str = Field(description="Paragraph resource id")
399
+
400
+ text: Optional[str] = None
401
+
402
+ # TODO: add labels to hydrated paragraphs
403
+ # labels: Optional[list[str]] = None
404
+
405
+ related: Optional[RelatedParagraphRefs] = None
406
+
407
+ image: Optional[HydratedParagraphImage] = None
408
+ table: Optional[HydratedParagraphTable] = None
409
+ page: Optional[HydratedParagraphPage] = None
410
+
411
+
412
+ class Hydrated(BaseModel, extra="forbid"):
413
+ resources: dict[str, HydratedResource]
414
+ fields: dict[
415
+ str,
416
+ Union[
417
+ HydratedTextField,
418
+ HydratedFileField,
419
+ HydratedLinkField,
420
+ HydratedConversationField,
421
+ HydratedGenericField,
422
+ ],
423
+ ]
424
+ paragraphs: dict[str, HydratedParagraph]
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: nucliadb_models
3
- Version: 6.8.1.post4983
3
+ Version: 6.8.1.post4988
4
4
  Author-email: Nuclia <nucliadb@nuclia.com>
5
5
  License-Expression: Apache-2.0
6
6
  Project-URL: Homepage, https://nuclia.com
@@ -9,6 +9,7 @@ nucliadb_models/external_index_providers.py,sha256=IIKjJjLixWQC1zrbzam2FDcAo5UUx
9
9
  nucliadb_models/extracted.py,sha256=Owz7LC3le3Dvau3TtRiO8NY84meOf6IxN-RrOqqpMPs,5593
10
10
  nucliadb_models/file.py,sha256=tXtgB9c7i2ADsnJ7HdbXyroAmXadGvOeA49htBh7BZo,2263
11
11
  nucliadb_models/filters.py,sha256=NQI2-4AFzzJuZy8NeY3jXlTbbU5wxiwMCP-5DrD-7lE,14759
12
+ nucliadb_models/hydration.py,sha256=7SFnAcTQRE9etVccpph6aA1AUqsHVwkzT4YF6Uzl0Gs,14262
12
13
  nucliadb_models/labels.py,sha256=9zqRgkpZuX3kUPwsTTgCH7JyOWK7dM5pwyuHJR86YdU,3949
13
14
  nucliadb_models/link.py,sha256=PF5hHLwdOed5TMBTxtokkgWtMh1bFnORZjybh0NwVCw,2526
14
15
  nucliadb_models/metadata.py,sha256=MFVYnpXMBoY4ylMg029o7yDKGxhK7NB0c0FSshzJHm4,8356
@@ -32,7 +33,7 @@ nucliadb_models/graph/responses.py,sha256=Sdq8OgFAL1YT-1lJyLLrkqcScvj7YTEqAUwQ-k
32
33
  nucliadb_models/internal/__init__.py,sha256=zG33bUz1rHFPtvqQPWn4rDwBJt3FJodGuQYD45quiQg,583
33
34
  nucliadb_models/internal/predict.py,sha256=Pnx6MmLfK65eExe1XnVxqmSlvMwdowewwks9BOEoqMw,2029
34
35
  nucliadb_models/internal/shards.py,sha256=__y1OZtWGiNcPQEWfSFOj8yw458WGi7mM4vZe0K-L1Y,1691
35
- nucliadb_models-6.8.1.post4983.dist-info/METADATA,sha256=1_uAWLGHp8_M1Y91Byb5aHUT9b0izZgsecCB9-d4t6Y,794
36
- nucliadb_models-6.8.1.post4983.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
37
- nucliadb_models-6.8.1.post4983.dist-info/top_level.txt,sha256=UrY1I8oeovIRwkXLYplssTrxQdUjhSEFDFbnwaIV3tA,16
38
- nucliadb_models-6.8.1.post4983.dist-info/RECORD,,
36
+ nucliadb_models-6.8.1.post4988.dist-info/METADATA,sha256=fy1-QANJo4iuyQTTSj2mhgC3HxkGSz_mmYvHWQwL4e4,794
37
+ nucliadb_models-6.8.1.post4988.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
38
+ nucliadb_models-6.8.1.post4988.dist-info/top_level.txt,sha256=UrY1I8oeovIRwkXLYplssTrxQdUjhSEFDFbnwaIV3tA,16
39
+ nucliadb_models-6.8.1.post4988.dist-info/RECORD,,