Table of Contents
- S3 Vector Bucket Metadata Filtering
- Writing filters
- How values match
- How a filtered query runs
- Indexed metadata keys
- When to index a key
- Adding and removing a key
- States
- Writes while a key is added
- What an indexed key covers
- Filtering in indexed-only mode
- Exact scoring of few matches
- Segments and the size cap
- Storage cost
- Performance
- Limits
S3 Vector Bucket Metadata Filtering
A QueryVectors call can take a filter on the metadata stored with each vector. Only vectors whose metadata matches are candidates for the topK nearest. This page covers the filter syntax, how values match, how a filtered query runs, indexed metadata keys that make filters on chosen keys fast, and what filters cost. For the rest of the API see S3 Vectors API; for setup see S3 Vector Bucket.
s3v.query_vectors(
vectorBucketName="media", indexName="movies",
queryVector={"float32": [0.15, 0.85, 0.15]}, topK=10,
filter={"$and": [{"genre": "scifi"}, {"year": {"$gte": 1978}}]},
returnDistance=True, returnMetadata=True,
)
A filter only narrows a query. It is not access control: see S3 Vector Bucket Security.
Writing filters
| Filter | Matches |
|---|---|
{"genre": "scifi"} |
genre equals "scifi", or is an array that holds "scifi" |
{"genre": {"$eq": "scifi"}}, {"$ne": ...} |
equal / not equal; for an array, holds / does not hold the value |
{"year": {"$gt": 1977}}, $gte, $lt, $lte |
numeric comparison; the operand must be a number ($gt expects a number) |
{"genre": {"$in": ["drama", "western"]}}, $nin |
equal to (for an array, holds) one of / none of the values |
{"tags": {"$exists": true}} |
the key is present (or absent, with false) |
{"$and": [ ... ]}, {"$or": [ ... ]} |
all / any of the sub-filters |
{"genre": "scifi", "year": 2014} |
several keys in one object: all must match |
- An unknown operator is rejected (
unsupported operator $regex). - A filter holds up to 100 constraints, one per comparison on a field:
{"year": 1979}is one,{"year": {"$gte": 1970, "$lt": 1980}}two, and$and/$oradd none of their own.
How values match
- Arrays match by their elements. With
"tags": ["space", "classic"],{"tags": "space"},{"tags": {"$eq": "classic"}}and{"tags": {"$in": ["prison", "space"]}}all match.$neand$ninare their opposites, so{"tags": {"$ne": "space"}}does not match.$gt,$gte,$ltand$ltedo not look inside arrays:{"scores": {"$gt": 2}}does not match"scores": [1, 2.5]. - Types are compared strictly, inside arrays too.
1,"1",trueand"true"are four different values:{"scores": 1}matches[1, 2.5]but not["1", "2.5"], and{"flags": true}matches[true]but not["true"].{"a": 7}matches"a": 7and not"a": "7", and{"a": false}matches onlyfalse. - A missing key matches no
$eq,$inor comparison, and matches every$neand$nin:{"a": {"$ne": "x"}}and{"a": {"$nin": ["x", 7]}}both return vectors that have noa, including vectors with no metadata at all.{"a": {"$exists": false}}returns only those. A filter on a key that no vector has returns nothing for$eq, and every vector for$ne. nullcan be stored ("a": null), andGetVectorsreturns it. Such a vector counts as having the key ($exists: true) and matches$neand$ninof a string or number. A filter cannot test for null:{"a": null}and{"a": {"$ne": null}}are rejected withunsupported filter operand <nil>.- An empty array (
"a": []) has the key and holds nothing, so it matches$exists: true,$neand$nin, and no$eqor$in.{"a": {"$in": []}}matches nothing. - Nested objects are not searched. A dotted path such as
{"info.lang": "fr"}matches nothing, and{"info": {"lang": "fr"}}is rejected withunsupported operator lang. A vector whoseais an object matches$exists: trueand$ne. - Non-filterable keys (
nonFilterableMetadataKeysonCreateIndex) are stored and returned withreturnMetadata, but a filter on one is rejected:metadata key "private" is not filterable. - Array matching needs a gateway and a
weed-vectorof the same release. With an olderweed-vector, a number or boolean can also match a string element with the same text.
The cases in this section were checked through the S3 API on master a91def90c0.
How a filtered query runs
weed-vector turns the filter into a predicate on the Lance table's metadata column and hands it to Lance as a prefilter: the set of matching rows is worked out first, and the vector search then only scores rows in that set.
- Conditions on an indexed key are answered from its scalar index. The rest of this section is about filters on keys without one.
- The prefilter reads every row's metadata. In Lance's query plan for a 1% filter on 50,000 rows (master
4ac3633f1c), building the set of matching rows read the metadata of all 100 fragments, 3.0 MB, and took 34.5 of the query's 36.5 ms; the vector search took about 1 ms. Through the S3 API on mastera91def90c0, a filtered query with the engine's caches off made 3 to 7 times the volume server requests of an unfiltered one (430 against 130 at 50,000 rows, 1,400 against 200 at 200,000), and with the caches warm a filtered query took 50 to 86 ms against 15 ms unfiltered at 50,000 rows, whether 10% or 1% of the rows matched. - Without a vector index the search is exact: every matching row is scored.
- With a vector index (IVF) the search scores matching rows only in the partitions it probes (see S3 Vector Bucket#how-it-works for how many). Unfiltered, this is why a
topKnear the size of the index returns fewer vectors than exist: 4,000 vectors in 63 partitions withtopK4000 returned 1,924 to 2,071. - A short filtered answer falls back to an exact scan (#12802). When a filtered query through the index returns fewer than
topKvectors, or a vector without a finite distance, the engine runs it again as an exact scan of the data the index search covered, which on a single engine is the whole index. On the 4,000-vector index above, a filter that 400 vectors matched returned all 400 fortopK500, and a filter that 5 matched returned all 5 with finite distances fortopK10, on 5 of 5 queries each. The scan costs another pass over the table: with the caches off, a query whose filter matched 5 rows or none made about twice the volume server requests of a 1% filter (833 against 430 at 50,000 rows, 3,000 against 1,400 at 200,000).
Recall at low match counts
The fallback only runs when the answer is short. When the probed partitions hold topK matching rows, those are returned even if better matches sit in partitions that were not probed, so recall can drop below 1 when few rows match. Measured through the S3 API on master a91def90c0, 128 dimensions, cosine, topK 10, 50 queries, recall@10 against an exact search over the matching rows:
| Rows | Matching rows | Recall@10 (worst query) | Results per query |
|---|---|---|---|
| 50,000 | 5,000 (10%) | 1.000 (1.0) | 10 |
| 50,000 | 500 (1%) | 0.992 (0.8 to 0.9) | 10 |
| 50,000 | 5 | 1.000 (1.0) | 5 |
| 200,000 | 20,000 (10%) | 1.000 (1.0) | 10 |
| 200,000 | 2,000 (1%) | 1.000 (1.0) | 10 |
| 200,000 | 20 (0.01%) | 0.968 to 0.972 (0.7 to 0.8) | 10 |
| 200,000 | 5 | 1.000 (1.0) | 5 |
| 50,000 and 200,000 | 0 | 0 |
A filter on an indexed key that matches at most 256 rows is scored exactly, so its recall is 1.
Before #12802, a 20-row filter at 200,000 rows returned 7.8 results out of 10 on average, with recall 0.73, in a local benchmark of the engine's query code on master 4ac3633f1c.
Indexed metadata keys
A metadata filter normally reads every row's metadata and evaluates the JSON for each one. An indexed metadata key keeps a scalar index of the string values a filter compares, so a filter on that key reads the index instead. With the default search mode, indexing a metadata key changes how the filter is evaluated and leaves uncovered rows eligible for the query.
When to index a key
Index a key that your queries filter on with strings, for example {"author": "alice"} or {"genre": {"$in": ["drama", "comedy"]}}, and that you query often. The admin panel lists the keys an index's queries filtered on most in the last hour that are not indexed, with how many queries per hour and their average latency. An engine counts a limited number of keys per index; when it has stopped counting new ones, the panel says the list is partial.
Adding and removing a key
In the admin UI, open the vector bucket: each index has a Metadata indexes panel. + Index a key asks for the key name; a listed key's Index button fills it in. Remove stops indexing a ready key, Cancel a requested or building one.
From weed shell:
s3vectors.index.metadata -bucket embeddings -index articles
s3vectors.index.metadata -bucket embeddings -index articles -add author
s3vectors.index.metadata -bucket embeddings -index articles -remove author
Without -add or -remove the command lists each key with its state, the share of the index's rows its index covers, its segments and its size.
Adding is refused for a key the index declares non-filterable, for a ninth key (an index has at most 8 indexed keys), and while any registered vector engine is too old to fill indexed key columns on its writes.
States
| State | Meaning |
|---|---|
| requested | Recorded on the index's table; the lance_metadata_index worker job has not added the key yet. |
| building | The key's column exists and every write fills it; its index is being built. Queries do not use it yet. |
| ready | Queries use the key's index. |
| off | Being removed. Queries stopped using it at once; the job drops the index and the column. |
A key stays building for at least 3 minutes after its column is added. The job waits that long so that every PutVectors that opened the table before the add has committed, then derives the key's values again for the rows written meanwhile, and only then marks the key ready.
The admin dispatches the job when you add or remove a key from the panel and a worker can run it. A key added with the shell is picked up by the job's detection. The job types start disabled, see Lance Maintenance Worker.
Writes while a key is added
So that the wait above is enough, a PutVectors call must commit within 120 s of the engine opening the index's table, whether or not any key is being added. A call that takes longer fails with InternalFailure (HTTP 500); since PutVectors overwrites by key, sending it again is safe.
What an indexed key covers
| Filter on a ready key | Uses the index |
|---|---|
a string: {"author": "alice"}, {"author": {"$eq": "alice"}} |
yes |
$in of strings: {"author": {"$in": ["alice", "bob"]}} |
yes |
| either, ANDed with other conditions | yes; the other conditions still apply to the rows the index finds |
numbers, booleans, $in mixing strings with other types |
no |
$ne, $nin, $exists |
no |
inside $or |
no |
A string value matches a stored string and the string elements of a stored array, exactly as without the index. Filters the index does not cover read the metadata as before.
Filtering in indexed-only mode
Indexed-only queries consider only fragments covered by the vector index and by every metadata index used by the filter. Each condition must be string equality (a bare string or $eq) or $in with string values, and each key must have a ready metadata index. Combine conditions with AND. For example, with author and genre both ready:
{"$and": [{"author": "alice"}, {"genre": {"$in": ["drama", "comedy"]}}]}
An unsupported condition or a key whose index is missing or still building returns ValidationException. A ready key can still have uncovered fragments. lance_metadata_index expands metadata coverage and lance_optimize_indices expands vector coverage. Candidate counting and exact scoring stay within the fragments covered by both.
Exact scoring of few matches
Before searching, the engine counts the rows the indexed conditions match, through the index. When there are at most --exact-match-limit of them (default 256; set with the engine flag or WEED_VECTOR_EXACT_MATCH_LIMIT, 0 turns it off), it scores those rows exactly instead of searching the vector index, so a selective filter gets the exact top-k. Above the limit it searches the vector index with the indexed rows as the prefilter. Counting stops as soon as the count passes the limit.
Segments and the size cap
A key's index is kept as segments ordered by time: the newest one, the head, takes new rows. Once rows written since the last update reach min_unindexed_rows (default 50,000), the job folds them into the head, or starts a new segment once the head holds segment_rows (default 1,000,000). Default queries can still find rows outside the segments by reading the key's column. Indexed-only queries skip those rows. Compaction keeps each segment's rows apart. Both settings are on the job's form in the admin UI.
Storage cost
Each indexed key adds a hidden list column and its index to the index's table. The index measured about 2.6 bytes per row with 1,000 distinct values (2.7 MB for 1M rows).
Performance
Median latency of a filtered query through the S3 API on master a91def90c0, single engine, Go volume server, 128 dimensions, cosine, IVF index, topK 10, second of two rounds, on a shared host (load average 14 to 37 in these rounds). S3 Vector Bucket Performance#filtered-queries has the full tables, the first rounds, the commands and the setup.
| Filter | 50k, warm | 50k, caches off | 200k, warm | 200k, caches off |
|---|---|---|---|---|
| none | 15 ms | 86 to 106 ms | 38 to 40 ms | 79 to 113 ms |
| 10% of rows | 86 ms | 119 to 122 ms | 235 to 432 ms | 258 to 295 ms |
| 1% | 50 to 53 ms | 82 to 86 ms | 211 to 240 ms | 309 to 452 ms |
| 0.01% (20 rows) | 425 to 532 ms | 455 to 550 ms | ||
| 5 rows | 96 to 243 ms | 136 to 359 ms | 432 to 451 ms | 413 to 434 ms |
| no rows | 156 to 167 ms | 139 to 171 ms | 400 to 442 ms | 464 to 472 ms |
The ranges cover the two placements of the matching rows, scattered over the index or written together; neither was consistently faster. At 50,000 rows the 0.01% author has 5 rows and is in the "5 rows" line.
These are filters on a key without an index. In a separate run at 50,000 rows with the key indexed, filters matching 10% of the rows down to 5 rows took 12 to 23 ms, and recall@10 was 1.000 up to 256 matching rows: see S3 Vector Bucket Performance#with-indexed-metadata-keys.
Limits
The limits on metadata size, filterable metadata, nonFilterableMetadataKeys and filter constraints are in S3 Vector Bucket#limits. An index has at most 8 indexed metadata keys, each holding string values.
Introduction
- Quick Start with weed mini
- Simplest S3 Bucket and User Setup
- Components
- Blob Store Architecture
- Getting Started
- Production Setup
- A typical step‐by‐step example
- Benchmarks
- FAQ
- Applications
API
Configuration
- Replication
- Store file with a Time To Live
- Failover Master Server
- Erasure coding for warm storage
- EC Bitrot Detection
- Server Startup via Systemd
- Environment Variables
Filer
- Filer Setup
- Directories and Files
- File Operations Quick Reference
- Data Structure for Large Files
- Filer Data Encryption
- Filer Commands and Operations
- Filer JWT Use
- TUS Resumable Uploads
Filer Stores
- Filer Cassandra Setup
- Filer Redis Setup
- Super Large Directories
- Path-Specific Filer Store
- Choosing a Filer Store
- Customize Filer Store
Management
Advanced Filer Configurations
- Migrate to Filer Store
- Migrate Between Filer Stores
- Add New Filer Store
- Filer Store Replication
- Filer Active Active cross cluster continuous synchronization
- Filer as a Key-Large-Value Store
- Path Specific Configuration
- Filer Change Data Capture
- Filer Operation Serialization
FUSE Mount
- Mount on Windows
- FIO benchmark
- fstab and systemd mount
- POSIX Compliance
- Distributed POSIX Locks
- P2P reading in weed mount
- Mount over the Internet
WebDAV
SFTP Server
Cloud Drive
- Cloud Drive Benefits
- Cloud Drive Architecture
- Configure Remote Storage
- Azure Blob Storage Authentication
- Mount Remote Storage
- Cache Remote Storage
- Cloud Drive Quick Setup
- Gateway to Remote Object Storage
AWS S3 API
- Amazon S3 API
- Supported APIs vs Minio
- S3 Lifecycle
- S3 Lifecycle vs Volume TTL
- S3 Conditional Operations
- S3 CORS
- S3 Object Lock and Retention
- S3 Object Versioning
- S3 RenameObject
- S3 API Benchmark
- S3 API FAQ
- S3 Bucket Quota
- S3 Rate Limiting
- S3 API Audit log
- S3 Nginx Proxy
- Docker Compose for S3
- Image Gateway
S3 Table Bucket
- S3 Table Bucket
- S3 Table Bucket Commands
- S3 Tables Security
- SeaweedFS Iceberg Catalog
- Iceberg REST Catalog API
- Iceberg Table Maintenance
- SeaweedFS Lance Catalog
- Lance Maintenance Worker
S3 Vector Bucket
- S3 Vector Bucket
- S3 Vectors API
- S3 Vector Bucket Metadata Filtering
- S3 Vector Bucket Security
- S3 Vector Bucket Performance
Iceberg Integrations
- Spark Iceberg Integration
- Trino Iceberg Integration
- Dremio Iceberg Integration
- DuckDB Iceberg Integration
- Doris Iceberg Integration
- RisingWave Iceberg Integration
- Lakekeeper Iceberg Integration
- OLake Go Iceberg Integration
Lance Integrations
S3 Authentication & IAM
- S3 Configuration - Start Here
- S3 Credentials (
-s3.config) - OIDC Integration (
-s3.iam.config) - STS - Temporary Credentials
- Kubernetes ServiceAccount Authentication (IRSA-style)
- S3 Policy Variables
- S3 Policy Conditions
- S3 Bucket Policies
- Amazon IAM API
- AWS IAM CLI
- weed shell - Shell IAM Commands
Server-Side Encryption
S3 Client Tools
- AWS CLI with SeaweedFS
- s3cmd with SeaweedFS
- rclone with SeaweedFS
- restic with SeaweedFS
- nodejs with Seaweed S3
Machine Learning
HDFS
- Hadoop Compatible File System
- run Spark on SeaweedFS
- run HBase on SeaweedFS
- Run Trino on SeaweedFS
- Hadoop Benchmark
- HDFS via S3 connector
Replication and Backup
- Async Replication to another Filer [Deprecated]
- Async Backup
- Async Filer Metadata Backup
- Async Replication to Cloud [Deprecated]
- Kubernetes Backups and Recovery with K8up
Metadata Change Events
Messaging
- Structured Data Lake with SMQ and SQL
- Seaweed Message Queue
- SQL Queries on Message Queue
- SQL Quick Reference
- PostgreSQL-compatible Server weed db
- Pub-Sub to SMQ to SQL
- Kafka to Kafka Gateway to SMQ to SQL
Use Cases
Operations
- System Metrics
- weed shell
- Data Backup
- Deployment to Kubernetes and Minikube
- Helm Chart Recipes
- Deployment with seaweed-up
Rust Volume Server
Advanced
- Large File Handling
- Optimization
- Optimization for Many Small Buckets
- Volume Management
- Fixing Damaged Volumes
- Tiered Storage
- Cloud Tier
- Cloud Monitoring
- Load Command Line Options from a file
- SRV Service Discovery
- Volume Files Structure
Security
- Security Overview
- Security Configuration
- Cryptography and FIPS Compliance
- Run Blob Storage on Public Internet