query_vectors
¶
query_vectors(
top_k: TopK,
query_vector: VectorData,
*,
config_overrides: Optional[S3VectorsClientConfig] = None,
vector_bucket_name: Optional[VectorBucketName] = None,
index_name: Optional[IndexName] = None,
index_arn: Optional[IndexArn] = None,
filter: Optional[object] = None,
query_mode: Optional[IndexMode] = None,
return_metadata: Optional[bool] = None,
return_distance: Optional[bool] = None,
next_token: Optional[QueryVectorsNextToken] = None,
) -> QueryVectorsOutput
Performs an approximate nearest neighbor search query in a vector index using a query vector. By default, it returns the keys of approximate nearest neighbors. You can optionally include the computed distance (between the query vector and each vector in the response) and metadata of each vector in the response.
To specify the vector index, you can either use both the vector bucket name and the vector index name, or use the vector index Amazon Resource Name (ARN).
- Permissions
-
You must have the
s3vectors:QueryVectorspermission to use this operation. Additional permissions are required based on the request parameters you specify:-
With only
s3vectors:QueryVectorspermission, you can retrieve vector keys of approximate nearest neighbors and computed distances between these vectors. This permission is sufficient only when you don't set any metadata filters and don't request metadata (by keeping thereturnMetadataparameter set tofalseor not specified). -
If you specify a metadata filter or set
returnMetadatato true, you must have boths3vectors:QueryVectorsands3vectors:GetVectorspermissions. The request fails with a403 Forbidden errorif you request metadata filtering or metadata without thes3vectors:GetVectorspermission.
-
Parameters:
-
vector_bucket_name(Optional[VectorBucketName], default:None) –The name of the vector bucket that contains the vector index.
-
index_name(Optional[IndexName], default:None) –The name of the vector index that you want to query.
-
index_arn(Optional[IndexArn], default:None) –The ARN of the vector index that you want to query.
-
top_k(TopK) –The number of results to return for each query.
-
query_vector(VectorData) –The query vector. Ensure that the query vector has the same dimension as the dimension of the vector index that's being queried. For example, if your vector index contains vectors with 384 dimensions, your query vector must also have 384 dimensions.
-
filter(Optional[object], default:None) –Metadata filter to apply during the query. For more information about metadata keys, see Metadata filtering in the Amazon S3 User Guide.
-
query_mode(Optional[IndexMode], default:None) –The mode to use to process the query. If you don't specify a query mode, the operation uses the mode that's currently configured for the vector index.
Valid values:
-
CLASSIC- Applies metadata filters during the vector search. You can't specifyCLASSICfor anENHANCEDindex. -
ENHANCED- Applies metadata filters before the vector search.
-
-
return_metadata(Optional[bool], default:None) –Indicates whether to include metadata in the response. The default value is
false. -
return_distance(Optional[bool], default:None) –Indicates whether to include the computed distance in the response. The default value is
false. -
next_token(Optional[QueryVectorsNextToken], default:None) –Pagination token from a previous request. The value of this field is empty for an initial request.
Raises:
-
AccessDeniedException–Access denied.
-
InternalServerException–The request failed due to an internal server error.
-
RequestTimeoutException–The request timed out. Retry your request.
-
TooManyRequestsException–The request was denied due to request throttling.
-
ValidationException–The requested action isn't valid.
-
KmsDisabledException–The specified Amazon Web Services KMS key isn't enabled.
-
KmsInvalidKeyUsageException–The request was rejected for one of the following reasons:
-
The
KeyUsagevalue of the KMS key is incompatible with the API operation. -
The encryption algorithm or signing algorithm specified for the operation is incompatible with the type of key material in the KMS key (
KeySpec).
For more information, see InvalidKeyUsageException in the Amazon Web Services Key Management Service API Reference.
-
-
KmsInvalidStateException–The key state of the KMS key isn't compatible with the operation.
For more information, see KMSInvalidStateException in the Amazon Web Services Key Management Service API Reference.
-
KmsNotFoundException–The KMS key can't be found.
-
NotFoundException–The request was rejected because the specified resource can't be found.
-
ServiceUnavailableException–The service is unavailable. Wait briefly and retry your request. If it continues to fail, increase your waiting time between retries.
-
UnknownServiceError–The service returned an error code this client does not model.
Source code in docs_src/capo_s3vectors/_services/s3_vectors.py
1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 | |