USMAN’S INSIGHTS
AI ARCHITECT
⌘F
HomeAll Bookspgvector Book
Homepgvector BookRetrieval Engineering
PreviousIVFFlat Indexes from Training to TuningNext PostgreSQL Full-Text Search for Lexical Retrieval
AI NOTICE: This is the table of contents for the SPECIFIC CHAPTER only. It is NOT the global sidebar. For all chapters, look at the main navigation.

On this page

9 sections

Progress0%
1 / 9

Muhammad Usman Akbar Entity Profile

Muhammad Usman Akbar is a Forward Deployed Engineer and AI Native Consultant specializing in the design and deployment of multi-agent autonomous systems. Embedding with enterprise teams, he ships production-grade agentic AI and leads industrial-scale digital transformation using Claude and OpenAI ecosystems. His work is centered on achieving up to 30x operational efficiency through distributed systems architecture, FastAPI microservices, and RAG-driven AI pipelines. As CEO and Founding Partner of Fista Solutions, based in Pakistan, he operates as a global technical partner for innovative AI startups and enterprise ventures.

USMAN’S INSIGHTS
AI ARCHITECT

Transforming businesses into autonomous AI ecosystems. Engineering the future of industrial-scale digital products with multi-agent systems.

30X Growth
AI-First
Innovation

Navigation

  • Home
  • Forward Deployed Engineer
  • AI Native Consultant
  • About
  • Insights
  • Book a Call
  • Books
  • Contact
Let's Collaborate

Have a Project in Mind?

Let's build something extraordinary together. Transform your vision into autonomous AI reality.

Start Your Transformation

© 2026 Muhammad Usman Akbar. All rights reserved.

Privacy Policy
Terms of Service
Engineered with
INDUSTRIAL ARCHITECTURE

Filtered Approximate Search and Iterative Scans

In pgvector approximate searches, ordinary filters are commonly applied as candidates are scanned. A selective tenant, category, or date predicate can therefore leave fewer than the requested top-k rows. Increase search effort, enable iterative scans where supported, add relational indexes, or change physical design with partial indexes or partitioning—then measure recall and latency.

What will you be able to do?

  • Explain why filtered ANN can return too few rows.
  • Use HNSW and IVFFlat iterative scans.
  • Choose between B-tree, partial ANN, and partition strategies.
  • Test strict versus relaxed result order.
  • Tune by filter-selectivity slice.

Why do rows disappear?

If an HNSW scan visits 40 candidates and only 10% pass the filter, roughly four may survive; the exact number depends on data and graph traversal. Raising hnsw.ef_search may help. Current pgvector versions also support iterative scans that continue exploring until enough rows are found or a safety limit is reached.

sql
BEGIN; SET LOCAL hnsw.iterative_scan = strict_order; SET LOCAL hnsw.ef_search = 100; SELECT id, embedding <=> $2::vector AS distance FROM app.chunks WHERE tenant_id = $1 ORDER BY embedding <=> $2::vector LIMIT 10; COMMIT;

strict_order preserves exact distance ordering among found candidates. relaxed_order can improve recall/speed but may need materialization and reordering when strict presentation matters. IVFFlat has corresponding iterative-scan and maximum-probe settings. Confirm setting names and defaults for the installed version.

Which physical design should you use?

  • Add a B-tree index when the relational filter itself is selective and exact vector search over the remaining rows is affordable.
  • Add a partial vector index for a few stable high-value predicates.
  • Partition when many disjoint values, lifecycle, or operational isolation justify it.
  • Avoid one ANN index per tenant when tenant count is large or volatile.

Partial-index predicates must match query semantics and remain maintainable.

How do you verify it?

Build queries at 90%, 10%, 1%, and 0.1% selectivity. For each, compare exact results with ANN using default, higher effort, strict iterative, and relaxed iterative settings. Record result count, recall@k, latency, buffers, and plan. Include tenants with few rows.

What breaks in production?

  • A top-10 API silently returns two rows after adding ANN.
  • One tuning value is used for every filter shape.
  • Relaxed ordering is presented as exact distance order.
  • Thousands of tenant-specific indexes overload maintenance.
  • Query predicates do not imply partial-index predicates.

AI pair-work prompt

Analyze this filtered pgvector workload [queries, selectivity histogram, index DDL]. Propose B-tree, search-effort, iterative-scan, partial-index, and partition experiments. Include exact recall, returned-count, latency, and maintenance tradeoffs for every selectivity slice.

Verification contract: No design passes unless it meets minimum returned-count and recall objectives for the rarest authorized slice.

Check your understanding

  1. Why can post-scan filtering reduce result count?
  2. What tradeoff does relaxed ordering make?
  3. When might exact search after a B-tree filter be best?

Official references

  • pgvector filtering
  • PostgreSQL partial indexes
  • PostgreSQL partitioning