- Newest
- Most votes
- Most comments
Hi! The AI's answer is wrong, so please don't follow it. Two problems.
-
There is no
FilterExpressionparameter. S3 Vectors takes a MongoDB-style JSONfilterdocument, not a SQL-like expression string. -
$gt,$gte,$ltand$lteonly work on numbers. Strings support$eq,$ne,$in,$ninand$exists, nothing else. There is no lexicographic comparison, so"publication_date": "2025-10-09"can't be range-filtered at all, no matter how correct the ISO 8601 formatting is. See Metadata filtering.
Store dates as numbers instead, either YYYYMMDD (20260701) or epoch seconds if you need time-of-day granularity. Whichever you pick, use it for every vector in the index.
resp = client.query_vectors( vectorBucketName="my-bucket", indexName="my-index", topK=10, queryVector={"float32": embedding}, filter={"$and": [ {"publication_date": {"$gte": 20240101}}, {"publication_date": {"$lte": 20251231}}, ]}, returnMetadata=True, )
If the records themselves cover a date range, such as events with a start and an end, flip the comparisons to get overlap:
filter={"$and": [ {"start_date": {"$lte": window_end}}, {"end_date": {"$gte": window_start}}, ]}
answered a month ago
Yes, you can filter based on the publication_date field in your S3 Vectors index even when it's stored as a string. By default, all metadata attached to vectors is filterable unless explicitly specified as non-filterable during vector index creation.
For datetime filtering, you should use a consistent ISO 8601 format for your dates, such as "2025-10-09" or more precisely "2025-10-09T12:30:10+00:00" if you need time components. This standardized format allows for proper string comparison when filtering.
When querying, you can filter based on this date string using string comparison operators. For example:
# Filter for documents published after a certain date response = s3_vectors_client.query_vectors( BucketName="your-s3-vector-bucket-name", IndexName="your-vector-index-name", QueryVector=[0.1, 0.2, 0.3, ...], FilterExpression="publication_date > '2024-01-01'" ) # Filter for documents within a date range response = s3_vectors_client.query_vectors( BucketName="your-s3-vector-bucket-name", IndexName="your-vector-index-name", QueryVector=[0.1, 0.2, 0.3, ...], FilterExpression="publication_date >= '2024-01-01' AND publication_date <= '2025-12-31'" )
Keep in mind that S3 Vectors supports string, number, boolean, and list types for metadata. There's a limit of 40 KB total metadata per vector, with filterable metadata limited to 2 KB per vector. If you need to store the original document content but don't need to filter on it, consider marking it as non-filterable during vector index creation to save on your filterable metadata quota.
Sources
Working with S3 Vectors and vector buckets - Amazon Simple Storage Service
Prerequisites for using a vector store you created for a knowledge base - Amazon Bedrock
Tutorial: Getting started with S3 Vectors - Amazon Simple Storage Service
Vector indexes - Amazon Simple Storage Service
answered a year ago
Relevant content
asked a year ago
