nucliadb 6.9.0.post5068__py3-none-any.whl → 6.9.0.post5072__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 might be problematic. Click here for more details.

@@ -42,7 +42,7 @@ class Settings(BaseSettings):
42
42
  description="Maximum number of paragraphs to target per shard",
43
43
  )
44
44
  max_resource_paragraphs: int = Field(
45
- default=50_000,
45
+ default=300_000,
46
46
  title="Max paragraphs per resource",
47
47
  description="Maximum number of paragraphs allowed on a single resource",
48
48
  )
@@ -25,6 +25,8 @@ from nucliadb_protos.resources_pb2 import CloudFile, FieldConversation
25
25
  from nucliadb_protos.resources_pb2 import Conversation as PBConversation
26
26
  from nucliadb_utils.storages.storage import StorageField
27
27
 
28
+ MAX_CONVERSATION_MESSAGES = 50 * 1024
29
+
28
30
  PAGE_SIZE = 200
29
31
 
30
32
  CONVERSATION_PAGE_VALUE = "/kbs/{kbid}/r/{uuid}/f/{type}/{field}/{page}"
@@ -18,7 +18,7 @@
18
18
  # along with this program. If not, see <http://www.gnu.org/licenses/>.
19
19
  #
20
20
  from inspect import iscoroutinefunction
21
- from typing import TYPE_CHECKING, Annotated, Callable, Optional, Type, Union
21
+ from typing import TYPE_CHECKING, Annotated, Callable, List, Optional, Type, Union
22
22
 
23
23
  import pydantic
24
24
  from fastapi import HTTPException, Query, Response
@@ -460,7 +460,7 @@ async def append_messages_to_conversation_field_rslug_prefix(
460
460
  kbid: str,
461
461
  rslug: str,
462
462
  field_id: FieldIdString,
463
- messages: list[models.InputMessage],
463
+ messages: List[models.InputMessage],
464
464
  ) -> ResourceFieldAdded:
465
465
  try:
466
466
  field = models.InputConversationField(messages=messages)
@@ -483,7 +483,7 @@ async def append_messages_to_conversation_field_rid_prefix(
483
483
  kbid: str,
484
484
  rid: str,
485
485
  field_id: FieldIdString,
486
- messages: list[models.InputMessage],
486
+ messages: List[models.InputMessage],
487
487
  ) -> ResourceFieldAdded:
488
488
  try:
489
489
  field = models.InputConversationField(messages=messages)
@@ -21,13 +21,14 @@ import dataclasses
21
21
  from datetime import datetime
22
22
  from typing import Optional, Union
23
23
 
24
+ from fastapi import HTTPException
24
25
  from google.protobuf.json_format import MessageToDict
25
26
 
26
27
  import nucliadb_models as models
27
28
  from nucliadb.common import datamanagers
28
29
  from nucliadb.common.maindb.driver import Transaction
29
30
  from nucliadb.common.models_utils import from_proto, to_proto
30
- from nucliadb.ingest.fields.conversation import Conversation
31
+ from nucliadb.ingest.fields.conversation import MAX_CONVERSATION_MESSAGES, Conversation
31
32
  from nucliadb.ingest.orm.resource import Resource as ORMResource
32
33
  from nucliadb.models.internal import processing as processing_models
33
34
  from nucliadb.models.internal.processing import ClassificationLabel, PushConversation, PushPayload
@@ -431,6 +432,14 @@ async def parse_conversation_field(
431
432
  uuid: str,
432
433
  resource_classifications: ResourceClassifications,
433
434
  ) -> None:
435
+ # Make sure that the max number of messages is not exceeded
436
+ current_message_count = await get_current_conversation_message_count(kbid, uuid, key)
437
+ if len(conversation_field.messages) + current_message_count > MAX_CONVERSATION_MESSAGES:
438
+ raise HTTPException(
439
+ status_code=422,
440
+ detail=f"Conversation fields cannot have more than {MAX_CONVERSATION_MESSAGES} messages.",
441
+ )
442
+
434
443
  classif_labels = resource_classifications.for_field(key, resources_pb2.FieldType.CONVERSATION)
435
444
  storage = await get_storage(service_name=SERVICE_NAME)
436
445
  processing = get_processing()
@@ -543,3 +552,15 @@ async def get_stored_resource_classifications(
543
552
  classif = ClassificationLabel(labelset=f_classif.labelset, label=f_classif.label)
544
553
  rc.field_level.setdefault(fid, set()).add(classif)
545
554
  return rc
555
+
556
+
557
+ async def get_current_conversation_message_count(kbid: str, rid: str, field_id: str) -> int:
558
+ async with datamanagers.with_ro_transaction() as txn:
559
+ resource_obj = await datamanagers.resources.get_resource(txn, kbid=kbid, rid=rid)
560
+ if resource_obj is None:
561
+ return 0
562
+ field_obj: Conversation = await resource_obj.get_field(
563
+ field_id, resources_pb2.FieldType.CONVERSATION, load=False
564
+ )
565
+ metadata = await field_obj.get_metadata()
566
+ return metadata.total
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: nucliadb
3
- Version: 6.9.0.post5068
3
+ Version: 6.9.0.post5072
4
4
  Summary: NucliaDB
5
5
  Author-email: Nuclia <nucliadb@nuclia.com>
6
6
  License-Expression: AGPL-3.0-or-later
@@ -19,11 +19,11 @@ Classifier: Programming Language :: Python :: 3.12
19
19
  Classifier: Programming Language :: Python :: 3 :: Only
20
20
  Requires-Python: <4,>=3.9
21
21
  Description-Content-Type: text/markdown
22
- Requires-Dist: nucliadb-telemetry[all]>=6.9.0.post5068
23
- Requires-Dist: nucliadb-utils[cache,fastapi,storages]>=6.9.0.post5068
24
- Requires-Dist: nucliadb-protos>=6.9.0.post5068
25
- Requires-Dist: nucliadb-models>=6.9.0.post5068
26
- Requires-Dist: nidx-protos>=6.9.0.post5068
22
+ Requires-Dist: nucliadb-telemetry[all]>=6.9.0.post5072
23
+ Requires-Dist: nucliadb-utils[cache,fastapi,storages]>=6.9.0.post5072
24
+ Requires-Dist: nucliadb-protos>=6.9.0.post5072
25
+ Requires-Dist: nucliadb-models>=6.9.0.post5072
26
+ Requires-Dist: nidx-protos>=6.9.0.post5072
27
27
  Requires-Dist: nucliadb-admin-assets>=1.0.0.post1224
28
28
  Requires-Dist: nuclia-models>=0.50.0
29
29
  Requires-Dist: uvicorn[standard]
@@ -86,7 +86,7 @@ nucliadb/common/cluster/grpc_node_dummy.py,sha256=JkufazWzMA4KFEU8EBkMbiiDW4C8lL
86
86
  nucliadb/common/cluster/manager.py,sha256=QOHA7trtZVwV5G9IIxM1Y-0P2KE5mEhsXUMPs8vxIg0,12816
87
87
  nucliadb/common/cluster/rebalance.py,sha256=238JxqdSl1_oeJNpKuGBgfVn8WXVmyX5yl2PyHomYX8,8715
88
88
  nucliadb/common/cluster/rollover.py,sha256=swuYNXJ8u5p11PvYaHxVtomiYIPVWVGVsicwTgm24-Q,25862
89
- nucliadb/common/cluster/settings.py,sha256=H-KRSDdJozXLRZjjmDzgjMKm_9p6UBaPuqmTFkdhd_M,2270
89
+ nucliadb/common/cluster/settings.py,sha256=f6Y5K0PGahkedwe5wtkWMnbqwDFJgOOwX_MOIGwH9Dg,2271
90
90
  nucliadb/common/cluster/utils.py,sha256=IfW5PA7Ab26xWUYNOc3yBoksWV1GK4BGhTRo1vnHNKg,4662
91
91
  nucliadb/common/cluster/standalone/__init__.py,sha256=itSI7dtTwFP55YMX4iK7JzdMHS5CQVUiB1XzQu4UBh8,833
92
92
  nucliadb/common/cluster/standalone/utils.py,sha256=af3r-x_GF7A6dwIAhZLR-r-SZQEVxsFrDKeMfUTA6G0,1908
@@ -154,7 +154,7 @@ nucliadb/ingest/consumer/shard_creator.py,sha256=UKIk0yaS_jC_nGQqymn9NGJWzwZEqhI
154
154
  nucliadb/ingest/consumer/utils.py,sha256=jpX8D4lKzuPCpArQLZeX_Zczq3pfen_zAf8sPJfOEZU,2642
155
155
  nucliadb/ingest/fields/__init__.py,sha256=cp15ZcFnHvpcu_5-aK2A4uUyvuZVV_MJn4bIXMa20ks,835
156
156
  nucliadb/ingest/fields/base.py,sha256=D8NzawonF7hivDW9zvQBbV938TKA6e2OCGqV4kS96RU,24405
157
- nucliadb/ingest/fields/conversation.py,sha256=3_MZY_w0zK-9rd6Pb_sPVBUP2YB5twOZSdo_9lCa8KQ,7684
157
+ nucliadb/ingest/fields/conversation.py,sha256=ShdPapTIG7sA05YlG1Dj2CsAwNwibsqRSQrsuZnr8YI,7723
158
158
  nucliadb/ingest/fields/exceptions.py,sha256=sZBk21BSrXFdOdo1qUdCAyD-9YMYakSLdn4_WdIPCIQ,1217
159
159
  nucliadb/ingest/fields/file.py,sha256=1v4jLg3balUua2VmSV8hHkAwPFShTUCOzufZvIUQcQw,4740
160
160
  nucliadb/ingest/fields/generic.py,sha256=elgtqv15aJUq3zY7X_g0bli_2BpcwPArVvzhe54Y4Ig,1547
@@ -360,7 +360,7 @@ nucliadb/writer/api/constants.py,sha256=SCdqGDbEmpdczQdTfbTlpHzVjbLqccPtMQ25MPIF
360
360
  nucliadb/writer/api/utils.py,sha256=wIQHlU8RQiIGVLI72suvyVIKlCU44Unh0Ae0IiN6Qwo,1313
361
361
  nucliadb/writer/api/v1/__init__.py,sha256=akI9A_jloNLb0dU4T5zjfdyvmSAiDeIdjAlzNx74FlU,1128
362
362
  nucliadb/writer/api/v1/export_import.py,sha256=v0sU55TtRSqDzwkDgcwv2uSaqKCuQTtGcMpYoHQYBQA,8192
363
- nucliadb/writer/api/v1/field.py,sha256=aO4GFzadXnMhGlAfvJc5KkObii_z6a8R80yCdvjKEc8,18966
363
+ nucliadb/writer/api/v1/field.py,sha256=qcuniSwR9tR9vn5abpK3rB_olpuUTEj_0LcL_1eAiLw,18972
364
364
  nucliadb/writer/api/v1/knowledgebox.py,sha256=kioqjD3yN-y1cDTgmXAAOwivXHX9NXxwblcSzGqJup0,9533
365
365
  nucliadb/writer/api/v1/learning_config.py,sha256=DTLEzKJ3dHvi8pbZscjElUqCH_ZvLc6WZgvalFqHo10,4450
366
366
  nucliadb/writer/api/v1/resource.py,sha256=IfcT6HXnR5sC5wSnQSuKmFzEWcLTh7OzZEAV4hYmXnA,20442
@@ -373,7 +373,7 @@ nucliadb/writer/api/v1/vectorsets.py,sha256=F3iMViL5G95_Tns4aO2SOA0DwAzxK2_P8MXx
373
373
  nucliadb/writer/resource/__init__.py,sha256=cp15ZcFnHvpcu_5-aK2A4uUyvuZVV_MJn4bIXMa20ks,835
374
374
  nucliadb/writer/resource/audit.py,sha256=FvxMZPzrNHtd31HgpZEvxzwAkbxJTZRhPLqRYYJi3tA,1426
375
375
  nucliadb/writer/resource/basic.py,sha256=44GK8M9EEVoAUfGiabdLrrpENqeFwNn7qwxF2AHhQGg,10504
376
- nucliadb/writer/resource/field.py,sha256=1fHm2N-3LcgQDE3BUDiJ0ToCiwY1Di7UbA6fcJs8BIk,21193
376
+ nucliadb/writer/resource/field.py,sha256=eM2KFxhcG3u6-ldniZDSYqGzhJ5bpWgIQBGXXFwskqw,22195
377
377
  nucliadb/writer/resource/origin.py,sha256=pvhUDdU0mlWPUcpoQi4LDUJaRtfjzVVrA8XcGVI_N8k,2021
378
378
  nucliadb/writer/tus/__init__.py,sha256=Kera0BtxoDX0ngPftXiMjNgjrhtQ3l2XFc5nJqSBOJY,5498
379
379
  nucliadb/writer/tus/azure.py,sha256=yxoRi4PhGDikTqVK3PiuVyguy8H9DOS66JpZCY4hpUY,4177
@@ -384,8 +384,8 @@ nucliadb/writer/tus/local.py,sha256=7jYa_w9b-N90jWgN2sQKkNcomqn6JMVBOVeDOVYJHto,
384
384
  nucliadb/writer/tus/s3.py,sha256=vu1BGg4VqJ_x2P1u2BxqPKlSfw5orT_a3R-Ln5oPUpU,8483
385
385
  nucliadb/writer/tus/storage.py,sha256=ToqwjoYnjI4oIcwzkhha_MPxi-k4Jk3Lt55zRwaC1SM,2903
386
386
  nucliadb/writer/tus/utils.py,sha256=MSdVbRsRSZVdkaum69_0wku7X3p5wlZf4nr6E0GMKbw,2556
387
- nucliadb-6.9.0.post5068.dist-info/METADATA,sha256=eKVcsDkBBGIK56YqrJfJepBfiOvBFf9l40ztFBAR-pA,4158
388
- nucliadb-6.9.0.post5068.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
389
- nucliadb-6.9.0.post5068.dist-info/entry_points.txt,sha256=XqGfgFDuY3zXQc8ewXM2TRVjTModIq851zOsgrmaXx4,1268
390
- nucliadb-6.9.0.post5068.dist-info/top_level.txt,sha256=hwYhTVnX7jkQ9gJCkVrbqEG1M4lT2F_iPQND1fCzF80,20
391
- nucliadb-6.9.0.post5068.dist-info/RECORD,,
387
+ nucliadb-6.9.0.post5072.dist-info/METADATA,sha256=IuymQS1C87M_L3u-9Bpy-Wf76fYOScOwTD18Dr5srAQ,4158
388
+ nucliadb-6.9.0.post5072.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
389
+ nucliadb-6.9.0.post5072.dist-info/entry_points.txt,sha256=XqGfgFDuY3zXQc8ewXM2TRVjTModIq851zOsgrmaXx4,1268
390
+ nucliadb-6.9.0.post5072.dist-info/top_level.txt,sha256=hwYhTVnX7jkQ9gJCkVrbqEG1M4lT2F_iPQND1fCzF80,20
391
+ nucliadb-6.9.0.post5072.dist-info/RECORD,,