Skip to content

Commit 0ebb7b0

Browse files
authored
fix: explicit multipart upload config in store files APIs (#22)
1 parent 46aea64 commit 0ebb7b0

2 files changed

Lines changed: 40 additions & 12 deletions

File tree

src/mixedbread/resources/parsing/jobs.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
from ...lib import polling
1212
from ..._types import Body, Omit, Query, Headers, NotGiven, FileTypes, omit, not_given
13+
from ...lib.multipart_upload import MultipartUploadOptions
1314
from ..._utils import maybe_transform, async_maybe_transform
1415
from ..._compat import cached_property
1516
from ..._resource import SyncAPIResource, AsyncAPIResource
@@ -403,13 +404,14 @@ def upload(
403404
]
404405
| NotGiven = not_given,
405406
return_format: Literal["html", "markdown", "plain"] | NotGiven = not_given,
407+
multipart_upload: bool | MultipartUploadOptions | None = None,
406408
**kwargs: Any,
407409
) -> ParsingJob:
408410
"""Upload a file to the `files` API and then create a parsing job for it.
409411
Note the job will be asynchronously processed (you can use the alternative
410412
polling helper method to wait for processing to complete).
411413
"""
412-
file_obj = self._client.files.create(file=file, **kwargs)
414+
file_obj = self._client.files.create(file=file, multipart_upload=multipart_upload, **kwargs)
413415
return self.create(
414416
file_id=file_obj.id,
415417
chunking_strategy=chunking_strategy,
@@ -442,11 +444,12 @@ def upload_and_poll(
442444
]
443445
| NotGiven = not_given,
444446
return_format: Literal["html", "markdown", "plain"] | NotGiven = not_given,
447+
multipart_upload: bool | MultipartUploadOptions | None = None,
445448
poll_interval_ms: int | NotGiven = not_given,
446449
**kwargs: Any,
447450
) -> ParsingJob:
448451
"""Upload a file and create a parsing job, then poll until processing is complete."""
449-
file_obj = self._client.files.create(file=file, **kwargs)
452+
file_obj = self._client.files.create(file=file, multipart_upload=multipart_upload, **kwargs)
450453
return self.create_and_poll(
451454
file_id=file_obj.id,
452455
chunking_strategy=chunking_strategy,
@@ -827,13 +830,14 @@ async def upload(
827830
]
828831
| NotGiven = not_given,
829832
return_format: Literal["html", "markdown", "plain"] | NotGiven = not_given,
833+
multipart_upload: bool | MultipartUploadOptions | None = None,
830834
**kwargs: Any,
831835
) -> ParsingJob:
832836
"""Upload a file to the `files` API and then create a parsing job for it.
833837
Note the job will be asynchronously processed (you can use the alternative
834838
polling helper method to wait for processing to complete).
835839
"""
836-
file_obj = await self._client.files.create(file=file, **kwargs)
840+
file_obj = await self._client.files.create(file=file, multipart_upload=multipart_upload, **kwargs)
837841
return await self.create(
838842
file_id=file_obj.id,
839843
chunking_strategy=chunking_strategy,
@@ -866,11 +870,12 @@ async def upload_and_poll(
866870
]
867871
| NotGiven = not_given,
868872
return_format: Literal["html", "markdown", "plain"] | NotGiven = not_given,
873+
multipart_upload: bool | MultipartUploadOptions | None = None,
869874
poll_interval_ms: int | NotGiven = not_given,
870875
**kwargs: Any,
871876
) -> ParsingJob:
872877
"""Upload a file and create a parsing job, then poll until processing is complete."""
873-
file_obj = await self._client.files.create(file=file, **kwargs)
878+
file_obj = await self._client.files.create(file=file, multipart_upload=multipart_upload, **kwargs)
874879
return await self.create_and_poll(
875880
file_id=file_obj.id,
876881
chunking_strategy=chunking_strategy,

src/mixedbread/resources/stores/files.py

Lines changed: 31 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
from ...lib import polling
1111
from ..._types import Body, Omit, Query, Headers, NotGiven, FileTypes, SequenceNotStr, omit, not_given
12+
from ...lib.multipart_upload import MultipartUploadOptions
1213
from ..._utils import maybe_transform, async_maybe_transform
1314
from ..._compat import cached_property
1415
from ..._resource import SyncAPIResource, AsyncAPIResource
@@ -495,6 +496,7 @@ def upload(
495496
external_id: Optional[str] | Omit = omit,
496497
overwrite: bool | Omit = omit,
497498
experimental: file_create_params.Experimental | Omit = omit,
499+
multipart_upload: bool | MultipartUploadOptions | None = None,
498500
**kwargs: Any,
499501
) -> StoreFile:
500502
"""Upload a file to the `files` API and then attach it to the given store.
@@ -509,14 +511,19 @@ def upload(
509511
external_id: External identifier for this file in the store
510512
overwrite: If true, overwrite an existing file with the same external_id
511513
experimental: Configuration for a file.
514+
multipart_upload: Controls multipart upload behavior for the file upload.
515+
None (default) auto-detects based on file size.
516+
True forces multipart with default options.
517+
False disables multipart.
518+
MultipartUploadOptions for custom settings.
512519
extra_headers: Send extra headers
513520
extra_query: Add additional query parameters to the request
514521
extra_body: Add additional JSON properties to the request
515522
timeout: Override the client-level default timeout for this request, in seconds
516523
Returns:
517524
The file object once it reaches a terminal state
518525
"""
519-
file_obj = self._client.files.create(file=file, **kwargs)
526+
file_obj = self._client.files.create(file=file, multipart_upload=multipart_upload, **kwargs)
520527
return self.create(
521528
store_identifier=store_identifier,
522529
file_id=file_obj.id,
@@ -538,12 +545,13 @@ def upload_and_poll(
538545
external_id: Optional[str] | Omit = omit,
539546
overwrite: bool | Omit = omit,
540547
experimental: file_create_params.Experimental | Omit = omit,
548+
multipart_upload: bool | MultipartUploadOptions | None = None,
541549
poll_interval_ms: int | NotGiven = not_given,
542550
poll_timeout_ms: float | NotGiven = not_given,
543551
**kwargs: Any,
544552
) -> StoreFile:
545553
"""Add a file to a store and poll until processing is complete.
546-
554+
547555
Args:
548556
store_identifier: The ID or name of the store
549557
file: The file to upload
@@ -552,12 +560,17 @@ def upload_and_poll(
552560
external_id: External identifier for this file in the store
553561
overwrite: If true, overwrite an existing file with the same external_id
554562
experimental: Configuration for a file.
563+
multipart_upload: Controls multipart upload behavior for the file upload.
564+
None (default) auto-detects based on file size.
565+
True forces multipart with default options.
566+
False disables multipart.
567+
MultipartUploadOptions for custom settings.
555568
poll_interval_ms: The interval between polls in milliseconds
556569
poll_timeout_ms: The maximum time to poll for in milliseconds
557570
Returns:
558571
The file object once it reaches a terminal state
559572
"""
560-
file_obj = self._client.files.create(file=file, **kwargs)
573+
file_obj = self._client.files.create(file=file, multipart_upload=multipart_upload, **kwargs)
561574
return self.create_and_poll(
562575
store_identifier=store_identifier,
563576
file_id=file_obj.id,
@@ -1038,6 +1051,7 @@ async def upload(
10381051
external_id: Optional[str] | Omit = omit,
10391052
overwrite: bool | Omit = omit,
10401053
experimental: file_create_params.Experimental | Omit = omit,
1054+
multipart_upload: bool | MultipartUploadOptions | None = None,
10411055
**kwargs: Any,
10421056
) -> StoreFile:
10431057
"""Upload a file to the `files` API and then attach it to the given vector store.
@@ -1052,12 +1066,15 @@ async def upload(
10521066
external_id: External identifier for this file in the store
10531067
overwrite: If true, overwrite an existing file with the same external_id
10541068
experimental: Configuration for a file.
1055-
poll_interval_ms: The interval between polls in milliseconds
1056-
poll_timeout_ms: The maximum time to poll for in milliseconds
1069+
multipart_upload: Controls multipart upload behavior for the file upload.
1070+
None (default) auto-detects based on file size.
1071+
True forces multipart with default options.
1072+
False disables multipart.
1073+
MultipartUploadOptions for custom settings.
10571074
Returns:
10581075
The file object once it reaches a terminal state
10591076
"""
1060-
file_obj = await self._client.files.create(file=file, **kwargs)
1077+
file_obj = await self._client.files.create(file=file, multipart_upload=multipart_upload, **kwargs)
10611078
return await self.create(
10621079
store_identifier=store_identifier,
10631080
file_id=file_obj.id,
@@ -1079,12 +1096,13 @@ async def upload_and_poll(
10791096
external_id: Optional[str] | Omit = omit,
10801097
overwrite: bool | Omit = omit,
10811098
experimental: file_create_params.Experimental | Omit = omit,
1099+
multipart_upload: bool | MultipartUploadOptions | None = None,
10821100
poll_interval_ms: int | NotGiven = not_given,
10831101
poll_timeout_ms: float | NotGiven = not_given,
10841102
**kwargs: Any,
10851103
) -> StoreFile:
10861104
"""Add a file to a store and poll until processing is complete.
1087-
1105+
10881106
Args:
10891107
store_identifier: The ID or name of the store
10901108
file: The file to upload
@@ -1093,12 +1111,17 @@ async def upload_and_poll(
10931111
external_id: External identifier for this file in the store
10941112
overwrite: If true, overwrite an existing file with the same external_id
10951113
experimental: Configuration for a file.
1114+
multipart_upload: Controls multipart upload behavior for the file upload.
1115+
None (default) auto-detects based on file size.
1116+
True forces multipart with default options.
1117+
False disables multipart.
1118+
MultipartUploadOptions for custom settings.
10961119
poll_interval_ms: The interval between polls in milliseconds
10971120
poll_timeout_ms: The maximum time to poll for in milliseconds
10981121
Returns:
10991122
The file object once it reaches a terminal state
11001123
"""
1101-
file_obj = await self._client.files.create(file=file, **kwargs)
1124+
file_obj = await self._client.files.create(file=file, multipart_upload=multipart_upload, **kwargs)
11021125
return await self.create_and_poll(
11031126
store_identifier=store_identifier,
11041127
file_id=file_obj.id,

0 commit comments

Comments
 (0)