Skip to content

aws.bedrock_agent_runtime.retrieve

Example SQL Queries

SELECT * FROM
aws.bedrock_agent_runtime.retrieve
WHERE
"knowledge_base_id" = 'VALUE'
AND "retrieval_query" = 'VALUE';

Description

Queries a knowledge base and retrieves information from it.

Table Definition

Column NameColumn Data Type
knowledge_base_id Required Input Column

The unique identifier of the knowledge base to query.

VARCHAR
retrieval_query Required Input Column

Contains the query to send the knowledge base.

STRUCT(
"text" VARCHAR
)
Show child fields
retrieval_query.text

The text of the query made to the knowledge base.

retrieval_configuration Input Column

Contains configurations for the knowledge base query and retrieval process. For more information, see Query configurations.

STRUCT(
"vector_search_configuration" STRUCT(
"filter" STRUCT(
"equals" STRUCT(
"key" VARCHAR,
"value" VARCHAR
),
"greater_than" STRUCT(
"key" VARCHAR,
"value" VARCHAR
),
"greater_than_or_equals" STRUCT(
"key" VARCHAR,
"value" VARCHAR
),
"in" STRUCT(
"key" VARCHAR,
"value" VARCHAR
),
"less_than" STRUCT(
"key" VARCHAR,
"value" VARCHAR
),
"less_than_or_equals" STRUCT(
"key" VARCHAR,
"value" VARCHAR
),
"list_contains" STRUCT(
"key" VARCHAR,
"value" VARCHAR
),
"not_equals" STRUCT(
"key" VARCHAR,
"value" VARCHAR
),
"not_in" STRUCT(
"key" VARCHAR,
"value" VARCHAR
),
"starts_with" STRUCT(
"key" VARCHAR,
"value" VARCHAR
),
"string_contains" STRUCT(
"key" VARCHAR,
"value" VARCHAR
)
),
"number_of_results" BIGINT,
"override_search_type" VARCHAR
)
)
Show child fields
retrieval_configuration.vector_search_configuration

Contains details about how the results from the vector search should be returned. For more information, see Query configurations.

Show child fields
retrieval_configuration.vector_search_configuration.filter

Specifies the filters to use on the metadata in the knowledge base data sources before returning results. For more information, see Query configurations.

Show child fields
retrieval_configuration.vector_search_configuration.filter.equals

Knowledge base data sources are returned if they contain a metadata attribute whose name matches the key and whose value matches the value in this object.

The following example would return data sources with an animal attribute whose value is cat:

"equals": { "key": "animal", "value": "cat" }

Show child fields
retrieval_configuration.vector_search_configuration.filter.equals.key

The name that the metadata attribute must match.

retrieval_configuration.vector_search_configuration.filter.equals.value

The value to whcih to compare the value of the metadata attribute.

retrieval_configuration.vector_search_configuration.filter.greater_than

Knowledge base data sources are returned if they contain a metadata attribute whose name matches the key and whose value is greater than the value in this object.

The following example would return data sources with an year attribute whose value is greater than 1989:

"greaterThan": { "key": "year", "value": 1989 }

Show child fields
retrieval_configuration.vector_search_configuration.filter.greater_than.key

The name that the metadata attribute must match.

retrieval_configuration.vector_search_configuration.filter.greater_than.value

The value to whcih to compare the value of the metadata attribute.

retrieval_configuration.vector_search_configuration.filter.greater_than_or_equals

Knowledge base data sources are returned if they contain a metadata attribute whose name matches the key and whose value is greater than or equal to the value in this object.

The following example would return data sources with an year attribute whose value is greater than or equal to 1989:

"greaterThanOrEquals": { "key": "year", "value": 1989 }

Show child fields
retrieval_configuration.vector_search_configuration.filter.greater_than_or_equals.key

The name that the metadata attribute must match.

retrieval_configuration.vector_search_configuration.filter.greater_than_or_equals.value

The value to whcih to compare the value of the metadata attribute.

retrieval_configuration.vector_search_configuration.filter.in

Knowledge base data sources are returned if they contain a metadata attribute whose name matches the key and whose value is in the list specified in the value in this object.

The following example would return data sources with an animal attribute that is either cat or dog:

"in": { "key": "animal", "value": ["cat", "dog"] }

Show child fields
retrieval_configuration.vector_search_configuration.filter.in.key

The name that the metadata attribute must match.

retrieval_configuration.vector_search_configuration.filter.in.value

The value to whcih to compare the value of the metadata attribute.

retrieval_configuration.vector_search_configuration.filter.less_than

Knowledge base data sources are returned if they contain a metadata attribute whose name matches the key and whose value is less than the value in this object.

The following example would return data sources with an year attribute whose value is less than to 1989.

"lessThan": { "key": "year", "value": 1989 }

Show child fields
retrieval_configuration.vector_search_configuration.filter.less_than.key

The name that the metadata attribute must match.

retrieval_configuration.vector_search_configuration.filter.less_than.value

The value to whcih to compare the value of the metadata attribute.

retrieval_configuration.vector_search_configuration.filter.less_than_or_equals

Knowledge base data sources are returned if they contain a metadata attribute whose name matches the key and whose value is less than or equal to the value in this object.

The following example would return data sources with an year attribute whose value is less than or equal to 1989.

"lessThanOrEquals": { "key": "year", "value": 1989 }

Show child fields
retrieval_configuration.vector_search_configuration.filter.less_than_or_equals.key

The name that the metadata attribute must match.

retrieval_configuration.vector_search_configuration.filter.less_than_or_equals.value

The value to whcih to compare the value of the metadata attribute.

retrieval_configuration.vector_search_configuration.filter.list_contains

Knowledge base data sources are returned if they contain a metadata attribute whose name matches the key and whose value is a list that contains the value as one of its members.

The following example would return data sources with an animals attribute that is a list containing a cat member (for example ["dog", "cat"]).

"listContains": { "key": "animals", "value": "cat" }

Show child fields
retrieval_configuration.vector_search_configuration.filter.list_contains.key

The name that the metadata attribute must match.

retrieval_configuration.vector_search_configuration.filter.list_contains.value

The value to whcih to compare the value of the metadata attribute.

retrieval_configuration.vector_search_configuration.filter.not_equals

Knowledge base data sources that contain a metadata attribute whose name matches the key and whose value doesn't match the value in this object are returned.

The following example would return data sources that don't contain an animal attribute whose value is cat.

"notEquals": { "key": "animal", "value": "cat" }

Show child fields
retrieval_configuration.vector_search_configuration.filter.not_equals.key

The name that the metadata attribute must match.

retrieval_configuration.vector_search_configuration.filter.not_equals.value

The value to whcih to compare the value of the metadata attribute.

retrieval_configuration.vector_search_configuration.filter.not_in

Knowledge base data sources are returned if they contain a metadata attribute whose name matches the key and whose value isn't in the list specified in the value in this object.

The following example would return data sources whose animal attribute is neither cat nor dog.

"notIn": { "key": "animal", "value": ["cat", "dog"] }

Show child fields
retrieval_configuration.vector_search_configuration.filter.not_in.key

The name that the metadata attribute must match.

retrieval_configuration.vector_search_configuration.filter.not_in.value

The value to whcih to compare the value of the metadata attribute.

retrieval_configuration.vector_search_configuration.filter.starts_with

Knowledge base data sources are returned if they contain a metadata attribute whose name matches the key and whose value starts with the value in this object. This filter is currently only supported for Amazon OpenSearch Serverless vector stores.

The following example would return data sources with an animal attribute starts with ca (for example, cat or camel).

"startsWith": { "key": "animal", "value": "ca" }

Show child fields
retrieval_configuration.vector_search_configuration.filter.starts_with.key

The name that the metadata attribute must match.

retrieval_configuration.vector_search_configuration.filter.starts_with.value

The value to whcih to compare the value of the metadata attribute.

retrieval_configuration.vector_search_configuration.filter.string_contains

Knowledge base data sources are returned if they contain a metadata attribute whose name matches the key and whose value is one of the following:

  • A string that contains the value as a substring. The following example would return data sources with an animal attribute that contains the substring at (for example cat).

    "stringContains": { "key": "animal", "value": "at" }

  • A list with a member that contains the value as a substring. The following example would return data sources with an animals attribute that is a list containing a member that contains the substring at (for example ["dog", "cat"]).

    "stringContains": { "key": "animals", "value": "at" }

Show child fields
retrieval_configuration.vector_search_configuration.filter.string_contains.key

The name that the metadata attribute must match.

retrieval_configuration.vector_search_configuration.filter.string_contains.value

The value to whcih to compare the value of the metadata attribute.

retrieval_configuration.vector_search_configuration.number_of_results

The number of source chunks to retrieve.

retrieval_configuration.vector_search_configuration.override_search_type

By default, Amazon Bedrock decides a search strategy for you. If you're using an Amazon OpenSearch Serverless vector store that contains a filterable text field, you can specify whether to query the knowledge base with a HYBRID search using both vector embeddings and raw text, or SEMANTIC search using only vector embeddings. For other vector store configurations, only SEMANTIC search is available. For more information, see Test a knowledge base.

_aws_profile Input Column

The AWS profile defines the AWS identity used. It can be defined via credentials or by assuming a IAM role.

STRUCT(
"type" VARCHAR,
"name" VARCHAR,
"account_id" VARCHAR,
"via_profile_name" VARCHAR,
"assumed_role_arn" VARCHAR,
"organization" STRUCT(
"account_name" VARCHAR,
"id" VARCHAR,
"tags" STRUCT(
"key" VARCHAR,
"value" VARCHAR
)[],
"master_account" STRUCT(
"id" VARCHAR,
"email" VARCHAR
),
"parents" STRUCT(
"type" VARCHAR,
"id" VARCHAR,
"name" VARCHAR,
"tags" STRUCT(
"key" VARCHAR,
"value" VARCHAR
)[]
)[]
)
)
Show child fields
_aws_profile.account_id

The AWS account id

_aws_profile.assumed_role_arn

The ARN of the assumed role

_aws_profile.name

The unique name of the profile.

_aws_profile.organization

Information about this profile's membership in the AWS organization.

Show child fields
_aws_profile.organization.account_name

The name of account speciifed by the organization

_aws_profile.organization.id

The organization id

_aws_profile.organization.master_account
Show child fields
_aws_profile.organization.master_account.email

The organization master account email address

_aws_profile.organization.master_account.id

The organization master account id

_aws_profile.organization.parents[]
Show child fields
_aws_profile.organization.parents[].id

The id of the parent

_aws_profile.organization.parents[].name

The name of the parent

_aws_profile.organization.parents[].tags[]
Show child fields
_aws_profile.organization.parents[].tags[].key
_aws_profile.organization.parents[].tags[].value
_aws_profile.organization.parents[].type

The type of parent can be an organization unit or a root

_aws_profile.organization.tags[]
Show child fields
_aws_profile.organization.tags[].key
_aws_profile.organization.tags[].value
_aws_profile.type

The type of profile, either 'credentials' or 'assumed_role'

_aws_profile.via_profile_name

This IAM role for this profile is assumed by first utilizing another profile with this name to obtain credentials.

content

Contains a chunk of text from a data source in the knowledge base.

STRUCT(
"text" VARCHAR
)
Show child fields
content.text

The cited text from the data source.

location

Contains information about the location of the data source.

STRUCT(
"confluence_location" STRUCT(
"url" VARCHAR
),
"s3_location" STRUCT(
"uri" VARCHAR
),
"salesforce_location" STRUCT(
"url" VARCHAR
),
"share_point_location" STRUCT(
"url" VARCHAR
),
"type" VARCHAR,
"web_location" STRUCT(
"url" VARCHAR
)
)
Show child fields
location.confluence_location

The Confluence data source location.

Show child fields
location.confluence_location.url

The Confluence host URL for the data source location.

location.s3_location

The S3 data source location.

Show child fields
location.s3_location.uri

The S3 URI for the data source location.

location.salesforce_location

The Salesforce data source location.

Show child fields
location.salesforce_location.url

The Salesforce host URL for the data source location.

location.share_point_location

The SharePoint data source location.

Show child fields
location.share_point_location.url

The SharePoint site URL for the data source location.

location.type

The type of data source location.

location.web_location

The web URL/URLs data source location.

Show child fields
location.web_location.url

The web URL/URLs for the data source location.

metadata

Contains metadata attributes and their values for the file in the data source. For more information, see Metadata and filtering.

MAP(VARCHAR, VARCHAR)
score

The level of relevance of the result to the query.

DOUBLE