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

import typing
from json.decoder import JSONDecodeError

from ..core.api_error import ApiError
from ..core.client_wrapper import AsyncClientWrapper, SyncClientWrapper
from ..core.http_response import AsyncHttpResponse, HttpResponse
from ..core.jsonable_encoder import jsonable_encoder
from ..core.pydantic_utilities import parse_obj_as
from ..core.request_options import RequestOptions
from ..errors.unprocessable_entity_error import UnprocessableEntityError
from ..types.memory_detail_response import MemoryDetailResponse
from ..types.memory_list_response import MemoryListResponse
from ..types.memory_response import MemoryResponse
from ..types.memory_search_response import MemorySearchResponse
from ..types.reset_memories_response import ResetMemoriesResponse
from .types.create_memory_request_category import CreateMemoryRequestCategory
from .types.create_memory_request_scope import CreateMemoryRequestScope
from .types.update_memory_request_category import UpdateMemoryRequestCategory
from .types.update_memory_request_scope import UpdateMemoryRequestScope

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


class RawMemoriesClient:
    def __init__(self, *, client_wrapper: SyncClientWrapper):
        self._client_wrapper = client_wrapper

    def list_memories(
        self,
        *,
        scope: typing.Optional[str] = None,
        category: typing.Optional[str] = None,
        organization_id: typing.Optional[str] = None,
        limit: typing.Optional[int] = None,
        offset: typing.Optional[int] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> HttpResponse[MemoryListResponse]:
        """
        Retrieve memories for the authenticated user with optional filters. Returns paginated results sorted by creation date descending.

        Parameters
        ----------
        scope : typing.Optional[str]
            Filter by scope: global or organization

        category : typing.Optional[str]
            Filter by category

        organization_id : typing.Optional[str]
            Filter by organization ID

        limit : typing.Optional[int]
            Page size (1-100)

        offset : typing.Optional[int]
            Offset for pagination

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

        Returns
        -------
        HttpResponse[MemoryListResponse]
            Successful Response
        """
        _response = self._client_wrapper.httpx_client.request(
            "v1/me/memories",
            method="GET",
            params={
                "scope": scope,
                "category": category,
                "organization_id": organization_id,
                "limit": limit,
                "offset": offset,
            },
            request_options=request_options,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    MemoryListResponse,
                    parse_obj_as(
                        type_=MemoryListResponse,  # type: ignore
                        object_=_response.json(),
                    ),
                )
                return HttpResponse(response=_response, data=_data)
            if _response.status_code == 422:
                raise UnprocessableEntityError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Any,
                        parse_obj_as(
                            type_=typing.Any,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            _response_json = _response.json()
        except JSONDecodeError:
            raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
        raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)

    def create_memory(
        self,
        *,
        content: str,
        category: typing.Optional[CreateMemoryRequestCategory] = OMIT,
        scope: typing.Optional[CreateMemoryRequestScope] = OMIT,
        organization_id: typing.Optional[str] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> HttpResponse[MemoryResponse]:
        """
        Manually create a personal memory. Automatically checks for duplicates via embedding similarity. Returns the created or matched existing memory.

        Parameters
        ----------
        content : str
            The memory text

        category : typing.Optional[CreateMemoryRequestCategory]
            Category: fact, preference, instruction, context, biographical

        scope : typing.Optional[CreateMemoryRequestScope]
            Scope: global or organization

        organization_id : typing.Optional[str]
            Required when scope is organization

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

        Returns
        -------
        HttpResponse[MemoryResponse]
            Successful Response
        """
        _response = self._client_wrapper.httpx_client.request(
            "v1/me/memories",
            method="POST",
            json={
                "content": content,
                "category": category,
                "scope": scope,
                "organization_id": organization_id,
            },
            headers={
                "content-type": "application/json",
            },
            request_options=request_options,
            omit=OMIT,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    MemoryResponse,
                    parse_obj_as(
                        type_=MemoryResponse,  # type: ignore
                        object_=_response.json(),
                    ),
                )
                return HttpResponse(response=_response, data=_data)
            if _response.status_code == 422:
                raise UnprocessableEntityError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Any,
                        parse_obj_as(
                            type_=typing.Any,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            _response_json = _response.json()
        except JSONDecodeError:
            raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
        raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)

    def reset_all_memories(
        self, *, confirm_reset: typing.Optional[str] = None, request_options: typing.Optional[RequestOptions] = None
    ) -> HttpResponse[ResetMemoriesResponse]:
        """
        Permanently delete all memories for the authenticated user. Requires the X-Confirm-Reset: true header as a safety measure.

        Parameters
        ----------
        confirm_reset : typing.Optional[str]

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

        Returns
        -------
        HttpResponse[ResetMemoriesResponse]
            Successful Response
        """
        _response = self._client_wrapper.httpx_client.request(
            "v1/me/memories",
            method="DELETE",
            headers={
                "X-Confirm-Reset": str(confirm_reset) if confirm_reset is not None else None,
            },
            request_options=request_options,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    ResetMemoriesResponse,
                    parse_obj_as(
                        type_=ResetMemoriesResponse,  # type: ignore
                        object_=_response.json(),
                    ),
                )
                return HttpResponse(response=_response, data=_data)
            if _response.status_code == 422:
                raise UnprocessableEntityError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Any,
                        parse_obj_as(
                            type_=typing.Any,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            _response_json = _response.json()
        except JSONDecodeError:
            raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
        raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)

    def get_memory(
        self, memory_id: str, *, request_options: typing.Optional[RequestOptions] = None
    ) -> HttpResponse[MemoryDetailResponse]:
        """
        Retrieve a single memory by ID, including source tracking fields.

        Parameters
        ----------
        memory_id : str

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

        Returns
        -------
        HttpResponse[MemoryDetailResponse]
            Successful Response
        """
        _response = self._client_wrapper.httpx_client.request(
            f"v1/me/memories/{jsonable_encoder(memory_id)}",
            method="GET",
            request_options=request_options,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    MemoryDetailResponse,
                    parse_obj_as(
                        type_=MemoryDetailResponse,  # type: ignore
                        object_=_response.json(),
                    ),
                )
                return HttpResponse(response=_response, data=_data)
            if _response.status_code == 422:
                raise UnprocessableEntityError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Any,
                        parse_obj_as(
                            type_=typing.Any,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            _response_json = _response.json()
        except JSONDecodeError:
            raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
        raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)

    def delete_memory(
        self, memory_id: str, *, request_options: typing.Optional[RequestOptions] = None
    ) -> HttpResponse[None]:
        """
        Permanently delete a single memory and its vector embedding.

        Parameters
        ----------
        memory_id : str

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

        Returns
        -------
        HttpResponse[None]
        """
        _response = self._client_wrapper.httpx_client.request(
            f"v1/me/memories/{jsonable_encoder(memory_id)}",
            method="DELETE",
            request_options=request_options,
        )
        try:
            if 200 <= _response.status_code < 300:
                return HttpResponse(response=_response, data=None)
            if _response.status_code == 422:
                raise UnprocessableEntityError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Any,
                        parse_obj_as(
                            type_=typing.Any,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            _response_json = _response.json()
        except JSONDecodeError:
            raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
        raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)

    def update_memory(
        self,
        memory_id: str,
        *,
        content: typing.Optional[str] = OMIT,
        category: typing.Optional[UpdateMemoryRequestCategory] = OMIT,
        scope: typing.Optional[UpdateMemoryRequestScope] = OMIT,
        organization_id: typing.Optional[str] = OMIT,
        is_pinned: typing.Optional[bool] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> HttpResponse[MemoryResponse]:
        """
        Update a memory's content, category, scope, or pinned status. Re-embeds the content if it changed.

        Parameters
        ----------
        memory_id : str

        content : typing.Optional[str]

        category : typing.Optional[UpdateMemoryRequestCategory]

        scope : typing.Optional[UpdateMemoryRequestScope]

        organization_id : typing.Optional[str]

        is_pinned : typing.Optional[bool]

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

        Returns
        -------
        HttpResponse[MemoryResponse]
            Successful Response
        """
        _response = self._client_wrapper.httpx_client.request(
            f"v1/me/memories/{jsonable_encoder(memory_id)}",
            method="PATCH",
            json={
                "content": content,
                "category": category,
                "scope": scope,
                "organization_id": organization_id,
                "is_pinned": is_pinned,
            },
            headers={
                "content-type": "application/json",
            },
            request_options=request_options,
            omit=OMIT,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    MemoryResponse,
                    parse_obj_as(
                        type_=MemoryResponse,  # type: ignore
                        object_=_response.json(),
                    ),
                )
                return HttpResponse(response=_response, data=_data)
            if _response.status_code == 422:
                raise UnprocessableEntityError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Any,
                        parse_obj_as(
                            type_=typing.Any,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            _response_json = _response.json()
        except JSONDecodeError:
            raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
        raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)

    def search_memories(
        self, *, query: str, limit: typing.Optional[int] = OMIT, request_options: typing.Optional[RequestOptions] = None
    ) -> HttpResponse[MemorySearchResponse]:
        """
        Semantic search over the authenticated user's memories. Returns memories ranked by relevance to the query.

        Parameters
        ----------
        query : str
            Search query

        limit : typing.Optional[int]
            Max results (1-50)

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

        Returns
        -------
        HttpResponse[MemorySearchResponse]
            Successful Response
        """
        _response = self._client_wrapper.httpx_client.request(
            "v1/me/memories/search",
            method="POST",
            json={
                "query": query,
                "limit": limit,
            },
            headers={
                "content-type": "application/json",
            },
            request_options=request_options,
            omit=OMIT,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    MemorySearchResponse,
                    parse_obj_as(
                        type_=MemorySearchResponse,  # type: ignore
                        object_=_response.json(),
                    ),
                )
                return HttpResponse(response=_response, data=_data)
            if _response.status_code == 422:
                raise UnprocessableEntityError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Any,
                        parse_obj_as(
                            type_=typing.Any,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            _response_json = _response.json()
        except JSONDecodeError:
            raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
        raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)


class AsyncRawMemoriesClient:
    def __init__(self, *, client_wrapper: AsyncClientWrapper):
        self._client_wrapper = client_wrapper

    async def list_memories(
        self,
        *,
        scope: typing.Optional[str] = None,
        category: typing.Optional[str] = None,
        organization_id: typing.Optional[str] = None,
        limit: typing.Optional[int] = None,
        offset: typing.Optional[int] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> AsyncHttpResponse[MemoryListResponse]:
        """
        Retrieve memories for the authenticated user with optional filters. Returns paginated results sorted by creation date descending.

        Parameters
        ----------
        scope : typing.Optional[str]
            Filter by scope: global or organization

        category : typing.Optional[str]
            Filter by category

        organization_id : typing.Optional[str]
            Filter by organization ID

        limit : typing.Optional[int]
            Page size (1-100)

        offset : typing.Optional[int]
            Offset for pagination

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

        Returns
        -------
        AsyncHttpResponse[MemoryListResponse]
            Successful Response
        """
        _response = await self._client_wrapper.httpx_client.request(
            "v1/me/memories",
            method="GET",
            params={
                "scope": scope,
                "category": category,
                "organization_id": organization_id,
                "limit": limit,
                "offset": offset,
            },
            request_options=request_options,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    MemoryListResponse,
                    parse_obj_as(
                        type_=MemoryListResponse,  # type: ignore
                        object_=_response.json(),
                    ),
                )
                return AsyncHttpResponse(response=_response, data=_data)
            if _response.status_code == 422:
                raise UnprocessableEntityError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Any,
                        parse_obj_as(
                            type_=typing.Any,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            _response_json = _response.json()
        except JSONDecodeError:
            raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
        raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)

    async def create_memory(
        self,
        *,
        content: str,
        category: typing.Optional[CreateMemoryRequestCategory] = OMIT,
        scope: typing.Optional[CreateMemoryRequestScope] = OMIT,
        organization_id: typing.Optional[str] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> AsyncHttpResponse[MemoryResponse]:
        """
        Manually create a personal memory. Automatically checks for duplicates via embedding similarity. Returns the created or matched existing memory.

        Parameters
        ----------
        content : str
            The memory text

        category : typing.Optional[CreateMemoryRequestCategory]
            Category: fact, preference, instruction, context, biographical

        scope : typing.Optional[CreateMemoryRequestScope]
            Scope: global or organization

        organization_id : typing.Optional[str]
            Required when scope is organization

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

        Returns
        -------
        AsyncHttpResponse[MemoryResponse]
            Successful Response
        """
        _response = await self._client_wrapper.httpx_client.request(
            "v1/me/memories",
            method="POST",
            json={
                "content": content,
                "category": category,
                "scope": scope,
                "organization_id": organization_id,
            },
            headers={
                "content-type": "application/json",
            },
            request_options=request_options,
            omit=OMIT,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    MemoryResponse,
                    parse_obj_as(
                        type_=MemoryResponse,  # type: ignore
                        object_=_response.json(),
                    ),
                )
                return AsyncHttpResponse(response=_response, data=_data)
            if _response.status_code == 422:
                raise UnprocessableEntityError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Any,
                        parse_obj_as(
                            type_=typing.Any,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            _response_json = _response.json()
        except JSONDecodeError:
            raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
        raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)

    async def reset_all_memories(
        self, *, confirm_reset: typing.Optional[str] = None, request_options: typing.Optional[RequestOptions] = None
    ) -> AsyncHttpResponse[ResetMemoriesResponse]:
        """
        Permanently delete all memories for the authenticated user. Requires the X-Confirm-Reset: true header as a safety measure.

        Parameters
        ----------
        confirm_reset : typing.Optional[str]

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

        Returns
        -------
        AsyncHttpResponse[ResetMemoriesResponse]
            Successful Response
        """
        _response = await self._client_wrapper.httpx_client.request(
            "v1/me/memories",
            method="DELETE",
            headers={
                "X-Confirm-Reset": str(confirm_reset) if confirm_reset is not None else None,
            },
            request_options=request_options,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    ResetMemoriesResponse,
                    parse_obj_as(
                        type_=ResetMemoriesResponse,  # type: ignore
                        object_=_response.json(),
                    ),
                )
                return AsyncHttpResponse(response=_response, data=_data)
            if _response.status_code == 422:
                raise UnprocessableEntityError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Any,
                        parse_obj_as(
                            type_=typing.Any,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            _response_json = _response.json()
        except JSONDecodeError:
            raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
        raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)

    async def get_memory(
        self, memory_id: str, *, request_options: typing.Optional[RequestOptions] = None
    ) -> AsyncHttpResponse[MemoryDetailResponse]:
        """
        Retrieve a single memory by ID, including source tracking fields.

        Parameters
        ----------
        memory_id : str

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

        Returns
        -------
        AsyncHttpResponse[MemoryDetailResponse]
            Successful Response
        """
        _response = await self._client_wrapper.httpx_client.request(
            f"v1/me/memories/{jsonable_encoder(memory_id)}",
            method="GET",
            request_options=request_options,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    MemoryDetailResponse,
                    parse_obj_as(
                        type_=MemoryDetailResponse,  # type: ignore
                        object_=_response.json(),
                    ),
                )
                return AsyncHttpResponse(response=_response, data=_data)
            if _response.status_code == 422:
                raise UnprocessableEntityError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Any,
                        parse_obj_as(
                            type_=typing.Any,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            _response_json = _response.json()
        except JSONDecodeError:
            raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
        raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)

    async def delete_memory(
        self, memory_id: str, *, request_options: typing.Optional[RequestOptions] = None
    ) -> AsyncHttpResponse[None]:
        """
        Permanently delete a single memory and its vector embedding.

        Parameters
        ----------
        memory_id : str

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

        Returns
        -------
        AsyncHttpResponse[None]
        """
        _response = await self._client_wrapper.httpx_client.request(
            f"v1/me/memories/{jsonable_encoder(memory_id)}",
            method="DELETE",
            request_options=request_options,
        )
        try:
            if 200 <= _response.status_code < 300:
                return AsyncHttpResponse(response=_response, data=None)
            if _response.status_code == 422:
                raise UnprocessableEntityError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Any,
                        parse_obj_as(
                            type_=typing.Any,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            _response_json = _response.json()
        except JSONDecodeError:
            raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
        raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)

    async def update_memory(
        self,
        memory_id: str,
        *,
        content: typing.Optional[str] = OMIT,
        category: typing.Optional[UpdateMemoryRequestCategory] = OMIT,
        scope: typing.Optional[UpdateMemoryRequestScope] = OMIT,
        organization_id: typing.Optional[str] = OMIT,
        is_pinned: typing.Optional[bool] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> AsyncHttpResponse[MemoryResponse]:
        """
        Update a memory's content, category, scope, or pinned status. Re-embeds the content if it changed.

        Parameters
        ----------
        memory_id : str

        content : typing.Optional[str]

        category : typing.Optional[UpdateMemoryRequestCategory]

        scope : typing.Optional[UpdateMemoryRequestScope]

        organization_id : typing.Optional[str]

        is_pinned : typing.Optional[bool]

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

        Returns
        -------
        AsyncHttpResponse[MemoryResponse]
            Successful Response
        """
        _response = await self._client_wrapper.httpx_client.request(
            f"v1/me/memories/{jsonable_encoder(memory_id)}",
            method="PATCH",
            json={
                "content": content,
                "category": category,
                "scope": scope,
                "organization_id": organization_id,
                "is_pinned": is_pinned,
            },
            headers={
                "content-type": "application/json",
            },
            request_options=request_options,
            omit=OMIT,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    MemoryResponse,
                    parse_obj_as(
                        type_=MemoryResponse,  # type: ignore
                        object_=_response.json(),
                    ),
                )
                return AsyncHttpResponse(response=_response, data=_data)
            if _response.status_code == 422:
                raise UnprocessableEntityError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Any,
                        parse_obj_as(
                            type_=typing.Any,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            _response_json = _response.json()
        except JSONDecodeError:
            raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
        raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)

    async def search_memories(
        self, *, query: str, limit: typing.Optional[int] = OMIT, request_options: typing.Optional[RequestOptions] = None
    ) -> AsyncHttpResponse[MemorySearchResponse]:
        """
        Semantic search over the authenticated user's memories. Returns memories ranked by relevance to the query.

        Parameters
        ----------
        query : str
            Search query

        limit : typing.Optional[int]
            Max results (1-50)

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

        Returns
        -------
        AsyncHttpResponse[MemorySearchResponse]
            Successful Response
        """
        _response = await self._client_wrapper.httpx_client.request(
            "v1/me/memories/search",
            method="POST",
            json={
                "query": query,
                "limit": limit,
            },
            headers={
                "content-type": "application/json",
            },
            request_options=request_options,
            omit=OMIT,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    MemorySearchResponse,
                    parse_obj_as(
                        type_=MemorySearchResponse,  # type: ignore
                        object_=_response.json(),
                    ),
                )
                return AsyncHttpResponse(response=_response, data=_data)
            if _response.status_code == 422:
                raise UnprocessableEntityError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Any,
                        parse_obj_as(
                            type_=typing.Any,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            _response_json = _response.json()
        except JSONDecodeError:
            raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
        raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)
