query_vectors
async
¶
query_vectors(
top_k: TopK,
*,
config_overrides: Optional[AsyncS3VectorsClientConfig] = None,
vector_bucket_name: Optional[VectorBucketName] = None,
index_name: Optional[IndexName] = None,
index_arn: Optional[IndexArn] = None,
query_vector: Optional[VectorData] = None,
filter: Optional[object] = None,
query_mode: Optional[IndexMode] = None,
return_metadata: Optional[bool] = None,
return_distance: Optional[bool] = None,
query_texts: Optional[QueryTextList] = None,
return_scores: Optional[bool] = None,
next_token: Optional[QueryVectorsNextToken] = None,
) -> QueryVectorsOutput
Returns matching vector keys from a vector index ranked by vector similarity, full-text relevance, or both. Specify queryVector to perform a vector search, specify queryTexts to perform a full-text search, or specify both to perform a hybrid search. Full-text search ranks results using BM25. Hybrid search combines the vector and full-text rankings using Reciprocal Rank Fusion (RRF).
Amazon S3 Vectors ranks results by distance for a vector-only search, by BM25 score for a full-text-only search, and by RRF score for a hybrid search. You can optionally include computed distances, relevance scores, and vector metadata in the response. Full-text and hybrid searches require a vector index in ENHANCED mode.
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 setqueryTexts, don't set any metadata filters, and don't request metadata (by keeping thereturnMetadataparameter set tofalseor not specified). -
To use
queryTexts, a metadata filter, orreturnMetadataset totruewith this operation, you must have both thes3vectors:QueryVectorsands3vectors:GetVectorspermissions. If you use any of these options without thes3vectors:GetVectorspermission, Amazon S3 Vectors returns anAccessDeniedException.
-
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(Optional[VectorData], default:None) –The query vector for vector similarity search. The query vector must have the same dimension as the vector index. For example, if the vector index has 384 dimensions, the query vector must also have 384 dimensions. You can omit this parameter when you supply
queryTextsto perform a full-text-only search. A request must includequeryVector,queryTexts, or both. -
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. -
query_texts(Optional[QueryTextList], default:None) –Full-text queries for searchable metadata keys. Omit
queryVectorto run a full-text-only search, or provide both fields to run a hybrid search. Each entry must target a distinct searchable metadata key. -
return_scores(Optional[bool], default:None) –Indicates whether to include relevance scores in the response. Full-text-only results can include BM25 scores. Hybrid results can also include a Reciprocal Rank Fusion (RRF) score and vector distance. This setting doesn't add scores to vector-only requests. 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/async_s3_vectors.py
1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 | |