main
1# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
3from __future__ import annotations
4
5from typing import Union, Optional
6from typing_extensions import Literal
7
8import httpx
9
10from ... import _legacy_response
11from .files import (
12 Files,
13 AsyncFiles,
14 FilesWithRawResponse,
15 AsyncFilesWithRawResponse,
16 FilesWithStreamingResponse,
17 AsyncFilesWithStreamingResponse,
18)
19from ...types import (
20 FileChunkingStrategyParam,
21 vector_store_list_params,
22 vector_store_create_params,
23 vector_store_search_params,
24 vector_store_update_params,
25)
26from ..._types import Body, Omit, Query, Headers, NotGiven, SequenceNotStr, omit, not_given
27from ..._utils import maybe_transform, async_maybe_transform
28from ..._compat import cached_property
29from ..._resource import SyncAPIResource, AsyncAPIResource
30from ..._response import to_streamed_response_wrapper, async_to_streamed_response_wrapper
31from ...pagination import SyncPage, AsyncPage, SyncCursorPage, AsyncCursorPage
32from .file_batches import (
33 FileBatches,
34 AsyncFileBatches,
35 FileBatchesWithRawResponse,
36 AsyncFileBatchesWithRawResponse,
37 FileBatchesWithStreamingResponse,
38 AsyncFileBatchesWithStreamingResponse,
39)
40from ..._base_client import AsyncPaginator, make_request_options
41from ...types.vector_store import VectorStore
42from ...types.vector_store_deleted import VectorStoreDeleted
43from ...types.shared_params.metadata import Metadata
44from ...types.file_chunking_strategy_param import FileChunkingStrategyParam
45from ...types.vector_store_search_response import VectorStoreSearchResponse
46
47__all__ = ["VectorStores", "AsyncVectorStores"]
48
49
50class VectorStores(SyncAPIResource):
51 @cached_property
52 def files(self) -> Files:
53 return Files(self._client)
54
55 @cached_property
56 def file_batches(self) -> FileBatches:
57 return FileBatches(self._client)
58
59 @cached_property
60 def with_raw_response(self) -> VectorStoresWithRawResponse:
61 """
62 This property can be used as a prefix for any HTTP method call to return
63 the raw response object instead of the parsed content.
64
65 For more information, see https://www.github.com/openai/openai-python#accessing-raw-response-data-eg-headers
66 """
67 return VectorStoresWithRawResponse(self)
68
69 @cached_property
70 def with_streaming_response(self) -> VectorStoresWithStreamingResponse:
71 """
72 An alternative to `.with_raw_response` that doesn't eagerly read the response body.
73
74 For more information, see https://www.github.com/openai/openai-python#with_streaming_response
75 """
76 return VectorStoresWithStreamingResponse(self)
77
78 def create(
79 self,
80 *,
81 chunking_strategy: FileChunkingStrategyParam | Omit = omit,
82 description: str | Omit = omit,
83 expires_after: vector_store_create_params.ExpiresAfter | Omit = omit,
84 file_ids: SequenceNotStr[str] | Omit = omit,
85 metadata: Optional[Metadata] | Omit = omit,
86 name: str | Omit = omit,
87 # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
88 # The extra values given here take precedence over values defined on the client or passed to this method.
89 extra_headers: Headers | None = None,
90 extra_query: Query | None = None,
91 extra_body: Body | None = None,
92 timeout: float | httpx.Timeout | None | NotGiven = not_given,
93 ) -> VectorStore:
94 """
95 Create a vector store.
96
97 Args:
98 chunking_strategy: The chunking strategy used to chunk the file(s). If not set, will use the `auto`
99 strategy. Only applicable if `file_ids` is non-empty.
100
101 description: A description for the vector store. Can be used to describe the vector store's
102 purpose.
103
104 expires_after: The expiration policy for a vector store.
105
106 file_ids: A list of [File](https://platform.openai.com/docs/api-reference/files) IDs that
107 the vector store should use. Useful for tools like `file_search` that can access
108 files.
109
110 metadata: Set of 16 key-value pairs that can be attached to an object. This can be useful
111 for storing additional information about the object in a structured format, and
112 querying for objects via API or the dashboard.
113
114 Keys are strings with a maximum length of 64 characters. Values are strings with
115 a maximum length of 512 characters.
116
117 name: The name of the vector store.
118
119 extra_headers: Send extra headers
120
121 extra_query: Add additional query parameters to the request
122
123 extra_body: Add additional JSON properties to the request
124
125 timeout: Override the client-level default timeout for this request, in seconds
126 """
127 extra_headers = {"OpenAI-Beta": "assistants=v2", **(extra_headers or {})}
128 return self._post(
129 "/vector_stores",
130 body=maybe_transform(
131 {
132 "chunking_strategy": chunking_strategy,
133 "description": description,
134 "expires_after": expires_after,
135 "file_ids": file_ids,
136 "metadata": metadata,
137 "name": name,
138 },
139 vector_store_create_params.VectorStoreCreateParams,
140 ),
141 options=make_request_options(
142 extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
143 ),
144 cast_to=VectorStore,
145 )
146
147 def retrieve(
148 self,
149 vector_store_id: str,
150 *,
151 # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
152 # The extra values given here take precedence over values defined on the client or passed to this method.
153 extra_headers: Headers | None = None,
154 extra_query: Query | None = None,
155 extra_body: Body | None = None,
156 timeout: float | httpx.Timeout | None | NotGiven = not_given,
157 ) -> VectorStore:
158 """
159 Retrieves a vector store.
160
161 Args:
162 extra_headers: Send extra headers
163
164 extra_query: Add additional query parameters to the request
165
166 extra_body: Add additional JSON properties to the request
167
168 timeout: Override the client-level default timeout for this request, in seconds
169 """
170 if not vector_store_id:
171 raise ValueError(f"Expected a non-empty value for `vector_store_id` but received {vector_store_id!r}")
172 extra_headers = {"OpenAI-Beta": "assistants=v2", **(extra_headers or {})}
173 return self._get(
174 f"/vector_stores/{vector_store_id}",
175 options=make_request_options(
176 extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
177 ),
178 cast_to=VectorStore,
179 )
180
181 def update(
182 self,
183 vector_store_id: str,
184 *,
185 expires_after: Optional[vector_store_update_params.ExpiresAfter] | Omit = omit,
186 metadata: Optional[Metadata] | Omit = omit,
187 name: Optional[str] | Omit = omit,
188 # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
189 # The extra values given here take precedence over values defined on the client or passed to this method.
190 extra_headers: Headers | None = None,
191 extra_query: Query | None = None,
192 extra_body: Body | None = None,
193 timeout: float | httpx.Timeout | None | NotGiven = not_given,
194 ) -> VectorStore:
195 """
196 Modifies a vector store.
197
198 Args:
199 expires_after: The expiration policy for a vector store.
200
201 metadata: Set of 16 key-value pairs that can be attached to an object. This can be useful
202 for storing additional information about the object in a structured format, and
203 querying for objects via API or the dashboard.
204
205 Keys are strings with a maximum length of 64 characters. Values are strings with
206 a maximum length of 512 characters.
207
208 name: The name of the vector store.
209
210 extra_headers: Send extra headers
211
212 extra_query: Add additional query parameters to the request
213
214 extra_body: Add additional JSON properties to the request
215
216 timeout: Override the client-level default timeout for this request, in seconds
217 """
218 if not vector_store_id:
219 raise ValueError(f"Expected a non-empty value for `vector_store_id` but received {vector_store_id!r}")
220 extra_headers = {"OpenAI-Beta": "assistants=v2", **(extra_headers or {})}
221 return self._post(
222 f"/vector_stores/{vector_store_id}",
223 body=maybe_transform(
224 {
225 "expires_after": expires_after,
226 "metadata": metadata,
227 "name": name,
228 },
229 vector_store_update_params.VectorStoreUpdateParams,
230 ),
231 options=make_request_options(
232 extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
233 ),
234 cast_to=VectorStore,
235 )
236
237 def list(
238 self,
239 *,
240 after: str | Omit = omit,
241 before: str | Omit = omit,
242 limit: int | Omit = omit,
243 order: Literal["asc", "desc"] | Omit = omit,
244 # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
245 # The extra values given here take precedence over values defined on the client or passed to this method.
246 extra_headers: Headers | None = None,
247 extra_query: Query | None = None,
248 extra_body: Body | None = None,
249 timeout: float | httpx.Timeout | None | NotGiven = not_given,
250 ) -> SyncCursorPage[VectorStore]:
251 """Returns a list of vector stores.
252
253 Args:
254 after: A cursor for use in pagination.
255
256 `after` is an object ID that defines your place
257 in the list. For instance, if you make a list request and receive 100 objects,
258 ending with obj_foo, your subsequent call can include after=obj_foo in order to
259 fetch the next page of the list.
260
261 before: A cursor for use in pagination. `before` is an object ID that defines your place
262 in the list. For instance, if you make a list request and receive 100 objects,
263 starting with obj_foo, your subsequent call can include before=obj_foo in order
264 to fetch the previous page of the list.
265
266 limit: A limit on the number of objects to be returned. Limit can range between 1 and
267 100, and the default is 20.
268
269 order: Sort order by the `created_at` timestamp of the objects. `asc` for ascending
270 order and `desc` for descending order.
271
272 extra_headers: Send extra headers
273
274 extra_query: Add additional query parameters to the request
275
276 extra_body: Add additional JSON properties to the request
277
278 timeout: Override the client-level default timeout for this request, in seconds
279 """
280 extra_headers = {"OpenAI-Beta": "assistants=v2", **(extra_headers or {})}
281 return self._get_api_list(
282 "/vector_stores",
283 page=SyncCursorPage[VectorStore],
284 options=make_request_options(
285 extra_headers=extra_headers,
286 extra_query=extra_query,
287 extra_body=extra_body,
288 timeout=timeout,
289 query=maybe_transform(
290 {
291 "after": after,
292 "before": before,
293 "limit": limit,
294 "order": order,
295 },
296 vector_store_list_params.VectorStoreListParams,
297 ),
298 ),
299 model=VectorStore,
300 )
301
302 def delete(
303 self,
304 vector_store_id: str,
305 *,
306 # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
307 # The extra values given here take precedence over values defined on the client or passed to this method.
308 extra_headers: Headers | None = None,
309 extra_query: Query | None = None,
310 extra_body: Body | None = None,
311 timeout: float | httpx.Timeout | None | NotGiven = not_given,
312 ) -> VectorStoreDeleted:
313 """
314 Delete a vector store.
315
316 Args:
317 extra_headers: Send extra headers
318
319 extra_query: Add additional query parameters to the request
320
321 extra_body: Add additional JSON properties to the request
322
323 timeout: Override the client-level default timeout for this request, in seconds
324 """
325 if not vector_store_id:
326 raise ValueError(f"Expected a non-empty value for `vector_store_id` but received {vector_store_id!r}")
327 extra_headers = {"OpenAI-Beta": "assistants=v2", **(extra_headers or {})}
328 return self._delete(
329 f"/vector_stores/{vector_store_id}",
330 options=make_request_options(
331 extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
332 ),
333 cast_to=VectorStoreDeleted,
334 )
335
336 def search(
337 self,
338 vector_store_id: str,
339 *,
340 query: Union[str, SequenceNotStr[str]],
341 filters: vector_store_search_params.Filters | Omit = omit,
342 max_num_results: int | Omit = omit,
343 ranking_options: vector_store_search_params.RankingOptions | Omit = omit,
344 rewrite_query: bool | Omit = omit,
345 # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
346 # The extra values given here take precedence over values defined on the client or passed to this method.
347 extra_headers: Headers | None = None,
348 extra_query: Query | None = None,
349 extra_body: Body | None = None,
350 timeout: float | httpx.Timeout | None | NotGiven = not_given,
351 ) -> SyncPage[VectorStoreSearchResponse]:
352 """
353 Search a vector store for relevant chunks based on a query and file attributes
354 filter.
355
356 Args:
357 query: A query string for a search
358
359 filters: A filter to apply based on file attributes.
360
361 max_num_results: The maximum number of results to return. This number should be between 1 and 50
362 inclusive.
363
364 ranking_options: Ranking options for search.
365
366 rewrite_query: Whether to rewrite the natural language query for vector search.
367
368 extra_headers: Send extra headers
369
370 extra_query: Add additional query parameters to the request
371
372 extra_body: Add additional JSON properties to the request
373
374 timeout: Override the client-level default timeout for this request, in seconds
375 """
376 if not vector_store_id:
377 raise ValueError(f"Expected a non-empty value for `vector_store_id` but received {vector_store_id!r}")
378 extra_headers = {"OpenAI-Beta": "assistants=v2", **(extra_headers or {})}
379 return self._get_api_list(
380 f"/vector_stores/{vector_store_id}/search",
381 page=SyncPage[VectorStoreSearchResponse],
382 body=maybe_transform(
383 {
384 "query": query,
385 "filters": filters,
386 "max_num_results": max_num_results,
387 "ranking_options": ranking_options,
388 "rewrite_query": rewrite_query,
389 },
390 vector_store_search_params.VectorStoreSearchParams,
391 ),
392 options=make_request_options(
393 extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
394 ),
395 model=VectorStoreSearchResponse,
396 method="post",
397 )
398
399
400class AsyncVectorStores(AsyncAPIResource):
401 @cached_property
402 def files(self) -> AsyncFiles:
403 return AsyncFiles(self._client)
404
405 @cached_property
406 def file_batches(self) -> AsyncFileBatches:
407 return AsyncFileBatches(self._client)
408
409 @cached_property
410 def with_raw_response(self) -> AsyncVectorStoresWithRawResponse:
411 """
412 This property can be used as a prefix for any HTTP method call to return
413 the raw response object instead of the parsed content.
414
415 For more information, see https://www.github.com/openai/openai-python#accessing-raw-response-data-eg-headers
416 """
417 return AsyncVectorStoresWithRawResponse(self)
418
419 @cached_property
420 def with_streaming_response(self) -> AsyncVectorStoresWithStreamingResponse:
421 """
422 An alternative to `.with_raw_response` that doesn't eagerly read the response body.
423
424 For more information, see https://www.github.com/openai/openai-python#with_streaming_response
425 """
426 return AsyncVectorStoresWithStreamingResponse(self)
427
428 async def create(
429 self,
430 *,
431 chunking_strategy: FileChunkingStrategyParam | Omit = omit,
432 description: str | Omit = omit,
433 expires_after: vector_store_create_params.ExpiresAfter | Omit = omit,
434 file_ids: SequenceNotStr[str] | Omit = omit,
435 metadata: Optional[Metadata] | Omit = omit,
436 name: str | Omit = omit,
437 # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
438 # The extra values given here take precedence over values defined on the client or passed to this method.
439 extra_headers: Headers | None = None,
440 extra_query: Query | None = None,
441 extra_body: Body | None = None,
442 timeout: float | httpx.Timeout | None | NotGiven = not_given,
443 ) -> VectorStore:
444 """
445 Create a vector store.
446
447 Args:
448 chunking_strategy: The chunking strategy used to chunk the file(s). If not set, will use the `auto`
449 strategy. Only applicable if `file_ids` is non-empty.
450
451 description: A description for the vector store. Can be used to describe the vector store's
452 purpose.
453
454 expires_after: The expiration policy for a vector store.
455
456 file_ids: A list of [File](https://platform.openai.com/docs/api-reference/files) IDs that
457 the vector store should use. Useful for tools like `file_search` that can access
458 files.
459
460 metadata: Set of 16 key-value pairs that can be attached to an object. This can be useful
461 for storing additional information about the object in a structured format, and
462 querying for objects via API or the dashboard.
463
464 Keys are strings with a maximum length of 64 characters. Values are strings with
465 a maximum length of 512 characters.
466
467 name: The name of the vector store.
468
469 extra_headers: Send extra headers
470
471 extra_query: Add additional query parameters to the request
472
473 extra_body: Add additional JSON properties to the request
474
475 timeout: Override the client-level default timeout for this request, in seconds
476 """
477 extra_headers = {"OpenAI-Beta": "assistants=v2", **(extra_headers or {})}
478 return await self._post(
479 "/vector_stores",
480 body=await async_maybe_transform(
481 {
482 "chunking_strategy": chunking_strategy,
483 "description": description,
484 "expires_after": expires_after,
485 "file_ids": file_ids,
486 "metadata": metadata,
487 "name": name,
488 },
489 vector_store_create_params.VectorStoreCreateParams,
490 ),
491 options=make_request_options(
492 extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
493 ),
494 cast_to=VectorStore,
495 )
496
497 async def retrieve(
498 self,
499 vector_store_id: str,
500 *,
501 # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
502 # The extra values given here take precedence over values defined on the client or passed to this method.
503 extra_headers: Headers | None = None,
504 extra_query: Query | None = None,
505 extra_body: Body | None = None,
506 timeout: float | httpx.Timeout | None | NotGiven = not_given,
507 ) -> VectorStore:
508 """
509 Retrieves a vector store.
510
511 Args:
512 extra_headers: Send extra headers
513
514 extra_query: Add additional query parameters to the request
515
516 extra_body: Add additional JSON properties to the request
517
518 timeout: Override the client-level default timeout for this request, in seconds
519 """
520 if not vector_store_id:
521 raise ValueError(f"Expected a non-empty value for `vector_store_id` but received {vector_store_id!r}")
522 extra_headers = {"OpenAI-Beta": "assistants=v2", **(extra_headers or {})}
523 return await self._get(
524 f"/vector_stores/{vector_store_id}",
525 options=make_request_options(
526 extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
527 ),
528 cast_to=VectorStore,
529 )
530
531 async def update(
532 self,
533 vector_store_id: str,
534 *,
535 expires_after: Optional[vector_store_update_params.ExpiresAfter] | Omit = omit,
536 metadata: Optional[Metadata] | Omit = omit,
537 name: Optional[str] | Omit = omit,
538 # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
539 # The extra values given here take precedence over values defined on the client or passed to this method.
540 extra_headers: Headers | None = None,
541 extra_query: Query | None = None,
542 extra_body: Body | None = None,
543 timeout: float | httpx.Timeout | None | NotGiven = not_given,
544 ) -> VectorStore:
545 """
546 Modifies a vector store.
547
548 Args:
549 expires_after: The expiration policy for a vector store.
550
551 metadata: Set of 16 key-value pairs that can be attached to an object. This can be useful
552 for storing additional information about the object in a structured format, and
553 querying for objects via API or the dashboard.
554
555 Keys are strings with a maximum length of 64 characters. Values are strings with
556 a maximum length of 512 characters.
557
558 name: The name of the vector store.
559
560 extra_headers: Send extra headers
561
562 extra_query: Add additional query parameters to the request
563
564 extra_body: Add additional JSON properties to the request
565
566 timeout: Override the client-level default timeout for this request, in seconds
567 """
568 if not vector_store_id:
569 raise ValueError(f"Expected a non-empty value for `vector_store_id` but received {vector_store_id!r}")
570 extra_headers = {"OpenAI-Beta": "assistants=v2", **(extra_headers or {})}
571 return await self._post(
572 f"/vector_stores/{vector_store_id}",
573 body=await async_maybe_transform(
574 {
575 "expires_after": expires_after,
576 "metadata": metadata,
577 "name": name,
578 },
579 vector_store_update_params.VectorStoreUpdateParams,
580 ),
581 options=make_request_options(
582 extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
583 ),
584 cast_to=VectorStore,
585 )
586
587 def list(
588 self,
589 *,
590 after: str | Omit = omit,
591 before: str | Omit = omit,
592 limit: int | Omit = omit,
593 order: Literal["asc", "desc"] | Omit = omit,
594 # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
595 # The extra values given here take precedence over values defined on the client or passed to this method.
596 extra_headers: Headers | None = None,
597 extra_query: Query | None = None,
598 extra_body: Body | None = None,
599 timeout: float | httpx.Timeout | None | NotGiven = not_given,
600 ) -> AsyncPaginator[VectorStore, AsyncCursorPage[VectorStore]]:
601 """Returns a list of vector stores.
602
603 Args:
604 after: A cursor for use in pagination.
605
606 `after` is an object ID that defines your place
607 in the list. For instance, if you make a list request and receive 100 objects,
608 ending with obj_foo, your subsequent call can include after=obj_foo in order to
609 fetch the next page of the list.
610
611 before: A cursor for use in pagination. `before` is an object ID that defines your place
612 in the list. For instance, if you make a list request and receive 100 objects,
613 starting with obj_foo, your subsequent call can include before=obj_foo in order
614 to fetch the previous page of the list.
615
616 limit: A limit on the number of objects to be returned. Limit can range between 1 and
617 100, and the default is 20.
618
619 order: Sort order by the `created_at` timestamp of the objects. `asc` for ascending
620 order and `desc` for descending order.
621
622 extra_headers: Send extra headers
623
624 extra_query: Add additional query parameters to the request
625
626 extra_body: Add additional JSON properties to the request
627
628 timeout: Override the client-level default timeout for this request, in seconds
629 """
630 extra_headers = {"OpenAI-Beta": "assistants=v2", **(extra_headers or {})}
631 return self._get_api_list(
632 "/vector_stores",
633 page=AsyncCursorPage[VectorStore],
634 options=make_request_options(
635 extra_headers=extra_headers,
636 extra_query=extra_query,
637 extra_body=extra_body,
638 timeout=timeout,
639 query=maybe_transform(
640 {
641 "after": after,
642 "before": before,
643 "limit": limit,
644 "order": order,
645 },
646 vector_store_list_params.VectorStoreListParams,
647 ),
648 ),
649 model=VectorStore,
650 )
651
652 async def delete(
653 self,
654 vector_store_id: str,
655 *,
656 # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
657 # The extra values given here take precedence over values defined on the client or passed to this method.
658 extra_headers: Headers | None = None,
659 extra_query: Query | None = None,
660 extra_body: Body | None = None,
661 timeout: float | httpx.Timeout | None | NotGiven = not_given,
662 ) -> VectorStoreDeleted:
663 """
664 Delete a vector store.
665
666 Args:
667 extra_headers: Send extra headers
668
669 extra_query: Add additional query parameters to the request
670
671 extra_body: Add additional JSON properties to the request
672
673 timeout: Override the client-level default timeout for this request, in seconds
674 """
675 if not vector_store_id:
676 raise ValueError(f"Expected a non-empty value for `vector_store_id` but received {vector_store_id!r}")
677 extra_headers = {"OpenAI-Beta": "assistants=v2", **(extra_headers or {})}
678 return await self._delete(
679 f"/vector_stores/{vector_store_id}",
680 options=make_request_options(
681 extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
682 ),
683 cast_to=VectorStoreDeleted,
684 )
685
686 def search(
687 self,
688 vector_store_id: str,
689 *,
690 query: Union[str, SequenceNotStr[str]],
691 filters: vector_store_search_params.Filters | Omit = omit,
692 max_num_results: int | Omit = omit,
693 ranking_options: vector_store_search_params.RankingOptions | Omit = omit,
694 rewrite_query: bool | Omit = omit,
695 # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
696 # The extra values given here take precedence over values defined on the client or passed to this method.
697 extra_headers: Headers | None = None,
698 extra_query: Query | None = None,
699 extra_body: Body | None = None,
700 timeout: float | httpx.Timeout | None | NotGiven = not_given,
701 ) -> AsyncPaginator[VectorStoreSearchResponse, AsyncPage[VectorStoreSearchResponse]]:
702 """
703 Search a vector store for relevant chunks based on a query and file attributes
704 filter.
705
706 Args:
707 query: A query string for a search
708
709 filters: A filter to apply based on file attributes.
710
711 max_num_results: The maximum number of results to return. This number should be between 1 and 50
712 inclusive.
713
714 ranking_options: Ranking options for search.
715
716 rewrite_query: Whether to rewrite the natural language query for vector search.
717
718 extra_headers: Send extra headers
719
720 extra_query: Add additional query parameters to the request
721
722 extra_body: Add additional JSON properties to the request
723
724 timeout: Override the client-level default timeout for this request, in seconds
725 """
726 if not vector_store_id:
727 raise ValueError(f"Expected a non-empty value for `vector_store_id` but received {vector_store_id!r}")
728 extra_headers = {"OpenAI-Beta": "assistants=v2", **(extra_headers or {})}
729 return self._get_api_list(
730 f"/vector_stores/{vector_store_id}/search",
731 page=AsyncPage[VectorStoreSearchResponse],
732 body=maybe_transform(
733 {
734 "query": query,
735 "filters": filters,
736 "max_num_results": max_num_results,
737 "ranking_options": ranking_options,
738 "rewrite_query": rewrite_query,
739 },
740 vector_store_search_params.VectorStoreSearchParams,
741 ),
742 options=make_request_options(
743 extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
744 ),
745 model=VectorStoreSearchResponse,
746 method="post",
747 )
748
749
750class VectorStoresWithRawResponse:
751 def __init__(self, vector_stores: VectorStores) -> None:
752 self._vector_stores = vector_stores
753
754 self.create = _legacy_response.to_raw_response_wrapper(
755 vector_stores.create,
756 )
757 self.retrieve = _legacy_response.to_raw_response_wrapper(
758 vector_stores.retrieve,
759 )
760 self.update = _legacy_response.to_raw_response_wrapper(
761 vector_stores.update,
762 )
763 self.list = _legacy_response.to_raw_response_wrapper(
764 vector_stores.list,
765 )
766 self.delete = _legacy_response.to_raw_response_wrapper(
767 vector_stores.delete,
768 )
769 self.search = _legacy_response.to_raw_response_wrapper(
770 vector_stores.search,
771 )
772
773 @cached_property
774 def files(self) -> FilesWithRawResponse:
775 return FilesWithRawResponse(self._vector_stores.files)
776
777 @cached_property
778 def file_batches(self) -> FileBatchesWithRawResponse:
779 return FileBatchesWithRawResponse(self._vector_stores.file_batches)
780
781
782class AsyncVectorStoresWithRawResponse:
783 def __init__(self, vector_stores: AsyncVectorStores) -> None:
784 self._vector_stores = vector_stores
785
786 self.create = _legacy_response.async_to_raw_response_wrapper(
787 vector_stores.create,
788 )
789 self.retrieve = _legacy_response.async_to_raw_response_wrapper(
790 vector_stores.retrieve,
791 )
792 self.update = _legacy_response.async_to_raw_response_wrapper(
793 vector_stores.update,
794 )
795 self.list = _legacy_response.async_to_raw_response_wrapper(
796 vector_stores.list,
797 )
798 self.delete = _legacy_response.async_to_raw_response_wrapper(
799 vector_stores.delete,
800 )
801 self.search = _legacy_response.async_to_raw_response_wrapper(
802 vector_stores.search,
803 )
804
805 @cached_property
806 def files(self) -> AsyncFilesWithRawResponse:
807 return AsyncFilesWithRawResponse(self._vector_stores.files)
808
809 @cached_property
810 def file_batches(self) -> AsyncFileBatchesWithRawResponse:
811 return AsyncFileBatchesWithRawResponse(self._vector_stores.file_batches)
812
813
814class VectorStoresWithStreamingResponse:
815 def __init__(self, vector_stores: VectorStores) -> None:
816 self._vector_stores = vector_stores
817
818 self.create = to_streamed_response_wrapper(
819 vector_stores.create,
820 )
821 self.retrieve = to_streamed_response_wrapper(
822 vector_stores.retrieve,
823 )
824 self.update = to_streamed_response_wrapper(
825 vector_stores.update,
826 )
827 self.list = to_streamed_response_wrapper(
828 vector_stores.list,
829 )
830 self.delete = to_streamed_response_wrapper(
831 vector_stores.delete,
832 )
833 self.search = to_streamed_response_wrapper(
834 vector_stores.search,
835 )
836
837 @cached_property
838 def files(self) -> FilesWithStreamingResponse:
839 return FilesWithStreamingResponse(self._vector_stores.files)
840
841 @cached_property
842 def file_batches(self) -> FileBatchesWithStreamingResponse:
843 return FileBatchesWithStreamingResponse(self._vector_stores.file_batches)
844
845
846class AsyncVectorStoresWithStreamingResponse:
847 def __init__(self, vector_stores: AsyncVectorStores) -> None:
848 self._vector_stores = vector_stores
849
850 self.create = async_to_streamed_response_wrapper(
851 vector_stores.create,
852 )
853 self.retrieve = async_to_streamed_response_wrapper(
854 vector_stores.retrieve,
855 )
856 self.update = async_to_streamed_response_wrapper(
857 vector_stores.update,
858 )
859 self.list = async_to_streamed_response_wrapper(
860 vector_stores.list,
861 )
862 self.delete = async_to_streamed_response_wrapper(
863 vector_stores.delete,
864 )
865 self.search = async_to_streamed_response_wrapper(
866 vector_stores.search,
867 )
868
869 @cached_property
870 def files(self) -> AsyncFilesWithStreamingResponse:
871 return AsyncFilesWithStreamingResponse(self._vector_stores.files)
872
873 @cached_property
874 def file_batches(self) -> AsyncFileBatchesWithStreamingResponse:
875 return AsyncFileBatchesWithStreamingResponse(self._vector_stores.file_batches)