Skip to content

search_agent_context async

search_agent_context(
    agent_context_id: AgentContextIdentifier,
    query: SearchQuery,
    search_type: SearchAgentContextType,
    *,
    config_overrides: Optional[AsyncContextClientConfig] = None,
    max_results: Optional[int] = None,
    next_token: Optional[str] = None,
    filter: Optional[SearchFilter] = None,
) -> SearchAgentContextResponse

Searches an agent context for entities matching a query. Returns ranked entities with relevance scores and metadata. To see the edges around a result node, pass its node ID to TraverseAgentContext.

Parameters:

  • max_results (Optional[int], default: None ) –

    Maximum number of results to return per page.

  • next_token (Optional[str], default: None ) –

    Opaque continuation token from a prior response. Omit on the first page.

  • agent_context_id (AgentContextIdentifier) –

    The agent context to search, by ID or full Amazon Resource Name (ARN).

  • query (SearchQuery) –

    The natural-language query or keywords to search for in the agent context. AWS Context interprets it based on searchType: as literal text for KEYWORD, as a semantic concept for SEMANTIC, or as both for AUTO.

  • filter (Optional[SearchFilter], default: None ) –

    Optional filter on node attributes: a single comparison, or andAll of comparisons that must all match.

  • search_type (SearchAgentContextType) –

    The search strategy to use. Valid values:

    • KEYWORD - Full-text keyword matching (BM25).

    • SEMANTIC - Vector similarity of embeddings.

    • AUTO - Keyword matches first, then semantic matches for the remaining results.

Raises:

  • AccessDeniedException –

    You don't have sufficient access to perform this operation. Verify that you have permission to perform the operation on the resource.

  • InternalServerException –

    The request failed because of an internal error. Retry the request.

  • ThrottlingException –

    The request was denied because it exceeded a request rate quota. Wait, then retry the request.

  • ValidationException –

    The input fails to satisfy the constraints of the operation. Correct the input before you retry the request.

  • ConflictException –

    The request conflicts with the current state of the resource. Check the resource's current state before you retry the request.

  • ResourceNotFoundException –

    The specified resource was not found. Check that the ID is correct and that the resource exists in your account and Region.

  • UnknownServiceError –

    The service returned an error code this client does not model.

Examples:

Search an agent context The following example runs a semantic search for customer orders and returns the two best-matching nodes, an AWS Glue table and one of its columns.

>>> await client.search_agent_context(agent_context_id='ac-0123456789abcdef0123456789abcdef', query='customer orders', search_type='SEMANTIC', max_results=5)
Source code in docs_src/capo_context/_services/async_context.py
async def search_agent_context(
    self,
    agent_context_id: "capo_context.types.agent_context_identifier.AgentContextIdentifier",
    query: "capo_context.types.search_query.SearchQuery",
    search_type: "capo_context.types.search_agent_context_type.SearchAgentContextType",
    *,
    config_overrides: Optional[AsyncContextClientConfig] = None,
    max_results: Optional[int] = None,
    next_token: Optional[str] = None,
    filter: Optional["capo_context.types.search_filter.SearchFilter"] = None,
) -> "capo_context.types.search_agent_context_response.SearchAgentContextResponse":
    """<p>Searches an agent context for entities matching a query. Returns ranked entities with relevance scores and metadata. To see the edges around a result node, pass its node ID to TraverseAgentContext.</p>

    Args:
        max_results: <p>Maximum number of results to return per page.</p>
        next_token: <p>Opaque continuation token from a prior response. Omit on the first page.</p>
        agent_context_id: <p>The agent context to search, by ID or full Amazon Resource Name (ARN).</p>
        query: <p>The natural-language query or keywords to search for in the agent context. AWS Context interprets it based on <code>searchType</code>: as literal text for <code>KEYWORD</code>, as a semantic concept for <code>SEMANTIC</code>, or as both for <code>AUTO</code>.</p>
        filter: <p>Optional filter on node attributes: a single comparison, or <code>andAll</code> of comparisons that must all match.</p>
        search_type: <p>The search strategy to use. Valid values:</p> <ul> <li> <p> <code>KEYWORD</code> - Full-text keyword matching (BM25).</p> </li> <li> <p> <code>SEMANTIC</code> - Vector similarity of embeddings.</p> </li> <li> <p> <code>AUTO</code> - Keyword matches first, then semantic matches for the remaining results.</p> </li> </ul>

    Raises:
        capo_context.errors.access_denied_exception.AccessDeniedException: <p>You don't have sufficient access to perform this operation. Verify that you have permission to perform the operation on the resource.</p>
        capo_context.errors.internal_server_exception.InternalServerException: <p>The request failed because of an internal error. Retry the request.</p>
        capo_context.errors.throttling_exception.ThrottlingException: <p>The request was denied because it exceeded a request rate quota. Wait, then retry the request.</p>
        capo_context.errors.validation_exception.ValidationException: <p>The input fails to satisfy the constraints of the operation. Correct the input before you retry the request.</p>
        capo_context.errors.conflict_exception.ConflictException: <p>The request conflicts with the current state of the resource. Check the resource's current state before you retry the request.</p>
        capo_context.errors.resource_not_found_exception.ResourceNotFoundException: <p>The specified resource was not found. Check that the ID is correct and that the resource exists in your account and Region.</p>
        capo_context.errors.UnknownServiceError: The service returned an error code this client does not model.

    Examples:
        Search an agent context
        The following example runs a semantic search for customer orders and returns the two best-matching nodes, an AWS Glue table and one of its columns.

        >>> await client.search_agent_context(agent_context_id='ac-0123456789abcdef0123456789abcdef', query='customer orders', search_type='SEMANTIC', max_results=5)
    """

    async def _handler(
        req: "AsyncOperationRequest[capo_context.types.search_agent_context_request.SearchAgentContextRequest]",
    ) -> AsyncOperationResponse[
        "capo_context.types.search_agent_context_response.SearchAgentContextResponse"
    ]:
        import capo_context._operations.context.search_agent_context

        (
            output,
            http_response,
        ) = await capo_context._operations.context.search_agent_context.async_search_agent_context(
            req.options, req.input
        )
        return AsyncOperationResponse(output=output, response=http_response)

    def _redact_input(
        input_: "capo_context.types.search_agent_context_request.SearchAgentContextRequest",
    ) -> dict[str, Any]:
        import capo_context.types.search_agent_context_request

        return capo_context.types.search_agent_context_request.redact_sensitive(
            input_
        )

    def _redact_output(
        output: "capo_context.types.search_agent_context_response.SearchAgentContextResponse",
    ) -> dict[str, Any]:
        import capo_context.types.search_agent_context_response

        return capo_context.types.search_agent_context_response.redact_sensitive(
            output
        )

    interceptors_, options_ = self.operation_options(
        config_overrides,
        OperationLogging(
            "SearchAgentContext",
            redact_input=_redact_input,
            redact_output=_redact_output,
        ),
    )
    input_: capo_context.types.search_agent_context_request.SearchAgentContextRequest = {
        "agent_context_id": agent_context_id,
        "query": query,
        "search_type": search_type,
    }
    if max_results is not None:
        input_["max_results"] = max_results
    if next_token is not None:
        input_["next_token"] = next_token
    if filter is not None:
        input_["filter"] = filter

    response = await aexecute_pipeline(
        AsyncOperationRequest(input=input_, options=options_),
        handler=_handler,
        interceptors=list(interceptors_),
    )
    await response.response.aclose()
    return response.output