Query configurations
You can modify configurations when you query the knowledge base to customize retrieval and response generation. To learn more about a configuration and how to modify it in the console or the API, select from the following topics.
The search type defines how data sources in the knowledge base are queried. The following search types are possible:
-
Default – Amazon Bedrock decides the search strategy for you.
-
Hybrid – Combines searching vector embeddings (semantic search) with searching through the raw text. Hybrid search is currently only supported for Amazon OpenSearch Serverless vector stores that contain a filterable text field. If you use a different vector store or your Amazon OpenSearch Serverless vector store doesn't contain a filterable text field, the query uses semantic search.
-
Semantic – Only searches vector embeddings.
To learn how to define the search type, select the tab corresponding to your method of choice and follow the steps.
When generating responses based off retrieval of information, you can use inference parameters to gain more control over the model’s behavior during inference and influence the model’s outputs. To learn how to modify the inference parameters, select the tab corresponding to your method of choice and follow the steps.
When you query a knowledge base, Amazon Bedrock returns up to five results in the response by default. Each result corresponds to a source chunk. To modify the maximum number of results to return, select the tab corresponding to your method of choice and follow the steps.
Your data sources can include metadata files associated with the source documents. A metadata file contains attributes as key-value pairs that you define for a source document. For more information about creating metadata for your data source files, see Add metadata to your files to allow for filtering. To use filters during knowledge base query, check that your knowledge base fulfills the following requirements:
-
The Amazon S3 bucket containing your data source includes at least one
.metadata.json
file with the same name as the source document it's associated with. -
If your knowledge base's vector index is in an Amazon OpenSearch Serverless vector store, check that the vector index is configured with the
faiss
engine. If the vector index is configured with thenmslib
engine, you'll have to do one of the following:-
Create a new knowledge base in the console and let Amazon Bedrock automatically create a vector index in Amazon OpenSearch Serverless for you.
-
Create another vector index in the vector store and select
faiss
as the Engine. Then Create a new knowledge base and specify the new vector index.
-
You can use the following filtering operators when modifying query configurations for filtering:
Filtering operators | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Operator | Console | API filter name | Supported attribute data types | Filtered results | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Equals | = | equals | string, number, boolean | Attribute matches the value you provide | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Not equals | != | notEquals | string, number, boolean | Attribute doesn't match the value you provide | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Greater than | > | greaterThan | number | Attribute is greater than the value you provide | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Greater than or equals | >= | greaterThanOrEquals | number | Attribute is greater than or equal to the value you provide | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Less than | < | lessThan | number | Attribute is less than the value you provide | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Less than or equals | <= | lessThanOrEquals | number | Attribute is less than or equal to the value you provide | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
In | : | in | string list | Attribute is in the list you provide | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Not in | !: | notIn | string list | Attribute isn't in the list you provide | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Starts with | ^ | startsWith | string | Attribute starts with the string you provide (only supported for Amazon OpenSearch Serverless vector stores) |
To combine filtering operators, you can use the following logical operators:
To learn how to filter results using metadata, select the tab corresponding to your method of choice and follow the steps.
When you query a knowledge base and request response generation, Amazon Bedrock uses a prompt template that combines instructions and context with the user query to construct the prompt that's sent to the model for response generation. You can engineer the prompt template with the following tools:
-
Prompt placeholders – Pre-defined variables in Knowledge bases for Amazon Bedrock that are dynamically filled in at runtime during knowledge base query. In the system prompt, you'll see these placeholders surrounded by the
$
symbol. The following list describes the placeholders you can use:Variable Replaced by Model Required? $query$ The user query sent to the knowledge base. Anthropic Claude Instant, Anthropic Claude v2.x Yes Anthropic Claude 3 Sonnet No (automatically included in model input) $search_results$ The retrieved results for the user query. All Yes $output_format_instructions$ Underlying instructions for formatting the response generation and citations. Differs by model. If you define your own formatting instructions, we suggest that you remove this placeholder. Without this placeholder, the response won't contain citations. All No $current_time$ The current time. All No -
XML tags – Anthropic models support the use of XML tags to structure and delineate your prompts. Use descriptive tag names for optimal results. For example, in the default system prompt, you'll see the
<database>
tag used to delineate a database of previously asked questions). For more information, see Use XML tagsin the Anthropic user guide .
For general prompt engineering guidelines, see Prompt engineering guidelines.
Select the tab corresponding to your method of choice and follow the steps.
You can implement safeguards for your knowledge base for your use cases and responsible AI policies. You can create multiple guardrails tailored to different use cases and apply them across multiple request and response conditions, providing a consistent user experience and standardizing safety controls across your knowledge base. You can configure denied topics to disallow undesirable topics and content filters to block harmful content in model inputs and responses. For more information, see Guardrails for Amazon Bedrock.
For general prompt engineering guidelines, see Prompt engineering guidelines.
Select the tab corresponding to your method of choice and follow the steps.