77
88import httpx
99
10- from ..types import search_memories_params , search_documents_params
10+ from ..types import search_execute_params , search_memories_params , search_documents_params
1111from .._types import NOT_GIVEN , Body , Query , Headers , NotGiven
1212from .._utils import maybe_transform , async_maybe_transform
1313from .._compat import cached_property
1919 async_to_streamed_response_wrapper ,
2020)
2121from .._base_client import make_request_options
22+ from ..types .search_execute_response import SearchExecuteResponse
2223from ..types .search_memories_response import SearchMemoriesResponse
2324from ..types .search_documents_response import SearchDocumentsResponse
2425
@@ -144,6 +145,105 @@ def documents(
144145 cast_to = SearchDocumentsResponse ,
145146 )
146147
148+ def execute (
149+ self ,
150+ * ,
151+ q : str ,
152+ categories_filter : List [Literal ["technology" , "science" , "business" , "health" ]] | NotGiven = NOT_GIVEN ,
153+ chunk_threshold : float | NotGiven = NOT_GIVEN ,
154+ container_tags : List [str ] | NotGiven = NOT_GIVEN ,
155+ doc_id : str | NotGiven = NOT_GIVEN ,
156+ document_threshold : float | NotGiven = NOT_GIVEN ,
157+ filters : search_execute_params .Filters | NotGiven = NOT_GIVEN ,
158+ include_full_docs : bool | NotGiven = NOT_GIVEN ,
159+ include_summary : bool | NotGiven = NOT_GIVEN ,
160+ limit : int | NotGiven = NOT_GIVEN ,
161+ only_matching_chunks : bool | NotGiven = NOT_GIVEN ,
162+ rerank : bool | NotGiven = NOT_GIVEN ,
163+ rewrite_query : bool | NotGiven = NOT_GIVEN ,
164+ # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
165+ # The extra values given here take precedence over values defined on the client or passed to this method.
166+ extra_headers : Headers | None = None ,
167+ extra_query : Query | None = None ,
168+ extra_body : Body | None = None ,
169+ timeout : float | httpx .Timeout | None | NotGiven = NOT_GIVEN ,
170+ ) -> SearchExecuteResponse :
171+ """
172+ Search memories with advanced filtering
173+
174+ Args:
175+ q: Search query string
176+
177+ categories_filter: Optional category filters
178+
179+ chunk_threshold: Threshold / sensitivity for chunk selection. 0 is least sensitive (returns most
180+ chunks, more results), 1 is most sensitive (returns lesser chunks, accurate
181+ results)
182+
183+ container_tags: Optional tags this search should be containerized by. This can be an ID for your
184+ user, a project ID, or any other identifier you wish to use to filter memories.
185+
186+ doc_id: Optional document ID to search within. You can use this to find chunks in a very
187+ large document.
188+
189+ document_threshold: Threshold / sensitivity for document selection. 0 is least sensitive (returns
190+ most documents, more results), 1 is most sensitive (returns lesser documents,
191+ accurate results)
192+
193+ filters: Optional filters to apply to the search
194+
195+ include_full_docs: If true, include full document in the response. This is helpful if you want a
196+ chatbot to know the full context of the document.
197+
198+ include_summary: If true, include document summary in the response. This is helpful if you want a
199+ chatbot to know the full context of the document.
200+
201+ limit: Maximum number of results to return
202+
203+ only_matching_chunks: If true, only return matching chunks without context. Normally, we send the
204+ previous and next chunk to provide more context for LLMs. If you only want the
205+ matching chunk, set this to true.
206+
207+ rerank: If true, rerank the results based on the query. This is helpful if you want to
208+ ensure the most relevant results are returned.
209+
210+ rewrite_query: If true, rewrites the query to make it easier to find documents. This increases
211+ the latency by about 400ms
212+
213+ extra_headers: Send extra headers
214+
215+ extra_query: Add additional query parameters to the request
216+
217+ extra_body: Add additional JSON properties to the request
218+
219+ timeout: Override the client-level default timeout for this request, in seconds
220+ """
221+ return self ._post (
222+ "/v3/search" ,
223+ body = maybe_transform (
224+ {
225+ "q" : q ,
226+ "categories_filter" : categories_filter ,
227+ "chunk_threshold" : chunk_threshold ,
228+ "container_tags" : container_tags ,
229+ "doc_id" : doc_id ,
230+ "document_threshold" : document_threshold ,
231+ "filters" : filters ,
232+ "include_full_docs" : include_full_docs ,
233+ "include_summary" : include_summary ,
234+ "limit" : limit ,
235+ "only_matching_chunks" : only_matching_chunks ,
236+ "rerank" : rerank ,
237+ "rewrite_query" : rewrite_query ,
238+ },
239+ search_execute_params .SearchExecuteParams ,
240+ ),
241+ options = make_request_options (
242+ extra_headers = extra_headers , extra_query = extra_query , extra_body = extra_body , timeout = timeout
243+ ),
244+ cast_to = SearchExecuteResponse ,
245+ )
246+
147247 def memories (
148248 self ,
149249 * ,
@@ -334,6 +434,105 @@ async def documents(
334434 cast_to = SearchDocumentsResponse ,
335435 )
336436
437+ async def execute (
438+ self ,
439+ * ,
440+ q : str ,
441+ categories_filter : List [Literal ["technology" , "science" , "business" , "health" ]] | NotGiven = NOT_GIVEN ,
442+ chunk_threshold : float | NotGiven = NOT_GIVEN ,
443+ container_tags : List [str ] | NotGiven = NOT_GIVEN ,
444+ doc_id : str | NotGiven = NOT_GIVEN ,
445+ document_threshold : float | NotGiven = NOT_GIVEN ,
446+ filters : search_execute_params .Filters | NotGiven = NOT_GIVEN ,
447+ include_full_docs : bool | NotGiven = NOT_GIVEN ,
448+ include_summary : bool | NotGiven = NOT_GIVEN ,
449+ limit : int | NotGiven = NOT_GIVEN ,
450+ only_matching_chunks : bool | NotGiven = NOT_GIVEN ,
451+ rerank : bool | NotGiven = NOT_GIVEN ,
452+ rewrite_query : bool | NotGiven = NOT_GIVEN ,
453+ # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
454+ # The extra values given here take precedence over values defined on the client or passed to this method.
455+ extra_headers : Headers | None = None ,
456+ extra_query : Query | None = None ,
457+ extra_body : Body | None = None ,
458+ timeout : float | httpx .Timeout | None | NotGiven = NOT_GIVEN ,
459+ ) -> SearchExecuteResponse :
460+ """
461+ Search memories with advanced filtering
462+
463+ Args:
464+ q: Search query string
465+
466+ categories_filter: Optional category filters
467+
468+ chunk_threshold: Threshold / sensitivity for chunk selection. 0 is least sensitive (returns most
469+ chunks, more results), 1 is most sensitive (returns lesser chunks, accurate
470+ results)
471+
472+ container_tags: Optional tags this search should be containerized by. This can be an ID for your
473+ user, a project ID, or any other identifier you wish to use to filter memories.
474+
475+ doc_id: Optional document ID to search within. You can use this to find chunks in a very
476+ large document.
477+
478+ document_threshold: Threshold / sensitivity for document selection. 0 is least sensitive (returns
479+ most documents, more results), 1 is most sensitive (returns lesser documents,
480+ accurate results)
481+
482+ filters: Optional filters to apply to the search
483+
484+ include_full_docs: If true, include full document in the response. This is helpful if you want a
485+ chatbot to know the full context of the document.
486+
487+ include_summary: If true, include document summary in the response. This is helpful if you want a
488+ chatbot to know the full context of the document.
489+
490+ limit: Maximum number of results to return
491+
492+ only_matching_chunks: If true, only return matching chunks without context. Normally, we send the
493+ previous and next chunk to provide more context for LLMs. If you only want the
494+ matching chunk, set this to true.
495+
496+ rerank: If true, rerank the results based on the query. This is helpful if you want to
497+ ensure the most relevant results are returned.
498+
499+ rewrite_query: If true, rewrites the query to make it easier to find documents. This increases
500+ the latency by about 400ms
501+
502+ extra_headers: Send extra headers
503+
504+ extra_query: Add additional query parameters to the request
505+
506+ extra_body: Add additional JSON properties to the request
507+
508+ timeout: Override the client-level default timeout for this request, in seconds
509+ """
510+ return await self ._post (
511+ "/v3/search" ,
512+ body = await async_maybe_transform (
513+ {
514+ "q" : q ,
515+ "categories_filter" : categories_filter ,
516+ "chunk_threshold" : chunk_threshold ,
517+ "container_tags" : container_tags ,
518+ "doc_id" : doc_id ,
519+ "document_threshold" : document_threshold ,
520+ "filters" : filters ,
521+ "include_full_docs" : include_full_docs ,
522+ "include_summary" : include_summary ,
523+ "limit" : limit ,
524+ "only_matching_chunks" : only_matching_chunks ,
525+ "rerank" : rerank ,
526+ "rewrite_query" : rewrite_query ,
527+ },
528+ search_execute_params .SearchExecuteParams ,
529+ ),
530+ options = make_request_options (
531+ extra_headers = extra_headers , extra_query = extra_query , extra_body = extra_body , timeout = timeout
532+ ),
533+ cast_to = SearchExecuteResponse ,
534+ )
535+
337536 async def memories (
338537 self ,
339538 * ,
@@ -412,6 +611,9 @@ def __init__(self, search: SearchResource) -> None:
412611 self .documents = to_raw_response_wrapper (
413612 search .documents ,
414613 )
614+ self .execute = to_raw_response_wrapper (
615+ search .execute ,
616+ )
415617 self .memories = to_raw_response_wrapper (
416618 search .memories ,
417619 )
@@ -424,6 +626,9 @@ def __init__(self, search: AsyncSearchResource) -> None:
424626 self .documents = async_to_raw_response_wrapper (
425627 search .documents ,
426628 )
629+ self .execute = async_to_raw_response_wrapper (
630+ search .execute ,
631+ )
427632 self .memories = async_to_raw_response_wrapper (
428633 search .memories ,
429634 )
@@ -436,6 +641,9 @@ def __init__(self, search: SearchResource) -> None:
436641 self .documents = to_streamed_response_wrapper (
437642 search .documents ,
438643 )
644+ self .execute = to_streamed_response_wrapper (
645+ search .execute ,
646+ )
439647 self .memories = to_streamed_response_wrapper (
440648 search .memories ,
441649 )
@@ -448,6 +656,9 @@ def __init__(self, search: AsyncSearchResource) -> None:
448656 self .documents = async_to_streamed_response_wrapper (
449657 search .documents ,
450658 )
659+ self .execute = async_to_streamed_response_wrapper (
660+ search .execute ,
661+ )
451662 self .memories = async_to_streamed_response_wrapper (
452663 search .memories ,
453664 )
0 commit comments