USMAN’S INSIGHTS
AI ARCHITECT
⌘F
HomeAll Bookspgvector Book
Homepgvector BookRetrieval Engineering
PreviousPostgreSQL Full-Text Search for Lexical RetrievalNext Reranking, Query Rewriting, and Multi-Query 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

Hybrid Search with Reciprocal Rank Fusion

Hybrid search retrieves candidates independently with lexical and vector methods, then combines their ranks. Reciprocal Rank Fusion (RRF) adds 1 / (k + rank) for each list, avoiding direct comparison of incompatible raw scores. Both branches must apply identical authorization and lifecycle policy before fusion, followed by deduplication and measured ranking evaluation.

What will you be able to do?

  • Build lexical and semantic candidate CTEs.
  • Fuse lists with RRF.
  • Preserve security filters in every branch.
  • Deduplicate and inspect branch contribution.
  • Tune fusion using labeled queries.

What is RRF?

For result d, RRF(d) = Σ 1 / (k + rank_i(d)). The constant k reduces the dominance of the first few ranks. k = 60 is a common starting value, not a universal optimum. Candidate depth and optional branch weights also matter.

sql
WITH query_text AS ( SELECT websearch_to_tsquery('english', $1) AS q ), semantic AS ( SELECT c.id, row_number() OVER (ORDER BY c.embedding <=> $2::vector) AS rank FROM app.chunks c WHERE c.tenant_id = $3 AND c.is_visible ORDER BY c.embedding <=> $2::vector LIMIT 50 ), lexical AS ( SELECT c.id, row_number() OVER ( ORDER BY ts_rank_cd(c.search_vector, query_text.q) DESC, c.id ) AS rank FROM app.chunks c CROSS JOIN query_text WHERE c.tenant_id = $3 AND c.is_visible AND c.search_vector @@ query_text.q ORDER BY ts_rank_cd(c.search_vector, query_text.q) DESC, c.id LIMIT 50 ), fused AS ( SELECT id, sum(score) AS rrf_score FROM ( SELECT id, 1.0 / (60 + rank) AS score FROM semantic UNION ALL SELECT id, 1.0 / (60 + rank) AS score FROM lexical ) candidates GROUP BY id ) SELECT c.id, c.content, fused.rrf_score FROM fused JOIN app.chunks c USING (id) ORDER BY fused.rrf_score DESC, c.id LIMIT 10;

In a normalized schema, join to documents and permissions identically in both branches. Do not retrieve broadly and filter unauthorized rows after fusion.

How do you improve diversity?

Limit chunks per document, collapse near duplicates, or use a diversity reranker after fusion. Preserve why each candidate appeared—lexical, semantic, or both—so debugging is possible.

How do you verify it?

Evaluate lexical, semantic, and hybrid with the same labels and filters. Slice exact-ID, paraphrase, multilingual, and mixed-intent queries. Sweep candidate depth, RRF constant, and branch weights on development data, then report held-out metrics and latency.

What breaks in production?

  • Only one branch enforces authorization.
  • Raw cosine and text rank scores are added directly.
  • Candidate depth is too small for fusion to recover results.
  • Duplicate chunks dominate top-k.
  • Fusion hides which subsystem regressed.

AI pair-work prompt

Review this hybrid search SQL and evaluation [paste]. Verify identical policy predicates, deterministic ranks, metric/operator correctness, fusion math, duplicate handling, candidate depth, and observability. Propose a development-grid and held-out test.

Verification contract: Hybrid must beat or deliberately trade against both single branches on defined query slices, not merely on one aggregate.

Check your understanding

  1. Why does RRF use rank instead of raw scores?
  2. Where must authorization be applied?
  3. Add a per-document result cap after fusion.

Official references

  • pgvector hybrid search guidance
  • PostgreSQL window functions