---
title: Filtered Approximate NN Search (FANNS)
url: https://www.emergentmind.com/topics/filtered-approximate-nearest-neighbor-search-fanns
type: topic
---

# Filtered Approximate NN Search (FANNS)

Filtered Approximate Nearest Neighbor Search (FANNS) is the problem of retrieving vectors that are nearest to a query in embedding space while also satisfying structured filter conditions on associated metadata or labels. A common formulation represents each item as \(I_i=(v_i,a_{i,1},\dots,a_{i,m})\), where \(v_i\) is a \(d\)-dimensional embedding and \(a_{i,l}\) are attributes, and each query as \(Q_j=(q_j,k_j,f_j)\), where \(q_j\) is the query vector, \(k_j\) is the requested result size, and \(f_j\) is a filter function; the goal is to approximately retrieve the top-\(k_j\) closest items satisfying \(f_j\) [2507.21989]. In a more compact constrained form, the exact objective is often written as \(NN(q\mid r)=\arg\min_{o\in D,\,r(o.a)}\|q-o.v\|\) [2508.16263]. FANNS arises in retrieval-augmented generation, recommendation systems, vehicle/person re-identification, face and voice recognition, e-commerce search, and vector databases, where semantic similarity alone is insufficient without metadata validity [2507.21989].

## 1. Formal scope and filter semantics

The core distinction between ordinary ANNS and FANNS is that the nearest-neighbor objective is restricted to a filtered subset. In label-based formulations, each database vector may carry a label set \(f_i\) or \(S_i\), and the query carries a label condition \(f_q\) or \(S_q\). One common discrete multi-label semantics is AND-style filtering, where a candidate is valid only if \(S_q \subseteq S_v\) [2511.04073]. In broader benchmark formulations, supported filter types include exact match on a single attribute (EM), range filtering on an ordered attribute (R), exact match in set (EMIS), multi-attribute variants MEM, MR, MEMIS, and combined filters \(C\) using arbitrary logical operators [2507.21989].

The literature also treats several specialized subproblems as FANNS. Range-filtered ANNS (RFANN or RFANNS) restricts the candidate set by numeric intervals, typically over one or more ordered attributes; an RFANN query can be written as \(q=\langle v, I=[a_l,a_r], k\rangle\), where only objects with attributes in the interval are eligible [2603.12913]. Multi-attribute range filtering generalizes this to conjunctions of intervals \(B=\{b_i=[l_i,r_i]\mid i\in\mathcal{J}\}\) over a subset of attributes [2602.15488]. A more recent extension replaces scalar filters with graph-structured constraints: in ANNGR, each vector is associated with a node in a filter graph, and valid answers must satisfy \(d_G(v_q,v_i)\le r\) for a query node \(v_q\) and graph radius \(r\) [2607.00727].

A related but distinct usage appears in clustering-based ANN. There, “filtered” refers to a first-stage routing step that selects promising clusters before an exact or approximate within-cluster search. In that setting, the corpus is partitioned into \(L\) clusters, search is restricted to \(\ell \ll L\) clusters, and the routing function can itself be optimized as a ranking problem [2412.05921]. This suggests that FANNS terminology spans both metadata-constrained retrieval and internal filter-then-search architectures.

## 2. Taxonomic frameworks and recurring design abstractions

The modern literature does not rely on a single taxonomy. One common axis classifies methods by **when** filtering occurs: pre-filtering, post-filtering, in-filtering, and hybrid indexing. Pre-filtering first identifies items satisfying the predicate and then applies ANN on that subset; post-filtering runs ANN first and discards invalid results afterward; in-filtering integrates the predicate into traversal; hybrid indexing combines vector and attribute structure in a single index [2507.21989]. A closely related benchmark taxonomy uses the operational families filter-then-search, search-then-filter, and hybrid-search [2509.07789]. Database-oriented analysis introduces a similar tripartite distinction of pre-filtering, runtime-filtering, and post-filtering [2602.11443].

A different abstraction classifies FANNS by its primary pruning mechanism rather than by filter timing. The pruning-focused survey distinguishes vector-solely pruning (VSP), vector-centric joint pruning (VJP), scalar-solely pruning (SSP), and scalar-centric joint pruning (SJP). In this view, FANNS performance depends on how vector pruning and scalar pruning are combined, not merely on whether filtering is applied before or after ANN traversal [2505.06501]. This reclassification is motivated by the observation that two algorithms can both be “in-filtering” yet differ substantially in whether scalar constraints affect neighborhood expansion, result maintenance, or index construction.

A third axis classifies methods by their ANN substrate: tree-based, hash-based, graph-based, and quantization-based. This is especially useful because filter support and selectivity sensitivity often track the underlying index geometry. Range-filtering methods frequently exploit segmented edges or segmented subgraphs; label-filtering methods often rely on graph augmentation or label-aware distances; arbitrary filtering methods tend to emphasize subset identification, partitioning, or predicate-agnostic traversal [2508.16263].

Terminology around **selectivity** remains inconsistent. Several benchmark papers define selectivity as the fraction of database items satisfying the filter, for example
\[
\text{selectivity}=\frac{|\{I_i\mid I_i\in D \land f(I_i)=true\}|}{|D|},
\]
which interprets low selectivity as a small matching subset [2507.21989]. By contrast, the pruning-focused survey adopts
\[
sel_{f_s}=1-\frac{|\mathcal{D}_{f_s}|}{|\mathcal{D}|},
\]
and argues that this should denote the fraction excluded by the filter, while the opposite convention is better called specificity [2505.06501]. This terminological divergence is not merely stylistic, because comparative claims about “high” or “low” selectivity can invert across papers.

## 3. Core algorithmic paradigms

A large fraction of FANNS research centers on graph-based search under constrained navigation. Standard graph ANN relies on traversability of a proximity graph, but filtering removes vertices and can create sparse or disconnected induced subgraphs. This motivates label-aware edge construction, filter-aware traversal scores, special entry-point policies, or hybrid exact/approximate fallback mechanisms. In practical terms, the central difficulty is usually not only ranking valid points correctly, but reaching them efficiently when invalid points dominate local neighborhoods [2602.10258].

One influential direction learns a filter-aware distance rather than fixing a hand-tuned penalty. For multiple discrete labels, the learned scoring rule
\[
D(q,v)=d(q,v)+w_m(1-m(q,v))
\]
adds a learned mismatch penalty \(w_m\) to the base vector distance and is used both in graph traversal and in graph construction. The same paper defines a data–data analogue
\[
D(v_1,v_2)=d(v_1,v_2)+w_m\bigl(1-m(S_{v_1},S_{v_2})\bigr),
\]
with an asymmetric Jaccard-style label similarity \(m(S_{v_1},S_{v_2})=\frac{|S_{v_1}\cap S_{v_2}|}{|S_{v_1}|}\) for index construction [2511.04073]. This unifies search-time and build-time filter awareness.

A more general graph design is JAG, or Joint Attribute Graphs, which introduces separate build-time attribute distance \(dist_A\) and query-time filter distance \(dist_F\). For equality filters, for example,
\[
dist_F(a,f)=
\begin{cases}
0,& a=f\\
1,& a\neq f
\end{cases},
\qquad
dist_A(a_1,a_2)=\mathbf{1}[a_1\neq a_2].
\]
For scalar range filters,
\[
dist_A(a_1,a_2)=|a_1-a_2|,
\]
and \(dist_F\) measures distance to the query interval. JAG uses these quantities in lexicographic comparators for graph construction and greedy search, and its Threshold-JAG variant merges edges produced under multiple attribute thresholds to remain robust across selectivity regimes and filter types [2602.10258].

FAVOR takes a related but explicitly selectivity-aware route. It keeps a standard HNSW-like graph, estimates query selectivity \(\hat p\), and routes the query either to pre-filtering brute force when \(\hat p<\lambda\) or to a modified graph search otherwise, with \(\lambda=1\%\) in the reported experiments. Its central mechanism is an exclusion distance: non-target data points receive an added penalty \(D\) in the adjusted distance
\[
\overline{Dis}(\mathbf{q},\mathbf{v})=
\begin{cases}
Dis(\mathbf{q},\mathbf{v}^T), & A\in\mathcal{F}\\
Dis(\mathbf{q},\mathbf{v}^N)+D, & A\notin\mathcal{F}
\end{cases},
\]
so invalid points remain available for connectivity but are pushed away in the traversal order [2605.07770].

Other graph-based methods recast the navigation problem geometrically. Fiber-Navigable Search models the filtered induced subgraph as a **fiber** and computes local filtered-neighborhood density
\[
\rho_S(x)=\frac{|N_S(x)|}{|N(x)|}
\]
and filtered drift
\[
\mathrm{drift}(x)=\frac{1}{|N_S(x)|}\sum_{y\in N_S(x)}(V(y)-V(x)),
\]
where \(V(x)=d(q,x)\), to decide when to remain inside the filtered neighborhood and when to revert to full-graph exploration. It classifies failures into topological cuts, geometric folds, and genuine basins, and handles all three with restarts in a fiber-present cluster identified by a lightweight anchor atlas [2604.00102].

Clustering-based ANN contributes a complementary first-stage filtering perspective. In an IVF-style pipeline, the dataset is partitioned into \(L\) clusters, one representative per cluster is indexed, and the routing function selects the top-\(\ell\) clusters before within-cluster search. “Learning Cluster Representatives for Approximate Nearest Neighbor Search” recasts routing as a supervised learning-to-rank problem: the conventional centroid matrix \(M\) in \(\tau(q)=\arg\max_i^{(\ell)} Mq\) is replaced by a learned matrix \(W\) in \(\acute{\tau}(q;W)=\arg\max_i^{(\ell)} Wq\), so representatives are optimized for routing quality rather than geometric averaging [2412.05921].

Hashing-based FANNS remains relevant as well. Falconn++ augments cross-polytope LSH with locality-sensitive filtering inside hash buckets. After hashing, a point is retained in a bucket only if its projection on the query’s extreme random direction exceeds a threshold \(t=(1-r^2/2)\sqrt{2\ln D}\). The method is analyzed as a locality-sensitive filtering scheme that suppresses far-away points before expensive candidate evaluation, and is reported to improve recall-speed tradeoffs over standard Falconn while remaining competitive with HNSW in high-recall regimes [2206.01382].

## 4. Specialized subfields: range, multi-attribute, logical, and graph-structured filters

Numeric range filtering has produced some of the most structured theory in FANNS. “Approximate Nearest Neighbor Search with Window Filters” formalizes \(c\)-approximate window search by attaching a real label \(\ell(x)\) to each point and restricting retrieval to the subset \(D_{(a,b)}=\{x\in D\mid \ell(x)\in (a,b)\}\). Its \(\beta\)-Window Search Tree stores a standard ANN index at each internal node of a label-partition tree, so any ANN method can be transformed into a window-search index. The query algorithm either recurses into partially covered children or directly invokes the ANN index of a fully covered subtree, and the paper reports up to a \(75\times\) speedup over existing solutions at the same recall level [2402.00943].

A more graph-theoretic range solution is RNSG. The paper first defines the Range-aware Relative Neighborhood Graph (RRNG), whose edges depend on both spatial and attribute proximity: an edge \((x,y)\) is absent if there exists a witness \(z\) that is closer to both \(x\) and \(y\) than they are to each other and whose attribute lies between theirs. RRNG is shown to satisfy monotonic searchability and structural heredity, meaning that a range-induced subgraph remains exactly the RRNG that would have been built on that range alone. RNSG is the practical approximation of this theory, and its reported results include higher query performance, smaller index size, and lower construction cost than prior RFANN methods [2603.12913].

Multi-attribute range filtering introduces combinatorial complexity that single-attribute methods do not address well. KHI combines an attribute-space partitioning tree with single-level HNSW graphs attached to tree nodes. Queries first route through the tree to obtain in-range entry points and then perform greedy graph search while reconstructing only in-range neighbors. The tree uses a skew-aware splitting rule that bounds height by \(O(\log n)\), and the paper reports average QPS gains of \(2.46\times\) over the state-of-the-art baseline and up to \(16.22\times\) on a hard dataset, with larger gains for smaller selectivity, larger \(k\), and higher predicate cardinality [2602.15488].

Garfield addresses the same multi-attribute RFANNS setting from a GPU-systems perspective. Its GMG index partitions data into disjoint cells, builds a local CAGRA graph inside each cell, and adds only a constant number of inter-cell edges, yielding space complexity \(O(n(d+lS))\). Query processing uses cell selection, cluster-guided cell ordering, and a search–jump–search traversal that reuses candidates across cells; large datasets are handled by a cell-oriented out-of-core pipeline. The paper reports a \(4.4\times\) reduction in index size and up to \(119.8\times\) higher throughput than state-of-the-art RFANNS methods [2604.20121].

Logical filters beyond conjunctions of simple predicates motivate cost-based planning. PathFinder converts a filter into disjunctive normal form, optimizes each conjunctive clause with a utility metric
\[
U(G,p)=
\frac{\text{card}(R,p)}
{\sum_{g_i\in G}\text{card}(g_i)\times |G|^\alpha}
\]
when \(G\) covers \(p\), and then merges plans across clauses, optionally borrowing an index on one attribute to process a correlated predicate on another. It supports tree-based graph indexes for numeric predicates and hash-based graph indexes for categorical ones, and reports up to \(9.8\times\) higher query throughput at recall \(0.95\) than the best baseline [2511.00995].

Graph-structured filters form a newer branch of FANNS. In ANNGR, the filter requires results to lie within an \(r\)-hop neighborhood in a predefined graph. DLH transforms this condition into distance-aware labeling sets \(D_i(v)\) derived from Pruned Landmark Labeling and checks in-range status through simplified set intersections over pairs with \(i+j\le r\). Large label sets are compressed with Bloom filters, and DLH-M memoizes query-side hashing. The paper reports throughput improvements of up to \(70.3\%\) while maintaining recall over \(98.5\%\) with limited extra storage [2607.00727].

## 5. Evaluation methodology, benchmark datasets, and workload dependence

Benchmarking has become a major research topic because FANNS results are highly sensitive to dataset construction, filter semantics, and tuning methodology. A central benchmark contribution is **arxiv-for-fanns**, built from embeddings of over 2.7 million arXiv abstracts using `stella_en_400M_v5`, producing normalized 4096-dimensional vectors and 11 real-world attributes including `submitter`, `main_categories`, `authors`, `update_date`, and `number_of_versions`. It provides small, medium, and large scales together with 10k EM, 10k R, and 10k EMIS queries per scale and precomputed ground truth [2507.21989].

Broader comparative studies reinforce that no single algorithm dominates. The transformer-embedding benchmark reports that ACORN supports arbitrary filter types and scales relatively well but is usually outperformed by more specialized methods; SeRF is excellent for ordered range filters but cannot handle categorical attributes; Filtered-DiskANN and UNG are strong on the medium-scale dataset but fail on the large-scale dataset; NHQ variants retain performance relatively well at scale but address AFANNS because they may return non-matching items. The paper’s main conclusion is explicit: no universally best FANNS method exists [2507.21989].

A separate in-depth experimental study proposes a unified FANNS interface and evaluates 10 algorithms and 12 methods across four datasets, using selectivity levels from \(0.1\%\) to \(100\%\). Its component analysis emphasizes the importance of pruning, entry-point selection, and edge-filtering costs. The study concludes that segmented subgraphs are especially effective for range filtering, label filtering remains underdeveloped, and arbitrary filtering is still hard despite ACORN’s flexibility [2508.16263].

Systematic evaluation has also exposed the importance of parameter control. One unified benchmark organizes methods into filter-then-search, search-then-filter, and hybrid-search, explores more than 41,000 parameter combinations, and selects about 1,300 representative full-index parameter sets. Its empirical analysis shows that label length, filter selectivity, \(k\), dataset structure, and scalability each materially affect the QPS–Recall trade-off, and that methods that look strong at recall@1 can diverge substantially as \(k\) increases [2509.07789].

Workload hardness is not explained by selectivity alone. The survey of vector-scalar hybrid FANNS argues that query difficulty also depends on the distribution relationship between filtered subsets and query vectors, introducing in-distribution (ID), partially overlapping distribution (POD), and out-of-distribution (OOD) regimes. It uses UMAP and Mahalanobis distance to study this effect and concludes that selectivity plus distribution factor is a more informative axis than selectivity alone [2505.06501]. A systems paper proposes a related per-query diagnostic, the Global-Local Selectivity correlation metric. With global selectivity
\[
\sigma_g=\frac{|\{v\in\mathcal{D}\mid \phi(v)=1\}|}{N}
\]
and local selectivity
\[
\sigma_l=\frac{|\{v\in\mathcal{N}_q\mid \phi(v)=1\}|}{k},
\]
it defines \(r=\sigma_l/\sigma_g\) and
\[
\rho_q=\frac{r-1}{r+1}\in[-1,1),
\]
so that \(\rho_q>0\) indicates enrichment of valid items near the query and \(\rho_q<0\) indicates depletion [2602.11443].

## 6. Systems integration, practical implications, and open problems

In production vector databases, FANNS is shaped as much by execution architecture as by the underlying ANN index. A comparative analysis of FAISS, Milvus, and pgvector shows that the same HNSW or IVFFlat index can behave quite differently depending on whether filtering is implemented as pre-filtering, runtime-filtering, or post-filtering. The paper reports that Milvus achieves recall stability through hybrid approximate/exact execution, including dual-pool traversal and an adaptive brute-force fallback triggered around 93% filtered out; pgvector’s optimizer frequently prefers ANN-first plans even when exact sequential scans would give perfect recall at comparable latency; and IVFFlat can outperform HNSW for low-selectivity queries because cluster pruning becomes more effective than graph traversal [2602.11443]. This supports the broader systems claim that architecture and query planning can override raw index quality in filtered workloads.

Practical method selection is therefore workload-dependent. For arbitrary filters or mixed attribute types, flexible general-purpose methods such as ACORN or other predicate-agnostic graph designs are attractive, but they are not uniformly best [2507.21989]. For ordered range filters, specialized range-aware structures such as SeRF, iRangeGraph, RNSG, KHI, or Garfield may be preferable, though the best choice depends on selectivity, construction budget, and hardware [2508.16263]. For low-selectivity arbitrary filters, routing between brute-force prefiltering and graph search, as in FAVOR, or engine-level fallback mechanisms, as in Milvus, is often decisive [2605.07770].

The main open problems recur across surveys and benchmarks. Arbitrary filtering remains hard, especially outside narrow selectivity bands and outside carefully targeted predicate families [2508.16263]. Hyperparameter tuning is too important and still poorly automated [2508.16263]. Dynamic indexing is underexplored, particularly for range-aware and segmented structures [2508.16263]. Benchmark realism remains incomplete, motivating richer real-world attributes, correlated vector–metadata distributions, and standardized workloads [2507.21989]. The hybrid-data survey adds workload-aware optimization, better query-difficulty metrics, and more general scalar-filter support to this list [2505.06501].

A plausible implication is that FANNS should no longer be viewed as a single algorithmic niche. The recent literature treats it as a family of constrained retrieval problems whose effective solution depends on filter semantics, selectivity regime, data–attribute correlation, hardware model, and optimizer behavior. That is why contemporary benchmark papers repeatedly conclude that there is no universally best method, only methods whose design assumptions align more or less well with the workload at hand [2507.21989].

Source: https://www.emergentmind.com/topics/filtered-approximate-nearest-neighbor-search-fanns