# This file was auto-generated by Fern from our API Definition.

import typing

from ..core.client_wrapper import AsyncClientWrapper, SyncClientWrapper
from ..core.pagination import AsyncPager, SyncPager
from ..core.request_options import RequestOptions
from ..types.compute_corpus_size_response import ComputeCorpusSizeResponse
from ..types.corpus import Corpus
from ..types.corpus_custom_dimension import CorpusCustomDimension
from ..types.corpus_key import CorpusKey
from ..types.filter_attribute import FilterAttribute
from ..types.generation_parameters import GenerationParameters
from ..types.query_full_response import QueryFullResponse
from ..types.query_streamed_response import QueryStreamedResponse
from ..types.replace_filter_attributes_response import ReplaceFilterAttributesResponse
from .raw_client import AsyncRawCorporaClient, RawCorporaClient
from .types.search_corpus_parameters import SearchCorpusParameters

# this is used as the default value for optional parameters
OMIT = typing.cast(typing.Any, ...)


class CorporaClient:
    def __init__(self, *, client_wrapper: SyncClientWrapper):
        self._raw_client = RawCorporaClient(client_wrapper=client_wrapper)

    @property
    def with_raw_response(self) -> RawCorporaClient:
        """
        Retrieves a raw implementation of this client that returns raw responses.

        Returns
        -------
        RawCorporaClient
        """
        return self._raw_client

    def list(
        self,
        *,
        limit: typing.Optional[int] = None,
        filter: typing.Optional[str] = None,
        page_key: typing.Optional[str] = None,
        request_timeout: typing.Optional[int] = None,
        request_timeout_millis: typing.Optional[int] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> SyncPager[Corpus]:
        """
        List corpora in the account. The returned corpus objects contain less
        detail compared to those retrieved the direct corpus retrieval operation.

        Parameters
        ----------
        limit : typing.Optional[int]
            The maximum number of corpora to return at one time.

        filter : typing.Optional[str]
            A regular expression to filter the corpora by their name or summary.

        page_key : typing.Optional[str]
            Used to retrieve the next page of corpora after the limit has been reached.

        request_timeout : typing.Optional[int]
            The API will make a best effort to complete the request in the specified seconds or time out.

        request_timeout_millis : typing.Optional[int]
            The API will make a best effort to complete the request in the specified milliseconds or time out.

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        SyncPager[Corpus]
            List of corpora.

        Examples
        --------
        from vectara import Vectara
        client = Vectara(api_key="YOUR_API_KEY", client_id="YOUR_CLIENT_ID", client_secret="YOUR_CLIENT_SECRET", )
        response = client.corpora.list()
        for item in response:
            yield item
        # alternatively, you can paginate page-by-page
        for page in response.iter_pages():
            yield page
        """
        response = self._raw_client.list(
            limit=limit,
            filter=filter,
            page_key=page_key,
            request_timeout=request_timeout,
            request_timeout_millis=request_timeout_millis,
            request_options=request_options,
        )
        return response.data

    def create(
        self,
        *,
        key: CorpusKey,
        request_timeout: typing.Optional[int] = None,
        request_timeout_millis: typing.Optional[int] = None,
        name: typing.Optional[str] = OMIT,
        description: typing.Optional[str] = OMIT,
        save_history: typing.Optional[bool] = OMIT,
        queries_are_answers: typing.Optional[bool] = OMIT,
        documents_are_questions: typing.Optional[bool] = OMIT,
        encoder_id: typing.Optional[str] = OMIT,
        encoder_name: typing.Optional[str] = OMIT,
        filter_attributes: typing.Optional[typing.Sequence[FilterAttribute]] = OMIT,
        custom_dimensions: typing.Optional[typing.Sequence[CorpusCustomDimension]] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> Corpus:
        """
        Create a corpus, which is a container to store documents and associated metadata. Here, you
        define the unique `corpus_key` that identifies the corpus. The `corpus_key` can be custom-defined
        following your preferred naming convention, allowing you to easily manage the corpus's data and
        reference it in queries. For more information, see
        [Corpus Key Definition](https://docs.vectara.com/docs/api-reference/search-apis/search#corpus-key-definition).

        Parameters
        ----------
        key : CorpusKey

        request_timeout : typing.Optional[int]
            The API will make a best effort to complete the request in the specified seconds or time out.

        request_timeout_millis : typing.Optional[int]
            The API will make a best effort to complete the request in the specified milliseconds or time out.

        name : typing.Optional[str]
            The name for the corpus. This value defaults to the key.

        description : typing.Optional[str]
            Description of the corpus.

        save_history : typing.Optional[bool]
            Indicates whether to save corpus queries to query history by default.

        queries_are_answers : typing.Optional[bool]
            Queries made to this corpus are considered answers, and not questions.

        documents_are_questions : typing.Optional[bool]
            Documents inside this corpus are considered questions, and not answers.

        encoder_id : typing.Optional[str]
            *Deprecated*: Use `encoder_name` instead.

        encoder_name : typing.Optional[str]
            The encoder used by the corpus, `boomerang-2023-q3`.

        filter_attributes : typing.Optional[typing.Sequence[FilterAttribute]]
            The new filter attributes of the corpus.
            If unset then the corpus will not have filter attributes.

        custom_dimensions : typing.Optional[typing.Sequence[CorpusCustomDimension]]
            A custom dimension is an additional numerical field attached to a document part. You
            can then multiply this numerical field with a query time custom dimension of the same
            name. This allows boosting (or burying) document parts for arbitrary reasons.
            This feature is only enabled for Pro and Enterprise customers.

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        Corpus
            The corpus has been created.

        Examples
        --------
        from vectara import Vectara
        client = Vectara(api_key="YOUR_API_KEY", client_id="YOUR_CLIENT_ID", client_secret="YOUR_CLIENT_SECRET", )
        client.corpora.create(key='my-corpus', )
        """
        response = self._raw_client.create(
            key=key,
            request_timeout=request_timeout,
            request_timeout_millis=request_timeout_millis,
            name=name,
            description=description,
            save_history=save_history,
            queries_are_answers=queries_are_answers,
            documents_are_questions=documents_are_questions,
            encoder_id=encoder_id,
            encoder_name=encoder_name,
            filter_attributes=filter_attributes,
            custom_dimensions=custom_dimensions,
            request_options=request_options,
        )
        return response.data

    def get(
        self,
        corpus_key: CorpusKey,
        *,
        request_timeout: typing.Optional[int] = None,
        request_timeout_millis: typing.Optional[int] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> Corpus:
        """
        Get metadata about a corpus. This operation does not search the corpus contents.
        Specify the `corpus_key` to identify the corpus whose metadata you want to
        retrieve. The `corpus_key` is created when the corpus is set up, either through
        the Vectara Console UI or the Create Corpus API. For more information,
        see [Corpus Key Definition](https://docs.vectara.com/docs/api-reference/search-apis/search#corpus-key-definition).

        Parameters
        ----------
        corpus_key : CorpusKey
            The unique key identifying the corpus to retrieve.

        request_timeout : typing.Optional[int]
            The API will make a best effort to complete the request in the specified seconds or time out.

        request_timeout_millis : typing.Optional[int]
            The API will make a best effort to complete the request in the specified milliseconds or time out.

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        Corpus
            A corpus.

        Examples
        --------
        from vectara import Vectara
        client = Vectara(api_key="YOUR_API_KEY", client_id="YOUR_CLIENT_ID", client_secret="YOUR_CLIENT_SECRET", )
        client.corpora.get(corpus_key='my-corpus', )
        """
        response = self._raw_client.get(
            corpus_key,
            request_timeout=request_timeout,
            request_timeout_millis=request_timeout_millis,
            request_options=request_options,
        )
        return response.data

    def delete(
        self,
        corpus_key: CorpusKey,
        *,
        request_timeout: typing.Optional[int] = None,
        request_timeout_millis: typing.Optional[int] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> None:
        """
        Permanently delete a corpus and all its associated data. The `corpus_key` uniquely identifies
        the corpus. For more information, see [Corpus Key Definition](https://docs.vectara.com/docs/api-reference/search-apis/search#corpus-key-definition).

        Parameters
        ----------
        corpus_key : CorpusKey
            The unique key identifying the corpus to delete.

        request_timeout : typing.Optional[int]
            The API will make a best effort to complete the request in the specified seconds or time out.

        request_timeout_millis : typing.Optional[int]
            The API will make a best effort to complete the request in the specified milliseconds or time out.

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        None

        Examples
        --------
        from vectara import Vectara
        client = Vectara(api_key="YOUR_API_KEY", client_id="YOUR_CLIENT_ID", client_secret="YOUR_CLIENT_SECRET", )
        client.corpora.delete(corpus_key='my-corpus', )
        """
        response = self._raw_client.delete(
            corpus_key,
            request_timeout=request_timeout,
            request_timeout_millis=request_timeout_millis,
            request_options=request_options,
        )
        return response.data

    def update(
        self,
        corpus_key: CorpusKey,
        *,
        request_timeout: typing.Optional[int] = None,
        request_timeout_millis: typing.Optional[int] = None,
        enabled: typing.Optional[bool] = OMIT,
        name: typing.Optional[str] = OMIT,
        description: typing.Optional[str] = OMIT,
        save_history: typing.Optional[bool] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> Corpus:
        """
        Enable, disable, or update the name and description of a corpus. This lets you
        manage data availability without deleting the corpus, which is useful for
        maintenance and security purposes. The `corpus_key` uniquely identifies the corpus.
        For more information, see [Corpus Key Definition](https://docs.vectara.com/docs/api-reference/search-apis/search#corpus-key-definition).
        Consider updating the name and description of a corpus dynamically to help keep your data
        aligned with changing business needs.

        Parameters
        ----------
        corpus_key : CorpusKey
            The unique key identifying the corpus to update.

        request_timeout : typing.Optional[int]
            The API will make a best effort to complete the request in the specified seconds or time out.

        request_timeout_millis : typing.Optional[int]
            The API will make a best effort to complete the request in the specified milliseconds or time out.

        enabled : typing.Optional[bool]
            Set whether or not the corpus is enabled. If unset then the corpus will remain in the same state.

        name : typing.Optional[str]
            The name for the corpus. If unset or null, then the corpus will remain in the same state.

        description : typing.Optional[str]
            Description of the corpus. If unset or null, then the corpus will remain in the same state.

        save_history : typing.Optional[bool]
            Indicates whether to save corpus queries to query history by default.

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        Corpus
            Successfully modified the corpus.

        Examples
        --------
        from vectara import Vectara
        client = Vectara(api_key="YOUR_API_KEY", client_id="YOUR_CLIENT_ID", client_secret="YOUR_CLIENT_SECRET", )
        client.corpora.update(corpus_key='my-corpus', )
        """
        response = self._raw_client.update(
            corpus_key,
            request_timeout=request_timeout,
            request_timeout_millis=request_timeout_millis,
            enabled=enabled,
            name=name,
            description=description,
            save_history=save_history,
            request_options=request_options,
        )
        return response.data

    def reset(
        self,
        corpus_key: CorpusKey,
        *,
        request_timeout: typing.Optional[int] = None,
        request_timeout_millis: typing.Optional[int] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> None:
        """
        Resets a corpus, which removes all documents and data from the specified corpus,
        while keeping the corpus itself. The `corpus_key` uniquely identifies the corpus.
        For more information, see [Corpus Key Definition](https://docs.vectara.com/docs/api-reference/search-apis/search#corpus-key-definition).

        Parameters
        ----------
        corpus_key : CorpusKey
            The unique key identifying the corpus to reset.

        request_timeout : typing.Optional[int]
            The API will make a best effort to complete the request in the specified seconds or time out.

        request_timeout_millis : typing.Optional[int]
            The API will make a best effort to complete the request in the specified milliseconds or time out.

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        None

        Examples
        --------
        from vectara import Vectara
        client = Vectara(api_key="YOUR_API_KEY", client_id="YOUR_CLIENT_ID", client_secret="YOUR_CLIENT_SECRET", )
        client.corpora.reset(corpus_key='my-corpus', )
        """
        response = self._raw_client.reset(
            corpus_key,
            request_timeout=request_timeout,
            request_timeout_millis=request_timeout_millis,
            request_options=request_options,
        )
        return response.data

    def replace_filter_attributes(
        self,
        corpus_key: CorpusKey,
        *,
        filter_attributes: typing.Sequence[FilterAttribute],
        request_timeout: typing.Optional[int] = None,
        request_timeout_millis: typing.Optional[int] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> ReplaceFilterAttributesResponse:
        """
        Replace the filter attributes of a corpus. This does not happen immediately, as
        this operation creates a job that completes asynchronously. These new filter
        attributes will not work until the job completes.

        You can monitor the status of the filter change using the returned job ID. The
        `corpus_key` uniquely identifies the corpus. For more information, see
        [Corpus Key Definition](https://docs.vectara.com/docs/api-reference/search-apis/search#corpus-key-definition).

        Parameters
        ----------
        corpus_key : CorpusKey
            The unique key identifying the corpus having its filters replaced.

        filter_attributes : typing.Sequence[FilterAttribute]
            The new filter attributes.

        request_timeout : typing.Optional[int]
            The API will make a best effort to complete the request in the specified seconds or time out.

        request_timeout_millis : typing.Optional[int]
            The API will make a best effort to complete the request in the specified milliseconds or time out.

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        ReplaceFilterAttributesResponse
            Successfully created a job that will replace the filter attributes.

        Examples
        --------
        from vectara import Vectara
        from vectara import FilterAttribute
        client = Vectara(api_key="YOUR_API_KEY", client_id="YOUR_CLIENT_ID", client_secret="YOUR_CLIENT_SECRET", )
        client.corpora.replace_filter_attributes(corpus_key='my-corpus', filter_attributes=[FilterAttribute(name='Title', level="document", type="integer", )], )
        """
        response = self._raw_client.replace_filter_attributes(
            corpus_key,
            filter_attributes=filter_attributes,
            request_timeout=request_timeout,
            request_timeout_millis=request_timeout_millis,
            request_options=request_options,
        )
        return response.data

    def compute_size(
        self,
        corpus_key: CorpusKey,
        *,
        request_timeout: typing.Optional[int] = None,
        request_timeout_millis: typing.Optional[int] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> ComputeCorpusSizeResponse:
        """
        Compute the current size of a corpus, including number of documents, parts, and characters.
        The `corpus_key` uniquely identifies the corpus. For more information, see
        [Corpus Key Definition](https://docs.vectara.com/docs/api-reference/search-apis/search#corpus-key-definition).

        Parameters
        ----------
        corpus_key : CorpusKey
            The unique key identifying the corpus to compute size for.

        request_timeout : typing.Optional[int]
            The API will make a best effort to complete the request in the specified seconds or time out.

        request_timeout_millis : typing.Optional[int]
            The API will make a best effort to complete the request in the specified milliseconds or time out.

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        ComputeCorpusSizeResponse
            Successfully computed the corpus size.

        Examples
        --------
        from vectara import Vectara
        client = Vectara(api_key="YOUR_API_KEY", client_id="YOUR_CLIENT_ID", client_secret="YOUR_CLIENT_SECRET", )
        client.corpora.compute_size(corpus_key='my-corpus', )
        """
        response = self._raw_client.compute_size(
            corpus_key,
            request_timeout=request_timeout,
            request_timeout_millis=request_timeout_millis,
            request_options=request_options,
        )
        return response.data

    def search(
        self,
        corpus_key: CorpusKey,
        *,
        query: str,
        limit: typing.Optional[int] = None,
        offset: typing.Optional[int] = None,
        save_history: typing.Optional[bool] = None,
        intelligent_query_rewriting: typing.Optional[bool] = None,
        request_timeout: typing.Optional[int] = None,
        request_timeout_millis: typing.Optional[int] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> QueryFullResponse:
        """
        Search a single corpus with a straightforward query request, specifying the corpus key and query parameters.
        * Specify the unique `corpus_key` identifying the corpus to query. The `corpus_key` is
        [created in the Vectara Console UI](https://docs.vectara.com/docs/console-ui/creating-a-corpus) or the [Create Corpus API definition](https://docs.vectara.com/docs/api-reference/admin-apis/create-corpus). When creating a new corpus, you have the option to assign a custom `corpus_key` following your preferred naming convention. This key serves as a unique identifier for the corpus, allowing it to be referenced in search requests. For more information, see [Corpus Key Definition](https://docs.vectara.com/docs/api-reference/search-apis/search#corpus-key-definition).
        * Enter the search `query` string for the corpus, which is the question you want to ask.
        * Set the maximum number of results (`limit`) to return. **Default**: 10, **minimum**: 1
        * Define the `offset` position from which to start in the result set.

        For more detailed information, see this [Query API guide](https://docs.vectara.com/docs/api-reference/search-apis/search).

        Parameters
        ----------
        corpus_key : CorpusKey
            The unique key identifying the corpus to query.

        query : str
            The search query string for the corpus, which is the question the user is asking.

        limit : typing.Optional[int]
            The maximum number of results to return.

        offset : typing.Optional[int]
            The position from which to start in the result set.

        save_history : typing.Optional[bool]
            Indicates whether to save the query in the query history.

        intelligent_query_rewriting : typing.Optional[bool]
            Indicates whether to enable intelligent query rewriting. When enabled, the platform will attempt to
            extract metadata filter and rewrite the query to improve search results.

        request_timeout : typing.Optional[int]
            The API will make a best effort to complete the request in the specified seconds or time out.

        request_timeout_millis : typing.Optional[int]
            The API will make a best effort to complete the request in the specified milliseconds or time out.

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        QueryFullResponse
            A response to a query.

        Examples
        --------
        from vectara import Vectara
        client = Vectara(api_key="YOUR_API_KEY", client_id="YOUR_CLIENT_ID", client_secret="YOUR_CLIENT_SECRET", )
        client.corpora.search(corpus_key='my-corpus', query='query', )
        """
        response = self._raw_client.search(
            corpus_key,
            query=query,
            limit=limit,
            offset=offset,
            save_history=save_history,
            intelligent_query_rewriting=intelligent_query_rewriting,
            request_timeout=request_timeout,
            request_timeout_millis=request_timeout_millis,
            request_options=request_options,
        )
        return response.data

    def query_stream(
        self,
        corpus_key: CorpusKey,
        *,
        query: str,
        request_timeout: typing.Optional[int] = None,
        request_timeout_millis: typing.Optional[int] = None,
        search: typing.Optional[SearchCorpusParameters] = OMIT,
        generation: typing.Optional[GenerationParameters] = OMIT,
        save_history: typing.Optional[bool] = OMIT,
        intelligent_query_rewriting: typing.Optional[bool] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> typing.Iterator[QueryStreamedResponse]:
        """
        Perform an advanced query on a specific corpus to find relevant results, highlight relevant snippets, and use Retrieval Augmented Generation:

        * Specify the unique `corpus_key` identifying the corpus to query. The `corpus_key` is [created in the Vectara Console UI](https://docs.vectara.com/docs/console-ui/creating-a-corpus) or the [Create Corpus API definition](https://docs.vectara.com/docs/api-reference/admin-apis/create-corpus). When creating a new corpus, you have the option to assign a custom `corpus_key` following your preferred naming convention. This key serves as a unique identifier for the corpus, allowing it to be referenced in search requests. For more information, see [Corpus Key Definition](https://docs.vectara.com/docs/api-reference/search-apis/search#corpus-key-definition).
        * Customize your search by specifying the query text (`query`), pagination details (`offset` and `limit`), and metadata filters (`metadata_filter`) to tailor your search results. [Learn more](https://docs.vectara.com/docs/api-reference/search-apis/search#query-definition)
        * Leverage advanced search capabilities like reranking (`reranker`) and Retrieval Augmented Generation (RAG) (`generation`) for enhanced query performance. Generation is opt in by setting the `generation` property. By excluding the property or by setting it to null, the response
        will not include generation. [Learn more](https://docs.vectara.com/docs/learn/grounded-generation/configure-query-summarization).
        * Use hybrid search to achieve optimal results by setting different values for `lexical_interpolation` (e.g., `0.025`). [Learn more](https://docs.vectara.com/docs/learn/hybrid-search)
        * Specify Vectara's RAG-focused LLM (Mockingbird) for the `generation_preset_name`. [Learn more](https://docs.vectara.com/docs/learn/mockingbird-llm)
        * Use advanced summarization options that utilize detailed summarization parameters such as `max_response_characters`, `temperature`, and `frequency_penalty` for generating precise and relevant summaries. [Learn more](https://docs.vectara.com/docs/api-reference/search-apis/search#advanced-summarization-options)

        For more detailed information, see [Query API guide](https://docs.vectara.com/docs/api-reference/search-apis/search).

        Parameters
        ----------
        corpus_key : CorpusKey
            The unique key identifying the corpus to query.

        query : str
            The search query string, which is the question the user is asking.

        request_timeout : typing.Optional[int]
            The API will make a best effort to complete the request in the specified seconds or time out.

        request_timeout_millis : typing.Optional[int]
            The API will make a best effort to complete the request in the specified milliseconds or time out.

        search : typing.Optional[SearchCorpusParameters]
            The parameters to search one corpus.

        generation : typing.Optional[GenerationParameters]

        save_history : typing.Optional[bool]
            Indicates whether to save the query to query history.

        intelligent_query_rewriting : typing.Optional[bool]
            Indicates whether to enable intelligent query rewriting. When enabled, the platform will attempt to
            extract metadata filter and rewrite the query to improve search results.

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Yields
        ------
        typing.Iterator[QueryStreamedResponse]


        Examples
        --------
        from vectara import Vectara
        client = Vectara(api_key="YOUR_API_KEY", client_id="YOUR_CLIENT_ID", client_secret="YOUR_CLIENT_SECRET", )
        response = client.corpora.query_stream(corpus_key='my-corpus', query='query', )
        for chunk in response:
            yield chunk
        """
        with self._raw_client.query_stream(
            corpus_key,
            query=query,
            request_timeout=request_timeout,
            request_timeout_millis=request_timeout_millis,
            search=search,
            generation=generation,
            save_history=save_history,
            intelligent_query_rewriting=intelligent_query_rewriting,
            request_options=request_options,
        ) as r:
            yield from r.data

    def query(
        self,
        corpus_key: CorpusKey,
        *,
        query: str,
        request_timeout: typing.Optional[int] = None,
        request_timeout_millis: typing.Optional[int] = None,
        search: typing.Optional[SearchCorpusParameters] = OMIT,
        generation: typing.Optional[GenerationParameters] = OMIT,
        save_history: typing.Optional[bool] = OMIT,
        intelligent_query_rewriting: typing.Optional[bool] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> QueryFullResponse:
        """
        Perform an advanced query on a specific corpus to find relevant results, highlight relevant snippets, and use Retrieval Augmented Generation:

        * Specify the unique `corpus_key` identifying the corpus to query. The `corpus_key` is [created in the Vectara Console UI](https://docs.vectara.com/docs/console-ui/creating-a-corpus) or the [Create Corpus API definition](https://docs.vectara.com/docs/api-reference/admin-apis/create-corpus). When creating a new corpus, you have the option to assign a custom `corpus_key` following your preferred naming convention. This key serves as a unique identifier for the corpus, allowing it to be referenced in search requests. For more information, see [Corpus Key Definition](https://docs.vectara.com/docs/api-reference/search-apis/search#corpus-key-definition).
        * Customize your search by specifying the query text (`query`), pagination details (`offset` and `limit`), and metadata filters (`metadata_filter`) to tailor your search results. [Learn more](https://docs.vectara.com/docs/api-reference/search-apis/search#query-definition)
        * Leverage advanced search capabilities like reranking (`reranker`) and Retrieval Augmented Generation (RAG) (`generation`) for enhanced query performance. Generation is opt in by setting the `generation` property. By excluding the property or by setting it to null, the response
        will not include generation. [Learn more](https://docs.vectara.com/docs/learn/grounded-generation/configure-query-summarization).
        * Use hybrid search to achieve optimal results by setting different values for `lexical_interpolation` (e.g., `0.025`). [Learn more](https://docs.vectara.com/docs/learn/hybrid-search)
        * Specify Vectara's RAG-focused LLM (Mockingbird) for the `generation_preset_name`. [Learn more](https://docs.vectara.com/docs/learn/mockingbird-llm)
        * Use advanced summarization options that utilize detailed summarization parameters such as `max_response_characters`, `temperature`, and `frequency_penalty` for generating precise and relevant summaries. [Learn more](https://docs.vectara.com/docs/api-reference/search-apis/search#advanced-summarization-options)

        For more detailed information, see [Query API guide](https://docs.vectara.com/docs/api-reference/search-apis/search).

        Parameters
        ----------
        corpus_key : CorpusKey
            The unique key identifying the corpus to query.

        query : str
            The search query string, which is the question the user is asking.

        request_timeout : typing.Optional[int]
            The API will make a best effort to complete the request in the specified seconds or time out.

        request_timeout_millis : typing.Optional[int]
            The API will make a best effort to complete the request in the specified milliseconds or time out.

        search : typing.Optional[SearchCorpusParameters]
            The parameters to search one corpus.

        generation : typing.Optional[GenerationParameters]

        save_history : typing.Optional[bool]
            Indicates whether to save the query to query history.

        intelligent_query_rewriting : typing.Optional[bool]
            Indicates whether to enable intelligent query rewriting. When enabled, the platform will attempt to
            extract metadata filter and rewrite the query to improve search results.

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        QueryFullResponse


        Examples
        --------
        from vectara import Vectara
        client = Vectara(api_key="YOUR_API_KEY", client_id="YOUR_CLIENT_ID", client_secret="YOUR_CLIENT_SECRET", )
        client.corpora.query(corpus_key='my-corpus', query='query', )
        """
        response = self._raw_client.query(
            corpus_key,
            query=query,
            request_timeout=request_timeout,
            request_timeout_millis=request_timeout_millis,
            search=search,
            generation=generation,
            save_history=save_history,
            intelligent_query_rewriting=intelligent_query_rewriting,
            request_options=request_options,
        )
        return response.data


class AsyncCorporaClient:
    def __init__(self, *, client_wrapper: AsyncClientWrapper):
        self._raw_client = AsyncRawCorporaClient(client_wrapper=client_wrapper)

    @property
    def with_raw_response(self) -> AsyncRawCorporaClient:
        """
        Retrieves a raw implementation of this client that returns raw responses.

        Returns
        -------
        AsyncRawCorporaClient
        """
        return self._raw_client

    async def list(
        self,
        *,
        limit: typing.Optional[int] = None,
        filter: typing.Optional[str] = None,
        page_key: typing.Optional[str] = None,
        request_timeout: typing.Optional[int] = None,
        request_timeout_millis: typing.Optional[int] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> AsyncPager[Corpus]:
        """
        List corpora in the account. The returned corpus objects contain less
        detail compared to those retrieved the direct corpus retrieval operation.

        Parameters
        ----------
        limit : typing.Optional[int]
            The maximum number of corpora to return at one time.

        filter : typing.Optional[str]
            A regular expression to filter the corpora by their name or summary.

        page_key : typing.Optional[str]
            Used to retrieve the next page of corpora after the limit has been reached.

        request_timeout : typing.Optional[int]
            The API will make a best effort to complete the request in the specified seconds or time out.

        request_timeout_millis : typing.Optional[int]
            The API will make a best effort to complete the request in the specified milliseconds or time out.

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        AsyncPager[Corpus]
            List of corpora.

        Examples
        --------
        from vectara import AsyncVectara
        import asyncio
        client = AsyncVectara(api_key="YOUR_API_KEY", client_id="YOUR_CLIENT_ID", client_secret="YOUR_CLIENT_SECRET", )
        async def main() -> None:
            response = await client.corpora.list()
            async for item in response:
                yield item

            # alternatively, you can paginate page-by-page
            async for page in response.iter_pages():
                yield page
        asyncio.run(main())
        """
        response = await self._raw_client.list(
            limit=limit,
            filter=filter,
            page_key=page_key,
            request_timeout=request_timeout,
            request_timeout_millis=request_timeout_millis,
            request_options=request_options,
        )
        return response.data

    async def create(
        self,
        *,
        key: CorpusKey,
        request_timeout: typing.Optional[int] = None,
        request_timeout_millis: typing.Optional[int] = None,
        name: typing.Optional[str] = OMIT,
        description: typing.Optional[str] = OMIT,
        save_history: typing.Optional[bool] = OMIT,
        queries_are_answers: typing.Optional[bool] = OMIT,
        documents_are_questions: typing.Optional[bool] = OMIT,
        encoder_id: typing.Optional[str] = OMIT,
        encoder_name: typing.Optional[str] = OMIT,
        filter_attributes: typing.Optional[typing.Sequence[FilterAttribute]] = OMIT,
        custom_dimensions: typing.Optional[typing.Sequence[CorpusCustomDimension]] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> Corpus:
        """
        Create a corpus, which is a container to store documents and associated metadata. Here, you
        define the unique `corpus_key` that identifies the corpus. The `corpus_key` can be custom-defined
        following your preferred naming convention, allowing you to easily manage the corpus's data and
        reference it in queries. For more information, see
        [Corpus Key Definition](https://docs.vectara.com/docs/api-reference/search-apis/search#corpus-key-definition).

        Parameters
        ----------
        key : CorpusKey

        request_timeout : typing.Optional[int]
            The API will make a best effort to complete the request in the specified seconds or time out.

        request_timeout_millis : typing.Optional[int]
            The API will make a best effort to complete the request in the specified milliseconds or time out.

        name : typing.Optional[str]
            The name for the corpus. This value defaults to the key.

        description : typing.Optional[str]
            Description of the corpus.

        save_history : typing.Optional[bool]
            Indicates whether to save corpus queries to query history by default.

        queries_are_answers : typing.Optional[bool]
            Queries made to this corpus are considered answers, and not questions.

        documents_are_questions : typing.Optional[bool]
            Documents inside this corpus are considered questions, and not answers.

        encoder_id : typing.Optional[str]
            *Deprecated*: Use `encoder_name` instead.

        encoder_name : typing.Optional[str]
            The encoder used by the corpus, `boomerang-2023-q3`.

        filter_attributes : typing.Optional[typing.Sequence[FilterAttribute]]
            The new filter attributes of the corpus.
            If unset then the corpus will not have filter attributes.

        custom_dimensions : typing.Optional[typing.Sequence[CorpusCustomDimension]]
            A custom dimension is an additional numerical field attached to a document part. You
            can then multiply this numerical field with a query time custom dimension of the same
            name. This allows boosting (or burying) document parts for arbitrary reasons.
            This feature is only enabled for Pro and Enterprise customers.

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        Corpus
            The corpus has been created.

        Examples
        --------
        from vectara import AsyncVectara
        import asyncio
        client = AsyncVectara(api_key="YOUR_API_KEY", client_id="YOUR_CLIENT_ID", client_secret="YOUR_CLIENT_SECRET", )
        async def main() -> None:
            await client.corpora.create(key='my-corpus', )
        asyncio.run(main())
        """
        response = await self._raw_client.create(
            key=key,
            request_timeout=request_timeout,
            request_timeout_millis=request_timeout_millis,
            name=name,
            description=description,
            save_history=save_history,
            queries_are_answers=queries_are_answers,
            documents_are_questions=documents_are_questions,
            encoder_id=encoder_id,
            encoder_name=encoder_name,
            filter_attributes=filter_attributes,
            custom_dimensions=custom_dimensions,
            request_options=request_options,
        )
        return response.data

    async def get(
        self,
        corpus_key: CorpusKey,
        *,
        request_timeout: typing.Optional[int] = None,
        request_timeout_millis: typing.Optional[int] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> Corpus:
        """
        Get metadata about a corpus. This operation does not search the corpus contents.
        Specify the `corpus_key` to identify the corpus whose metadata you want to
        retrieve. The `corpus_key` is created when the corpus is set up, either through
        the Vectara Console UI or the Create Corpus API. For more information,
        see [Corpus Key Definition](https://docs.vectara.com/docs/api-reference/search-apis/search#corpus-key-definition).

        Parameters
        ----------
        corpus_key : CorpusKey
            The unique key identifying the corpus to retrieve.

        request_timeout : typing.Optional[int]
            The API will make a best effort to complete the request in the specified seconds or time out.

        request_timeout_millis : typing.Optional[int]
            The API will make a best effort to complete the request in the specified milliseconds or time out.

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        Corpus
            A corpus.

        Examples
        --------
        from vectara import AsyncVectara
        import asyncio
        client = AsyncVectara(api_key="YOUR_API_KEY", client_id="YOUR_CLIENT_ID", client_secret="YOUR_CLIENT_SECRET", )
        async def main() -> None:
            await client.corpora.get(corpus_key='my-corpus', )
        asyncio.run(main())
        """
        response = await self._raw_client.get(
            corpus_key,
            request_timeout=request_timeout,
            request_timeout_millis=request_timeout_millis,
            request_options=request_options,
        )
        return response.data

    async def delete(
        self,
        corpus_key: CorpusKey,
        *,
        request_timeout: typing.Optional[int] = None,
        request_timeout_millis: typing.Optional[int] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> None:
        """
        Permanently delete a corpus and all its associated data. The `corpus_key` uniquely identifies
        the corpus. For more information, see [Corpus Key Definition](https://docs.vectara.com/docs/api-reference/search-apis/search#corpus-key-definition).

        Parameters
        ----------
        corpus_key : CorpusKey
            The unique key identifying the corpus to delete.

        request_timeout : typing.Optional[int]
            The API will make a best effort to complete the request in the specified seconds or time out.

        request_timeout_millis : typing.Optional[int]
            The API will make a best effort to complete the request in the specified milliseconds or time out.

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        None

        Examples
        --------
        from vectara import AsyncVectara
        import asyncio
        client = AsyncVectara(api_key="YOUR_API_KEY", client_id="YOUR_CLIENT_ID", client_secret="YOUR_CLIENT_SECRET", )
        async def main() -> None:
            await client.corpora.delete(corpus_key='my-corpus', )
        asyncio.run(main())
        """
        response = await self._raw_client.delete(
            corpus_key,
            request_timeout=request_timeout,
            request_timeout_millis=request_timeout_millis,
            request_options=request_options,
        )
        return response.data

    async def update(
        self,
        corpus_key: CorpusKey,
        *,
        request_timeout: typing.Optional[int] = None,
        request_timeout_millis: typing.Optional[int] = None,
        enabled: typing.Optional[bool] = OMIT,
        name: typing.Optional[str] = OMIT,
        description: typing.Optional[str] = OMIT,
        save_history: typing.Optional[bool] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> Corpus:
        """
        Enable, disable, or update the name and description of a corpus. This lets you
        manage data availability without deleting the corpus, which is useful for
        maintenance and security purposes. The `corpus_key` uniquely identifies the corpus.
        For more information, see [Corpus Key Definition](https://docs.vectara.com/docs/api-reference/search-apis/search#corpus-key-definition).
        Consider updating the name and description of a corpus dynamically to help keep your data
        aligned with changing business needs.

        Parameters
        ----------
        corpus_key : CorpusKey
            The unique key identifying the corpus to update.

        request_timeout : typing.Optional[int]
            The API will make a best effort to complete the request in the specified seconds or time out.

        request_timeout_millis : typing.Optional[int]
            The API will make a best effort to complete the request in the specified milliseconds or time out.

        enabled : typing.Optional[bool]
            Set whether or not the corpus is enabled. If unset then the corpus will remain in the same state.

        name : typing.Optional[str]
            The name for the corpus. If unset or null, then the corpus will remain in the same state.

        description : typing.Optional[str]
            Description of the corpus. If unset or null, then the corpus will remain in the same state.

        save_history : typing.Optional[bool]
            Indicates whether to save corpus queries to query history by default.

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        Corpus
            Successfully modified the corpus.

        Examples
        --------
        from vectara import AsyncVectara
        import asyncio
        client = AsyncVectara(api_key="YOUR_API_KEY", client_id="YOUR_CLIENT_ID", client_secret="YOUR_CLIENT_SECRET", )
        async def main() -> None:
            await client.corpora.update(corpus_key='my-corpus', )
        asyncio.run(main())
        """
        response = await self._raw_client.update(
            corpus_key,
            request_timeout=request_timeout,
            request_timeout_millis=request_timeout_millis,
            enabled=enabled,
            name=name,
            description=description,
            save_history=save_history,
            request_options=request_options,
        )
        return response.data

    async def reset(
        self,
        corpus_key: CorpusKey,
        *,
        request_timeout: typing.Optional[int] = None,
        request_timeout_millis: typing.Optional[int] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> None:
        """
        Resets a corpus, which removes all documents and data from the specified corpus,
        while keeping the corpus itself. The `corpus_key` uniquely identifies the corpus.
        For more information, see [Corpus Key Definition](https://docs.vectara.com/docs/api-reference/search-apis/search#corpus-key-definition).

        Parameters
        ----------
        corpus_key : CorpusKey
            The unique key identifying the corpus to reset.

        request_timeout : typing.Optional[int]
            The API will make a best effort to complete the request in the specified seconds or time out.

        request_timeout_millis : typing.Optional[int]
            The API will make a best effort to complete the request in the specified milliseconds or time out.

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        None

        Examples
        --------
        from vectara import AsyncVectara
        import asyncio
        client = AsyncVectara(api_key="YOUR_API_KEY", client_id="YOUR_CLIENT_ID", client_secret="YOUR_CLIENT_SECRET", )
        async def main() -> None:
            await client.corpora.reset(corpus_key='my-corpus', )
        asyncio.run(main())
        """
        response = await self._raw_client.reset(
            corpus_key,
            request_timeout=request_timeout,
            request_timeout_millis=request_timeout_millis,
            request_options=request_options,
        )
        return response.data

    async def replace_filter_attributes(
        self,
        corpus_key: CorpusKey,
        *,
        filter_attributes: typing.Sequence[FilterAttribute],
        request_timeout: typing.Optional[int] = None,
        request_timeout_millis: typing.Optional[int] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> ReplaceFilterAttributesResponse:
        """
        Replace the filter attributes of a corpus. This does not happen immediately, as
        this operation creates a job that completes asynchronously. These new filter
        attributes will not work until the job completes.

        You can monitor the status of the filter change using the returned job ID. The
        `corpus_key` uniquely identifies the corpus. For more information, see
        [Corpus Key Definition](https://docs.vectara.com/docs/api-reference/search-apis/search#corpus-key-definition).

        Parameters
        ----------
        corpus_key : CorpusKey
            The unique key identifying the corpus having its filters replaced.

        filter_attributes : typing.Sequence[FilterAttribute]
            The new filter attributes.

        request_timeout : typing.Optional[int]
            The API will make a best effort to complete the request in the specified seconds or time out.

        request_timeout_millis : typing.Optional[int]
            The API will make a best effort to complete the request in the specified milliseconds or time out.

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        ReplaceFilterAttributesResponse
            Successfully created a job that will replace the filter attributes.

        Examples
        --------
        from vectara import AsyncVectara
        from vectara import FilterAttribute
        import asyncio
        client = AsyncVectara(api_key="YOUR_API_KEY", client_id="YOUR_CLIENT_ID", client_secret="YOUR_CLIENT_SECRET", )
        async def main() -> None:
            await client.corpora.replace_filter_attributes(corpus_key='my-corpus', filter_attributes=[FilterAttribute(name='Title', level="document", type="integer", )], )
        asyncio.run(main())
        """
        response = await self._raw_client.replace_filter_attributes(
            corpus_key,
            filter_attributes=filter_attributes,
            request_timeout=request_timeout,
            request_timeout_millis=request_timeout_millis,
            request_options=request_options,
        )
        return response.data

    async def compute_size(
        self,
        corpus_key: CorpusKey,
        *,
        request_timeout: typing.Optional[int] = None,
        request_timeout_millis: typing.Optional[int] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> ComputeCorpusSizeResponse:
        """
        Compute the current size of a corpus, including number of documents, parts, and characters.
        The `corpus_key` uniquely identifies the corpus. For more information, see
        [Corpus Key Definition](https://docs.vectara.com/docs/api-reference/search-apis/search#corpus-key-definition).

        Parameters
        ----------
        corpus_key : CorpusKey
            The unique key identifying the corpus to compute size for.

        request_timeout : typing.Optional[int]
            The API will make a best effort to complete the request in the specified seconds or time out.

        request_timeout_millis : typing.Optional[int]
            The API will make a best effort to complete the request in the specified milliseconds or time out.

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        ComputeCorpusSizeResponse
            Successfully computed the corpus size.

        Examples
        --------
        from vectara import AsyncVectara
        import asyncio
        client = AsyncVectara(api_key="YOUR_API_KEY", client_id="YOUR_CLIENT_ID", client_secret="YOUR_CLIENT_SECRET", )
        async def main() -> None:
            await client.corpora.compute_size(corpus_key='my-corpus', )
        asyncio.run(main())
        """
        response = await self._raw_client.compute_size(
            corpus_key,
            request_timeout=request_timeout,
            request_timeout_millis=request_timeout_millis,
            request_options=request_options,
        )
        return response.data

    async def search(
        self,
        corpus_key: CorpusKey,
        *,
        query: str,
        limit: typing.Optional[int] = None,
        offset: typing.Optional[int] = None,
        save_history: typing.Optional[bool] = None,
        intelligent_query_rewriting: typing.Optional[bool] = None,
        request_timeout: typing.Optional[int] = None,
        request_timeout_millis: typing.Optional[int] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> QueryFullResponse:
        """
        Search a single corpus with a straightforward query request, specifying the corpus key and query parameters.
        * Specify the unique `corpus_key` identifying the corpus to query. The `corpus_key` is
        [created in the Vectara Console UI](https://docs.vectara.com/docs/console-ui/creating-a-corpus) or the [Create Corpus API definition](https://docs.vectara.com/docs/api-reference/admin-apis/create-corpus). When creating a new corpus, you have the option to assign a custom `corpus_key` following your preferred naming convention. This key serves as a unique identifier for the corpus, allowing it to be referenced in search requests. For more information, see [Corpus Key Definition](https://docs.vectara.com/docs/api-reference/search-apis/search#corpus-key-definition).
        * Enter the search `query` string for the corpus, which is the question you want to ask.
        * Set the maximum number of results (`limit`) to return. **Default**: 10, **minimum**: 1
        * Define the `offset` position from which to start in the result set.

        For more detailed information, see this [Query API guide](https://docs.vectara.com/docs/api-reference/search-apis/search).

        Parameters
        ----------
        corpus_key : CorpusKey
            The unique key identifying the corpus to query.

        query : str
            The search query string for the corpus, which is the question the user is asking.

        limit : typing.Optional[int]
            The maximum number of results to return.

        offset : typing.Optional[int]
            The position from which to start in the result set.

        save_history : typing.Optional[bool]
            Indicates whether to save the query in the query history.

        intelligent_query_rewriting : typing.Optional[bool]
            Indicates whether to enable intelligent query rewriting. When enabled, the platform will attempt to
            extract metadata filter and rewrite the query to improve search results.

        request_timeout : typing.Optional[int]
            The API will make a best effort to complete the request in the specified seconds or time out.

        request_timeout_millis : typing.Optional[int]
            The API will make a best effort to complete the request in the specified milliseconds or time out.

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        QueryFullResponse
            A response to a query.

        Examples
        --------
        from vectara import AsyncVectara
        import asyncio
        client = AsyncVectara(api_key="YOUR_API_KEY", client_id="YOUR_CLIENT_ID", client_secret="YOUR_CLIENT_SECRET", )
        async def main() -> None:
            await client.corpora.search(corpus_key='my-corpus', query='query', )
        asyncio.run(main())
        """
        response = await self._raw_client.search(
            corpus_key,
            query=query,
            limit=limit,
            offset=offset,
            save_history=save_history,
            intelligent_query_rewriting=intelligent_query_rewriting,
            request_timeout=request_timeout,
            request_timeout_millis=request_timeout_millis,
            request_options=request_options,
        )
        return response.data

    async def query_stream(
        self,
        corpus_key: CorpusKey,
        *,
        query: str,
        request_timeout: typing.Optional[int] = None,
        request_timeout_millis: typing.Optional[int] = None,
        search: typing.Optional[SearchCorpusParameters] = OMIT,
        generation: typing.Optional[GenerationParameters] = OMIT,
        save_history: typing.Optional[bool] = OMIT,
        intelligent_query_rewriting: typing.Optional[bool] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> typing.AsyncIterator[QueryStreamedResponse]:
        """
        Perform an advanced query on a specific corpus to find relevant results, highlight relevant snippets, and use Retrieval Augmented Generation:

        * Specify the unique `corpus_key` identifying the corpus to query. The `corpus_key` is [created in the Vectara Console UI](https://docs.vectara.com/docs/console-ui/creating-a-corpus) or the [Create Corpus API definition](https://docs.vectara.com/docs/api-reference/admin-apis/create-corpus). When creating a new corpus, you have the option to assign a custom `corpus_key` following your preferred naming convention. This key serves as a unique identifier for the corpus, allowing it to be referenced in search requests. For more information, see [Corpus Key Definition](https://docs.vectara.com/docs/api-reference/search-apis/search#corpus-key-definition).
        * Customize your search by specifying the query text (`query`), pagination details (`offset` and `limit`), and metadata filters (`metadata_filter`) to tailor your search results. [Learn more](https://docs.vectara.com/docs/api-reference/search-apis/search#query-definition)
        * Leverage advanced search capabilities like reranking (`reranker`) and Retrieval Augmented Generation (RAG) (`generation`) for enhanced query performance. Generation is opt in by setting the `generation` property. By excluding the property or by setting it to null, the response
        will not include generation. [Learn more](https://docs.vectara.com/docs/learn/grounded-generation/configure-query-summarization).
        * Use hybrid search to achieve optimal results by setting different values for `lexical_interpolation` (e.g., `0.025`). [Learn more](https://docs.vectara.com/docs/learn/hybrid-search)
        * Specify Vectara's RAG-focused LLM (Mockingbird) for the `generation_preset_name`. [Learn more](https://docs.vectara.com/docs/learn/mockingbird-llm)
        * Use advanced summarization options that utilize detailed summarization parameters such as `max_response_characters`, `temperature`, and `frequency_penalty` for generating precise and relevant summaries. [Learn more](https://docs.vectara.com/docs/api-reference/search-apis/search#advanced-summarization-options)

        For more detailed information, see [Query API guide](https://docs.vectara.com/docs/api-reference/search-apis/search).

        Parameters
        ----------
        corpus_key : CorpusKey
            The unique key identifying the corpus to query.

        query : str
            The search query string, which is the question the user is asking.

        request_timeout : typing.Optional[int]
            The API will make a best effort to complete the request in the specified seconds or time out.

        request_timeout_millis : typing.Optional[int]
            The API will make a best effort to complete the request in the specified milliseconds or time out.

        search : typing.Optional[SearchCorpusParameters]
            The parameters to search one corpus.

        generation : typing.Optional[GenerationParameters]

        save_history : typing.Optional[bool]
            Indicates whether to save the query to query history.

        intelligent_query_rewriting : typing.Optional[bool]
            Indicates whether to enable intelligent query rewriting. When enabled, the platform will attempt to
            extract metadata filter and rewrite the query to improve search results.

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Yields
        ------
        typing.AsyncIterator[QueryStreamedResponse]


        Examples
        --------
        from vectara import AsyncVectara
        import asyncio
        client = AsyncVectara(api_key="YOUR_API_KEY", client_id="YOUR_CLIENT_ID", client_secret="YOUR_CLIENT_SECRET", )
        async def main() -> None:
            response = await client.corpora.query_stream(corpus_key='my-corpus', query='query', )
            async for chunk in response:
                yield chunk
        asyncio.run(main())
        """
        async with self._raw_client.query_stream(
            corpus_key,
            query=query,
            request_timeout=request_timeout,
            request_timeout_millis=request_timeout_millis,
            search=search,
            generation=generation,
            save_history=save_history,
            intelligent_query_rewriting=intelligent_query_rewriting,
            request_options=request_options,
        ) as r:
            async for data in r.data:
                yield data

    async def query(
        self,
        corpus_key: CorpusKey,
        *,
        query: str,
        request_timeout: typing.Optional[int] = None,
        request_timeout_millis: typing.Optional[int] = None,
        search: typing.Optional[SearchCorpusParameters] = OMIT,
        generation: typing.Optional[GenerationParameters] = OMIT,
        save_history: typing.Optional[bool] = OMIT,
        intelligent_query_rewriting: typing.Optional[bool] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> QueryFullResponse:
        """
        Perform an advanced query on a specific corpus to find relevant results, highlight relevant snippets, and use Retrieval Augmented Generation:

        * Specify the unique `corpus_key` identifying the corpus to query. The `corpus_key` is [created in the Vectara Console UI](https://docs.vectara.com/docs/console-ui/creating-a-corpus) or the [Create Corpus API definition](https://docs.vectara.com/docs/api-reference/admin-apis/create-corpus). When creating a new corpus, you have the option to assign a custom `corpus_key` following your preferred naming convention. This key serves as a unique identifier for the corpus, allowing it to be referenced in search requests. For more information, see [Corpus Key Definition](https://docs.vectara.com/docs/api-reference/search-apis/search#corpus-key-definition).
        * Customize your search by specifying the query text (`query`), pagination details (`offset` and `limit`), and metadata filters (`metadata_filter`) to tailor your search results. [Learn more](https://docs.vectara.com/docs/api-reference/search-apis/search#query-definition)
        * Leverage advanced search capabilities like reranking (`reranker`) and Retrieval Augmented Generation (RAG) (`generation`) for enhanced query performance. Generation is opt in by setting the `generation` property. By excluding the property or by setting it to null, the response
        will not include generation. [Learn more](https://docs.vectara.com/docs/learn/grounded-generation/configure-query-summarization).
        * Use hybrid search to achieve optimal results by setting different values for `lexical_interpolation` (e.g., `0.025`). [Learn more](https://docs.vectara.com/docs/learn/hybrid-search)
        * Specify Vectara's RAG-focused LLM (Mockingbird) for the `generation_preset_name`. [Learn more](https://docs.vectara.com/docs/learn/mockingbird-llm)
        * Use advanced summarization options that utilize detailed summarization parameters such as `max_response_characters`, `temperature`, and `frequency_penalty` for generating precise and relevant summaries. [Learn more](https://docs.vectara.com/docs/api-reference/search-apis/search#advanced-summarization-options)

        For more detailed information, see [Query API guide](https://docs.vectara.com/docs/api-reference/search-apis/search).

        Parameters
        ----------
        corpus_key : CorpusKey
            The unique key identifying the corpus to query.

        query : str
            The search query string, which is the question the user is asking.

        request_timeout : typing.Optional[int]
            The API will make a best effort to complete the request in the specified seconds or time out.

        request_timeout_millis : typing.Optional[int]
            The API will make a best effort to complete the request in the specified milliseconds or time out.

        search : typing.Optional[SearchCorpusParameters]
            The parameters to search one corpus.

        generation : typing.Optional[GenerationParameters]

        save_history : typing.Optional[bool]
            Indicates whether to save the query to query history.

        intelligent_query_rewriting : typing.Optional[bool]
            Indicates whether to enable intelligent query rewriting. When enabled, the platform will attempt to
            extract metadata filter and rewrite the query to improve search results.

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        QueryFullResponse


        Examples
        --------
        from vectara import AsyncVectara
        import asyncio
        client = AsyncVectara(api_key="YOUR_API_KEY", client_id="YOUR_CLIENT_ID", client_secret="YOUR_CLIENT_SECRET", )
        async def main() -> None:
            await client.corpora.query(corpus_key='my-corpus', query='query', )
        asyncio.run(main())
        """
        response = await self._raw_client.query(
            corpus_key,
            query=query,
            request_timeout=request_timeout,
            request_timeout_millis=request_timeout_millis,
            search=search,
            generation=generation,
            save_history=save_history,
            intelligent_query_rewriting=intelligent_query_rewriting,
            request_options=request_options,
        )
        return response.data
