View a markdown version of this page

Search for entities - AWS Context

Search for entities

Use SearchAgentContext to find entities that match a query, ranked by relevance: tables, columns, metrics, business terms, documents, skills, or any other entity type in your ontology.

The searchType option is required and selects how AWS Context matches your query:

  • KEYWORD matches the terms in your query. Use it for exact names, such as a table or column name.

  • SEMANTIC matches by meaning. Use it for descriptive questions, such as where you track late shipments.

  • AUTO combines both in one ranked list. Use it when you aren’t sure which works better.

You can also set maxResults (up to 50), a filter (see Filter search results), and compact, which omits each result’s summary and properties.

Each result carries a nodeId to pass to TraverseAgentContext, a score that orders the results, a short summary, and the entity’s properties, including nodeType, the ontology type such as AWS::GLUE::TABLE or AWS::GLUE::COLUMN. AWS Context leaves out entities from a third-party source that the caller hasn’t authorized. For the response fields, see SearchAgentContext in the AWS Context API Reference.

To search and traverse from the top result

The following example uses the AWS SDK for Python (Boto3) to search an Agent context, then traverse from the top result.

import boto3 client = boto3.client("context", region_name="us-east-1") agent_context_id = "ac-1234567890abcdef" search = client.search_agent_context( agentContextId=agent_context_id, query="customer orders", searchType="AUTO", maxResults=10, ) for item in search["items"]: print(item["score"], item["nodeId"], item.get("summary")) if search["items"]: neighbors = client.traverse_agent_context( agentContextId=agent_context_id, nodeId=search["items"][0]["nodeId"], traversalStrategy={"direction": "BOTH", "maxDepth": 1}, ) for n in neighbors["items"]: print(n["depth"], n["nodeId"], [e["properties"].get("edgeType") for e in n["pathEdges"]])

The following AWS CLI command runs the same search.

aws context search-agent-context \ --agent-context-id ac-1234567890abcdef \ --query "customer orders" \ --search-type AUTO \ --max-results 10

For the traversal with the AWS CLI, see To traverse relationships.