Skip to content
HUIAHUB
VideointermediateRAG, search & data

PostgreSQL Hybrid Search Course – Keyword (BM25) + Vector Retrieval

by freeCodeCamp.orgUploaded Posted 1:00:18 long81K views

Why watchA practical course for developers building PostgreSQL search applications with BM25, vector embeddings, rank fusion, and a FastAPI backend.

What this video covers

This 60-minute freeCodeCamp course, created by Beau, builds a Wikipedia search application using PostgreSQL for keyword retrieval, vector search, and hybrid ranking. The project uses pg_textsearch for BM25, pgvector-scale for vector indexing, and reciprocal rank fusion (RRF) to combine results. A FastAPI backend connects the database to a web interface.

The course starts at 0:00 with the project overview. At 4:06, it introduces the difference between finding matching documents and ranking them. The BM25 section at 7:20 explains inverse document frequency, term frequency, and document length, the factors used to calculate relevance scores.

Database setup begins at 11:39 with Tiger Data Cloud and PostgreSQL. At 14:06, the course covers environment configuration and database extensions, followed by loading Wikipedia data and creating the schema at 15:43. A native PostgreSQL full-text search baseline starts at 20:30, with EXPLAIN ANALYZE used to inspect query plans at 24:38.

At 27:40, the implementation moves to BM25 keyword retrieval through pg_textsearch. The next sections cover constructing search queries, highlighting matches with TS_HEADLINE at 32:32, and handling Boolean conditions and phrase searches at 36:18.

Semantic retrieval begins at 37:32 with embeddings. Vector indexing using pgvector-scale follows at 41:33. At 43:28, the course introduces RRF to combine keyword and semantic rankings. It then examines hybrid query plans at 46:58 and compares keyword, semantic, and hybrid results at 49:12.

The final sections connect a FastAPI backend with connection pooling at 52:13, test the web interface and adjust ranking weights at 54:06, and add records through transactional writes at 55:23. The course finishes at 57:24 with scale benchmarks and optimization topics. The creator also provides a GitHub repository containing the project code.

Written by HuiaHub from the creator's title, description and chapters. All credit for the video goes to freeCodeCamp.org.

Key takeaways

  • Explain how BM25 uses term frequency, document frequency, and document length to rank matches.
  • Configure PostgreSQL extensions and build a keyword search query using pg_textsearch.
  • Generate embeddings and configure vector indexing with pgvector-scale.
  • Combine keyword and semantic rankings using reciprocal rank fusion.
  • Inspect PostgreSQL execution plans with EXPLAIN ANALYZE.
  • Connect search queries to a FastAPI backend and adjust hybrid ranking weights.

Chapters

  1. 0:00Introduction & Project Overview (opens YouTube at this moment)
  2. 4:06Matching vs. Ranking & PostgreSQL Text Search (opens YouTube at this moment)
  3. 7:20Understanding BM25 (IDF, Term Frequency, & Document Length) (opens YouTube at this moment)
  4. 11:39Setting Up Tiger Data Cloud & PostgreSQL (opens YouTube at this moment)
  5. 14:06Environment Setup & Enabling Database Extensions (opens YouTube at this moment)
  6. 15:43Loading Wikipedia Dataset & Schema Setup (opens YouTube at this moment)
  7. 20:30Native PostgreSQL Full-Text Search Baseline (opens YouTube at this moment)
  8. 24:38Analyzing Query Plans with EXPLAIN ANALYZE (opens YouTube at this moment)
  9. 27:40Implementing BM25 Keyword Search with pg_textsearch (opens YouTube at this moment)
  10. 32:32Building the Keyword Search Query & Highlighting (TS_HEADLINE) (opens YouTube at this moment)
  11. 36:18Boolean Conditions & Phrase Search (opens YouTube at this moment)
  12. 37:32Semantic Search Fundamentals & Generating Embeddings (opens YouTube at this moment)
  13. 41:33Vector Indexing with pgvector-scale (opens YouTube at this moment)
  14. 43:28Reciprocal Rank Fusion (RRF) for Hybrid Search (opens YouTube at this moment)
  15. 46:58Query Plan Analysis for Hybrid Search (opens YouTube at this moment)
  16. 49:12Comparing Keyword, Semantic, and Hybrid Results (opens YouTube at this moment)
  17. 52:13Connecting the FastAPI Backend & Connection Pooling (opens YouTube at this moment)
  18. 54:06Testing the Web Interface & Weight Tuning (opens YouTube at this moment)
  19. 55:23Adding New Records via Transactional Writes (opens YouTube at this moment)
  20. 57:24Scale Benchmarks & Next Steps for Optimization (opens YouTube at this moment)

Sources

More videos

All videos