Skip to content

Commit e82cd85

Browse files
author
Stainless Bot
committed
feat(vector store): improve chunking strategy type names (#1690)
1 parent b2f58cb commit e82cd85

20 files changed

+201
-321
lines changed

.stats.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
configured_endpoints: 68
2-
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/openai-1dbac0e95bdb5a89a0dd3d93265475a378214551b7d8c22862928e0d87ace94b.yml
2+
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/openai-85a85e0c08de456441431c0ae4e9c078cc8f9748c29430b9a9058340db6389ee.yml

api.md

+11-1
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,17 @@ Methods:
222222
Types:
223223

224224
```python
225-
from openai.types.beta import VectorStore, VectorStoreDeleted
225+
from openai.types.beta import (
226+
AutoFileChunkingStrategyParam,
227+
FileChunkingStrategy,
228+
FileChunkingStrategyParam,
229+
OtherFileChunkingStrategyObject,
230+
StaticFileChunkingStrategy,
231+
StaticFileChunkingStrategyObject,
232+
StaticFileChunkingStrategyParam,
233+
VectorStore,
234+
VectorStoreDeleted,
235+
)
226236
```
227237

228238
Methods:

src/openai/resources/beta/vector_stores/file_batches.py

+11-12
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,10 @@
2222
from ...._resource import SyncAPIResource, AsyncAPIResource
2323
from ...._response import to_streamed_response_wrapper, async_to_streamed_response_wrapper
2424
from ....pagination import SyncCursorPage, AsyncCursorPage
25-
from ...._base_client import (
26-
AsyncPaginator,
27-
make_request_options,
28-
)
25+
from ....types.beta import FileChunkingStrategyParam
26+
from ...._base_client import AsyncPaginator, make_request_options
2927
from ....types.beta.vector_stores import file_batch_create_params, file_batch_list_files_params
28+
from ....types.beta.file_chunking_strategy_param import FileChunkingStrategyParam
3029
from ....types.beta.vector_stores.vector_store_file import VectorStoreFile
3130
from ....types.beta.vector_stores.vector_store_file_batch import VectorStoreFileBatch
3231

@@ -47,7 +46,7 @@ def create(
4746
vector_store_id: str,
4847
*,
4948
file_ids: List[str],
50-
chunking_strategy: file_batch_create_params.ChunkingStrategy | NotGiven = NOT_GIVEN,
49+
chunking_strategy: FileChunkingStrategyParam | NotGiven = NOT_GIVEN,
5150
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
5251
# The extra values given here take precedence over values defined on the client or passed to this method.
5352
extra_headers: Headers | None = None,
@@ -64,7 +63,7 @@ def create(
6463
files.
6564
6665
chunking_strategy: The chunking strategy used to chunk the file(s). If not set, will use the `auto`
67-
strategy.
66+
strategy. Only applicable if `file_ids` is non-empty.
6867
6968
extra_headers: Send extra headers
7069
@@ -174,7 +173,7 @@ def create_and_poll(
174173
*,
175174
file_ids: List[str],
176175
poll_interval_ms: int | NotGiven = NOT_GIVEN,
177-
chunking_strategy: file_batch_create_params.ChunkingStrategy | NotGiven = NOT_GIVEN,
176+
chunking_strategy: FileChunkingStrategyParam | NotGiven = NOT_GIVEN,
178177
) -> VectorStoreFileBatch:
179178
"""Create a vector store batch and poll until all files have been processed."""
180179
batch = self.create(
@@ -308,7 +307,7 @@ def upload_and_poll(
308307
max_concurrency: int = 5,
309308
file_ids: List[str] = [],
310309
poll_interval_ms: int | NotGiven = NOT_GIVEN,
311-
chunking_strategy: file_batch_create_params.ChunkingStrategy | NotGiven = NOT_GIVEN,
310+
chunking_strategy: FileChunkingStrategyParam | NotGiven = NOT_GIVEN,
312311
) -> VectorStoreFileBatch:
313312
"""Uploads the given files concurrently and then creates a vector store file batch.
314313
@@ -365,7 +364,7 @@ async def create(
365364
vector_store_id: str,
366365
*,
367366
file_ids: List[str],
368-
chunking_strategy: file_batch_create_params.ChunkingStrategy | NotGiven = NOT_GIVEN,
367+
chunking_strategy: FileChunkingStrategyParam | NotGiven = NOT_GIVEN,
369368
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
370369
# The extra values given here take precedence over values defined on the client or passed to this method.
371370
extra_headers: Headers | None = None,
@@ -382,7 +381,7 @@ async def create(
382381
files.
383382
384383
chunking_strategy: The chunking strategy used to chunk the file(s). If not set, will use the `auto`
385-
strategy.
384+
strategy. Only applicable if `file_ids` is non-empty.
386385
387386
extra_headers: Send extra headers
388387
@@ -492,7 +491,7 @@ async def create_and_poll(
492491
*,
493492
file_ids: List[str],
494493
poll_interval_ms: int | NotGiven = NOT_GIVEN,
495-
chunking_strategy: file_batch_create_params.ChunkingStrategy | NotGiven = NOT_GIVEN,
494+
chunking_strategy: FileChunkingStrategyParam | NotGiven = NOT_GIVEN,
496495
) -> VectorStoreFileBatch:
497496
"""Create a vector store batch and poll until all files have been processed."""
498497
batch = await self.create(
@@ -626,7 +625,7 @@ async def upload_and_poll(
626625
max_concurrency: int = 5,
627626
file_ids: List[str] = [],
628627
poll_interval_ms: int | NotGiven = NOT_GIVEN,
629-
chunking_strategy: file_batch_create_params.ChunkingStrategy | NotGiven = NOT_GIVEN,
628+
chunking_strategy: FileChunkingStrategyParam | NotGiven = NOT_GIVEN,
630629
) -> VectorStoreFileBatch:
631630
"""Uploads the given files concurrently and then creates a vector store file batch.
632631

src/openai/resources/beta/vector_stores/files.py

+13-14
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,10 @@
1818
from ...._resource import SyncAPIResource, AsyncAPIResource
1919
from ...._response import to_streamed_response_wrapper, async_to_streamed_response_wrapper
2020
from ....pagination import SyncCursorPage, AsyncCursorPage
21-
from ...._base_client import (
22-
AsyncPaginator,
23-
make_request_options,
24-
)
21+
from ....types.beta import FileChunkingStrategyParam
22+
from ...._base_client import AsyncPaginator, make_request_options
2523
from ....types.beta.vector_stores import file_list_params, file_create_params
24+
from ....types.beta.file_chunking_strategy_param import FileChunkingStrategyParam
2625
from ....types.beta.vector_stores.vector_store_file import VectorStoreFile
2726
from ....types.beta.vector_stores.vector_store_file_deleted import VectorStoreFileDeleted
2827

@@ -43,7 +42,7 @@ def create(
4342
vector_store_id: str,
4443
*,
4544
file_id: str,
46-
chunking_strategy: file_create_params.ChunkingStrategy | NotGiven = NOT_GIVEN,
45+
chunking_strategy: FileChunkingStrategyParam | NotGiven = NOT_GIVEN,
4746
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
4847
# The extra values given here take precedence over values defined on the client or passed to this method.
4948
extra_headers: Headers | None = None,
@@ -62,7 +61,7 @@ def create(
6261
files.
6362
6463
chunking_strategy: The chunking strategy used to chunk the file(s). If not set, will use the `auto`
65-
strategy.
64+
strategy. Only applicable if `file_ids` is non-empty.
6665
6766
extra_headers: Send extra headers
6867
@@ -245,7 +244,7 @@ def create_and_poll(
245244
*,
246245
vector_store_id: str,
247246
poll_interval_ms: int | NotGiven = NOT_GIVEN,
248-
chunking_strategy: file_create_params.ChunkingStrategy | NotGiven = NOT_GIVEN,
247+
chunking_strategy: FileChunkingStrategyParam | NotGiven = NOT_GIVEN,
249248
) -> VectorStoreFile:
250249
"""Attach a file to the given vector store and wait for it to be processed."""
251250
self.create(vector_store_id=vector_store_id, file_id=file_id, chunking_strategy=chunking_strategy)
@@ -302,7 +301,7 @@ def upload(
302301
*,
303302
vector_store_id: str,
304303
file: FileTypes,
305-
chunking_strategy: file_create_params.ChunkingStrategy | NotGiven = NOT_GIVEN,
304+
chunking_strategy: FileChunkingStrategyParam | NotGiven = NOT_GIVEN,
306305
) -> VectorStoreFile:
307306
"""Upload a file to the `files` API and then attach it to the given vector store.
308307
@@ -318,7 +317,7 @@ def upload_and_poll(
318317
vector_store_id: str,
319318
file: FileTypes,
320319
poll_interval_ms: int | NotGiven = NOT_GIVEN,
321-
chunking_strategy: file_create_params.ChunkingStrategy | NotGiven = NOT_GIVEN,
320+
chunking_strategy: FileChunkingStrategyParam | NotGiven = NOT_GIVEN,
322321
) -> VectorStoreFile:
323322
"""Add a file to a vector store and poll until processing is complete."""
324323
file_obj = self._client.files.create(file=file, purpose="assistants")
@@ -344,7 +343,7 @@ async def create(
344343
vector_store_id: str,
345344
*,
346345
file_id: str,
347-
chunking_strategy: file_create_params.ChunkingStrategy | NotGiven = NOT_GIVEN,
346+
chunking_strategy: FileChunkingStrategyParam | NotGiven = NOT_GIVEN,
348347
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
349348
# The extra values given here take precedence over values defined on the client or passed to this method.
350349
extra_headers: Headers | None = None,
@@ -363,7 +362,7 @@ async def create(
363362
files.
364363
365364
chunking_strategy: The chunking strategy used to chunk the file(s). If not set, will use the `auto`
366-
strategy.
365+
strategy. Only applicable if `file_ids` is non-empty.
367366
368367
extra_headers: Send extra headers
369368
@@ -546,7 +545,7 @@ async def create_and_poll(
546545
*,
547546
vector_store_id: str,
548547
poll_interval_ms: int | NotGiven = NOT_GIVEN,
549-
chunking_strategy: file_create_params.ChunkingStrategy | NotGiven = NOT_GIVEN,
548+
chunking_strategy: FileChunkingStrategyParam | NotGiven = NOT_GIVEN,
550549
) -> VectorStoreFile:
551550
"""Attach a file to the given vector store and wait for it to be processed."""
552551
await self.create(vector_store_id=vector_store_id, file_id=file_id, chunking_strategy=chunking_strategy)
@@ -603,7 +602,7 @@ async def upload(
603602
*,
604603
vector_store_id: str,
605604
file: FileTypes,
606-
chunking_strategy: file_create_params.ChunkingStrategy | NotGiven = NOT_GIVEN,
605+
chunking_strategy: FileChunkingStrategyParam | NotGiven = NOT_GIVEN,
607606
) -> VectorStoreFile:
608607
"""Upload a file to the `files` API and then attach it to the given vector store.
609608
@@ -621,7 +620,7 @@ async def upload_and_poll(
621620
vector_store_id: str,
622621
file: FileTypes,
623622
poll_interval_ms: int | NotGiven = NOT_GIVEN,
624-
chunking_strategy: file_create_params.ChunkingStrategy | NotGiven = NOT_GIVEN,
623+
chunking_strategy: FileChunkingStrategyParam | NotGiven = NOT_GIVEN,
625624
) -> VectorStoreFile:
626625
"""Add a file to a vector store and poll until processing is complete."""
627626
file_obj = await self._client.files.create(file=file, purpose="assistants")

src/openai/resources/beta/vector_stores/vector_stores.py

+9-6
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,16 @@
3333
AsyncFileBatchesWithStreamingResponse,
3434
)
3535
from ....pagination import SyncCursorPage, AsyncCursorPage
36-
from ....types.beta import vector_store_list_params, vector_store_create_params, vector_store_update_params
37-
from ...._base_client import (
38-
AsyncPaginator,
39-
make_request_options,
36+
from ....types.beta import (
37+
FileChunkingStrategyParam,
38+
vector_store_list_params,
39+
vector_store_create_params,
40+
vector_store_update_params,
4041
)
42+
from ...._base_client import AsyncPaginator, make_request_options
4143
from ....types.beta.vector_store import VectorStore
4244
from ....types.beta.vector_store_deleted import VectorStoreDeleted
45+
from ....types.beta.file_chunking_strategy_param import FileChunkingStrategyParam
4346

4447
__all__ = ["VectorStores", "AsyncVectorStores"]
4548

@@ -64,7 +67,7 @@ def with_streaming_response(self) -> VectorStoresWithStreamingResponse:
6467
def create(
6568
self,
6669
*,
67-
chunking_strategy: vector_store_create_params.ChunkingStrategy | NotGiven = NOT_GIVEN,
70+
chunking_strategy: FileChunkingStrategyParam | NotGiven = NOT_GIVEN,
6871
expires_after: vector_store_create_params.ExpiresAfter | NotGiven = NOT_GIVEN,
6972
file_ids: List[str] | NotGiven = NOT_GIVEN,
7073
metadata: Optional[object] | NotGiven = NOT_GIVEN,
@@ -331,7 +334,7 @@ def with_streaming_response(self) -> AsyncVectorStoresWithStreamingResponse:
331334
async def create(
332335
self,
333336
*,
334-
chunking_strategy: vector_store_create_params.ChunkingStrategy | NotGiven = NOT_GIVEN,
337+
chunking_strategy: FileChunkingStrategyParam | NotGiven = NOT_GIVEN,
335338
expires_after: vector_store_create_params.ExpiresAfter | NotGiven = NOT_GIVEN,
336339
file_ids: List[str] | NotGiven = NOT_GIVEN,
337340
metadata: Optional[object] | NotGiven = NOT_GIVEN,

src/openai/types/beta/__init__.py

+7
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
from .assistant_tool_choice import AssistantToolChoice as AssistantToolChoice
2020
from .code_interpreter_tool import CodeInterpreterTool as CodeInterpreterTool
2121
from .assistant_stream_event import AssistantStreamEvent as AssistantStreamEvent
22+
from .file_chunking_strategy import FileChunkingStrategy as FileChunkingStrategy
2223
from .file_search_tool_param import FileSearchToolParam as FileSearchToolParam
2324
from .assistant_create_params import AssistantCreateParams as AssistantCreateParams
2425
from .assistant_update_params import AssistantUpdateParams as AssistantUpdateParams
@@ -28,11 +29,17 @@
2829
from .assistant_tool_choice_param import AssistantToolChoiceParam as AssistantToolChoiceParam
2930
from .code_interpreter_tool_param import CodeInterpreterToolParam as CodeInterpreterToolParam
3031
from .assistant_tool_choice_option import AssistantToolChoiceOption as AssistantToolChoiceOption
32+
from .file_chunking_strategy_param import FileChunkingStrategyParam as FileChunkingStrategyParam
3133
from .thread_create_and_run_params import ThreadCreateAndRunParams as ThreadCreateAndRunParams
34+
from .static_file_chunking_strategy import StaticFileChunkingStrategy as StaticFileChunkingStrategy
3235
from .assistant_tool_choice_function import AssistantToolChoiceFunction as AssistantToolChoiceFunction
3336
from .assistant_response_format_option import AssistantResponseFormatOption as AssistantResponseFormatOption
37+
from .auto_file_chunking_strategy_param import AutoFileChunkingStrategyParam as AutoFileChunkingStrategyParam
3438
from .assistant_tool_choice_option_param import AssistantToolChoiceOptionParam as AssistantToolChoiceOptionParam
39+
from .other_file_chunking_strategy_object import OtherFileChunkingStrategyObject as OtherFileChunkingStrategyObject
40+
from .static_file_chunking_strategy_param import StaticFileChunkingStrategyParam as StaticFileChunkingStrategyParam
3541
from .assistant_tool_choice_function_param import AssistantToolChoiceFunctionParam as AssistantToolChoiceFunctionParam
42+
from .static_file_chunking_strategy_object import StaticFileChunkingStrategyObject as StaticFileChunkingStrategyObject
3643
from .assistant_response_format_option_param import (
3744
AssistantResponseFormatOptionParam as AssistantResponseFormatOptionParam,
3845
)

src/openai/types/beta/assistant_create_params.py

+5-39
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@
33
from __future__ import annotations
44

55
from typing import List, Union, Iterable, Optional
6-
from typing_extensions import Literal, Required, TypeAlias, TypedDict
6+
from typing_extensions import Required, TypedDict
77

88
from ..chat_model import ChatModel
99
from .assistant_tool_param import AssistantToolParam
10+
from .file_chunking_strategy_param import FileChunkingStrategyParam
1011
from .assistant_response_format_option_param import AssistantResponseFormatOptionParam
1112

1213
__all__ = [
@@ -15,10 +16,6 @@
1516
"ToolResourcesCodeInterpreter",
1617
"ToolResourcesFileSearch",
1718
"ToolResourcesFileSearchVectorStore",
18-
"ToolResourcesFileSearchVectorStoreChunkingStrategy",
19-
"ToolResourcesFileSearchVectorStoreChunkingStrategyAuto",
20-
"ToolResourcesFileSearchVectorStoreChunkingStrategyStatic",
21-
"ToolResourcesFileSearchVectorStoreChunkingStrategyStaticStatic",
2219
]
2320

2421

@@ -118,43 +115,12 @@ class ToolResourcesCodeInterpreter(TypedDict, total=False):
118115
"""
119116

120117

121-
class ToolResourcesFileSearchVectorStoreChunkingStrategyAuto(TypedDict, total=False):
122-
type: Required[Literal["auto"]]
123-
"""Always `auto`."""
124-
125-
126-
class ToolResourcesFileSearchVectorStoreChunkingStrategyStaticStatic(TypedDict, total=False):
127-
chunk_overlap_tokens: Required[int]
128-
"""The number of tokens that overlap between chunks. The default value is `400`.
129-
130-
Note that the overlap must not exceed half of `max_chunk_size_tokens`.
131-
"""
132-
133-
max_chunk_size_tokens: Required[int]
134-
"""The maximum number of tokens in each chunk.
135-
136-
The default value is `800`. The minimum value is `100` and the maximum value is
137-
`4096`.
138-
"""
139-
140-
141-
class ToolResourcesFileSearchVectorStoreChunkingStrategyStatic(TypedDict, total=False):
142-
static: Required[ToolResourcesFileSearchVectorStoreChunkingStrategyStaticStatic]
143-
144-
type: Required[Literal["static"]]
145-
"""Always `static`."""
146-
147-
148-
ToolResourcesFileSearchVectorStoreChunkingStrategy: TypeAlias = Union[
149-
ToolResourcesFileSearchVectorStoreChunkingStrategyAuto, ToolResourcesFileSearchVectorStoreChunkingStrategyStatic
150-
]
151-
152-
153118
class ToolResourcesFileSearchVectorStore(TypedDict, total=False):
154-
chunking_strategy: ToolResourcesFileSearchVectorStoreChunkingStrategy
119+
chunking_strategy: FileChunkingStrategyParam
155120
"""The chunking strategy used to chunk the file(s).
156121
157-
If not set, will use the `auto` strategy.
122+
If not set, will use the `auto` strategy. Only applicable if `file_ids` is
123+
non-empty.
158124
"""
159125

160126
file_ids: List[str]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2+
3+
from __future__ import annotations
4+
5+
from typing_extensions import Literal, Required, TypedDict
6+
7+
__all__ = ["AutoFileChunkingStrategyParam"]
8+
9+
10+
class AutoFileChunkingStrategyParam(TypedDict, total=False):
11+
type: Required[Literal["auto"]]
12+
"""Always `auto`."""
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2+
3+
from typing import Union
4+
from typing_extensions import Annotated, TypeAlias
5+
6+
from ..._utils import PropertyInfo
7+
from .other_file_chunking_strategy_object import OtherFileChunkingStrategyObject
8+
from .static_file_chunking_strategy_object import StaticFileChunkingStrategyObject
9+
10+
__all__ = ["FileChunkingStrategy"]
11+
12+
FileChunkingStrategy: TypeAlias = Annotated[
13+
Union[StaticFileChunkingStrategyObject, OtherFileChunkingStrategyObject], PropertyInfo(discriminator="type")
14+
]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2+
3+
from __future__ import annotations
4+
5+
from typing import Union
6+
from typing_extensions import TypeAlias
7+
8+
from .auto_file_chunking_strategy_param import AutoFileChunkingStrategyParam
9+
from .static_file_chunking_strategy_param import StaticFileChunkingStrategyParam
10+
11+
__all__ = ["FileChunkingStrategyParam"]
12+
13+
FileChunkingStrategyParam: TypeAlias = Union[AutoFileChunkingStrategyParam, StaticFileChunkingStrategyParam]

0 commit comments

Comments
 (0)