Skip to content

ci(hybrid-search): test pg_textsearch + pg_vectorsearch hybrid search queries - #226

Draft
erimatnor wants to merge 3 commits into
mainfrom
feature/hybrid-search-ci-tests
Draft

erimatnor wants to merge 3 commits into
mainfrom
feature/hybrid-search-ci-tests

Conversation

@erimatnor

@erimatnor erimatnor commented Sep 1, 2026 •

Copy link
Copy Markdown
Member

Adds CI coverage for the hybrid search patterns pg_textsearch and pg_vectorsearch are designed to support together: Reciprocal Rank Fusion over two ranked CTEs, and filter-then-rerank in both directions.

The corpus is synthetic, five topics with disjoint vocabulary and one-hot embeddings, so the correct answer is known by construction and the suite is fast and network-free. Each case checks that results are a duplicate-free subset of an independently computed recall set, which catches join-wiring mistakes a topic-only check would miss.

Building pg_textsearch is the expensive part, so it is split from running the tests. build-pg-textsearch.sh and install-pg-textsearch.sh are the single build path for local runs and CI, the setup-pg-textsearch composite action caches the staged build keyed on the pinned release tag, and textsearch-hybrid.sh either reuses that stage or builds from source.

The architecture note's RRF example uses a FULL JOIN between the two ranked lists, since an inner join drops documents found by only one signal, and gives each CTE its own ORDER BY ... LIMIT. It also documents how each index scan sizes its output: PRISM from the query's LIMIT, pg_textsearch from the planner-recorded limit with a batched fallback, and that only documents with term overlap appear at all.

@github-actions

github-actions Bot commented Sep 1, 2026 •

Copy link
Copy Markdown

📊 Coverage Report

------------------------------------------------------------------------------
                           GCC Code Coverage Report
Directory: .
------------------------------------------------------------------------------
File                                       Lines    Exec  Cover   Missing
------------------------------------------------------------------------------
src/algo/distance.c                          151     120    79%   185,208,231,254,265,267,327-333,522,530,565,577,579-580,583,595,605,607-608,611,623,633,635-636,639,646
src/algo/distance_avx2.c                     138     134    97%   158,208,254,302
src/algo/hkmeans.c                           290     267    92%   183-184,235-237,268-270,367,369,419,498-500,571,573,575,577,583,593-594,600-601
src/algo/hkmeans.h                             6       6   100%
src/algo/kmeans.c                            450     406    90%   203,225,286,310,323,325-330,370,433,593,677,703,708,710-712,814-816,836,838,852,882-886,908,913,919-920,937-939,967,973,1004-1006,1069
src/algo/kmeans.h                              2       2   100%
src/algo/kmeans_elkan.c                      259     250    96%   72,217,227,270,359,371,429,453,459
src/algo/kmeans_hamerly.c                    175     155    88%   64,85,143,161-163,209-211,227,244-246,275,288-290,303,309,400
src/algo/kmeans_internal.h                     3       3   100%
src/algo/kmeans_lloyd.c                      244     235    96%   355,357-358,363,430-432,457,649
src/algo/simd_utils.h                         18      14    77%   97,99,108,110
src/algo/topk.c                              259     252    97%   89,144,179,205,207,420,431
src/algo/topk.h                                4       4   100%
src/algo/vecops.c                            105     105   100%
src/algo/vecops.h                              5       5   100%
src/core/idset.h                              29      28    96%   58
src/core/memory.h                              4       4   100%
src/core/platform.c                           61      46    75%   68,89,91-92,95-96,98,118,146,149-150,153-154,157-158
src/core/platform.h                            4       4   100%
src/core/types.h                               8       6    75%   128,135
src/index/build_progress.c                    19      15    78%   49,63,106,109
src/index/centroid_build.c                   114     103    90%   60,65,137,162,170,176,180-184
src/index/centroid_build.h                    33      30    90%   165,170,172
src/index/centroid_page.c                     43      43   100%
src/index/centroid_page.h                     89      84    94%   160,164-165,174,176
src/index/centroid_search.c                  402     344    85%   124-126,165,228,237,343-345,377,453,485-487,503,517,519-523,563,585,596,641,704,736,824,878-879,881,883-884,886-887,889,893-898,901-902,904,906,908-910,912,914-917,919,924,928-929
src/index/index_base.h                        10       6    60%   121-124
src/index/index_build.c                      481     440    91%   127,154,214,222,335,387,391-392,606,608,613,618,751,755,768-769,859-860,888,893-894,989-990,1028,1148,1163,1210,1220,1230,1232-1233,1235-1239,1241-1243,1246,1333
src/index/index_build.h                       14      14   100%
src/index/parallel_build.h                    61      58    95%   611,812,814
src/index/parallel_build_leader.c            327     314    96%   275,286,508,586,765-771,810,838
src/index/parallel_build_worker.c            327     325    99%   212,634
src/index/posting_build.c                    526     468    89%   81,118,135,142,145,151-155,159,161,163,165,167-170,172-173,175,177-179,181,184,189,193,196-197,219,229-233,235-245,394,482-483,506,529,1168,1173,1180-1182,1184
src/index/posting_build.h                     34      34   100%
src/index/posting_convert.c                   57      50    87%   75-80,103
src/index/posting_insert.c                   140     133    95%   30,196,224-226,265-266
src/index/posting_page.c                      86      81    94%   24,122-123,134,190
src/index/posting_page.h                     127     127   100%
src/index/posting_scan.c                     309     232    75%   71,73-74,99,154,170,208,210,215,217-218,235,241-245,267,409,425-426,429-431,434-438,441-445,448-450,453-455,457-458,460,469,484-486,488,490-497,506,508-509,512,514,516-517,519-521,525-526,550,556-557,583,607-610,635
src/index/posting_split.c                    421     400    95%   193,322-324,375,399,525,756,801,815,822,824,828,830,844,885,982,987,991,1120-1121
src/index/posting_split.h                     25      22    88%   245,249,252
src/index/query_scan.c                       277     262    94%   123,295,301,324,374,401,414-415,486,546,573,575,642,667-668
src/index/storage.h                           22      21    95%   167
src/pg/amcache.c                             181     173    95%   258,281,306,338-339,441-443
src/pg/bufstorage.c                          241     199    82%   178,363,373,375,378,385,388-391,394-395,397,399,401,403-404,406,410-411,413-415,417-419,423,425,429,433,436,438-440,442,444-445,448-450,452,692
src/pg/build.c                               456     440    96%   371,376,381,417,444,448,482,746,898,992,1348-1349,1359,1361-1362,1400
src/pg/build_progress.c                      105     103    98%   221,223
src/pg/cost.c                                170     165    97%   158-159,356,594,693
src/pg/explain.c                              47      43    91%   39,56-58
src/pg/iam_handler.c                         189     181    95%   136,260,389-391,434,551,553
src/pg/inspect.c                             412     389    94%   65,183-184,213,269-270,307-308,365,413,425-426,439-441,552-553,588-589,677,799,850-851
src/pg/maintenance.c                         345     330    95%   231-234,291-292,416-417,422,909,927,1003-1004,1092-1093
src/pg/meta.h                                  4       4   100%
src/pg/parallel_backend.c                    400     392    98%   114,349,360,600-601,791,837,877
src/pg/rabitq_params_pg.c                     35      34    97%   95
src/pg/rabitq_pg.c                           153     148    96%   52,85,102,164,340
src/pg/scan.c                                219     197    90%   129,132,134-136,143-149,151,304,534,591-596,598
src/pg/scan_bound.c                           98      84    85%   137,140,142-144,146-147,149-150,152-154,277,417
src/pg/support_pg.c                           80      78    97%   441,445
src/pg/typeinfo.c                             18      16    88%   76,78
src/pg/typeinfo.h                             14      13    92%   167
src/pg/vec16_pg.c                            236     221    93%   88,108,166,249,251-252,254,256-257,259,261-262,264,483,504
src/pg/vec32_pg.c                            218     204    93%   67,87,146,220,222-223,225,227-229,231,271,409,430
src/quant/fast_rotate.c                      254     137    53%   111-112,165,167,169,171,173-176,180,185,188-190,192,194-197,199,203,206-208,213,218,220-221,226-227,230,232-233,241,243-244,246,343-345,347-350,383,386-392,395-396,398-402,404,406-407,411,413-414,416,418-419,421-424,427,429,431-434,439-440,442-445,452,454-455,458-460,462-467,470,473-475,477-480,486-487,489-492,494,496-497,499,635,642
src/quant/fastscan.c                         267     244    91%   103,254,256,406-407,500-505,572,592,597,599-600,604-607,614,635,638
src/quant/fastscan.h                           4       4   100%
src/quant/fastscan_avx2.c                     50      50   100%
src/quant/matrix.c                           122      90    73%   114,182,221,243,251,259,313,316-318,340,349,351-353,355-356,358,361,369,373,375-376,379,425,427-428,441,446,451,465-466
src/quant/rabitq.c                           607     492    81%   167-170,212-214,257,265,277,386,403,411,413-414,416,441,445-446,459,491,499,528,532-533,568,571,596,651-657,735,750,755,757,763-770,792-793,826,830,875,884,897,906,943-944,947-948,958,960-961,963-965,967,969-973,975-976,978-979,982,986,988-989,991-997,1001,1008,1010,1012-1014,1016,1026-1027,1030,1054,1059-1060,1069-1071,1096,1103-1106,1159,1236,1342,1386,1424,1473,1511,1525
src/quant/rabitq.h                             8       8   100%
src/quant/rabitq_avx2.c                      108     108   100%
src/standalone/api.c                          82      67    81%   37,47,49,51,53,61,122-124,140,147,162-165
src/standalone/barrier.c                      47      47   100%
src/standalone/index.c                       368     307    83%   92-99,124-133,155,164,176,186,280,282-287,316,341,344,356-357,379,394,508,525,530-533,543,545,567-569,605,802-809,811-814,841
src/standalone/instr_time.h                    4       4   100%
src/standalone/latch.c                        42      40    95%   77-78
src/standalone/memory_sa.c                   163     160    98%   39,108,142
src/standalone/parallel_backend.c            337     328    97%   230,257-259,555,603,607,610,614
src/standalone/parallel_ctx.c                 71      64    90%   40,54,76,102,149-150,157
src/standalone/parallel_scan.c                21      21   100%
src/standalone/pg_compat.h                    36      36   100%
src/standalone/query.c                       158     141    89%   128,140,176,242,244,253-257,312,330,372,374-376,379
src/standalone/shm_toc.c                      53      44    83%   46-47,69,73,91-92,113,116,125
src/standalone/thread_pool.c                 122     122   100%
src/standalone/vec32_source.c                 21      17    81%   29,31-33
src/types/vec16.c                             43      40    93%   126,141,157
src/types/vec16.h                             96      96   100%
src/types/vec32.c                             45      43    95%   30,47
src/types/vec32.h                             34      34   100%
------------------------------------------------------------------------------
TOTAL                                      12943   11810    91%
------------------------------------------------------------------------------

Total Coverage: 91%

📁 View detailed coverage by file

Full HTML report available in artifacts


Coverage report generated by gcovr

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds CI coverage for pg_textsearch + meerkat hybrid-search query patterns (RRF and both “recall → rerank” directions), plus supporting CI build/install/caching plumbing and documentation updates.

Changes:

  • Add a new SQL compatibility test suite that validates hybrid query correctness and asserts index usage for each recall step.
  • Add CI scripts and a composite action to build/cache/install pg_textsearch and run the hybrid-search test on a temporary PostgreSQL 18 instance.
  • Update docs/architecture.md hybrid-search examples and document a planner/LIMIT gotcha for ordered index scans.

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
test/pg/compat/hybridsearch.sql New SQL test suite covering RRF and both hybrid filter-then-rerank directions.
scripts/ci/textsearch-hybrid.sh CI/local runner that provisions a temp PG instance, installs pg_textsearch + meerkat, and runs the SQL suite.
scripts/ci/install-pg-textsearch.sh Installs a DESTDIR-staged pg_textsearch build into the active PostgreSQL installation.
scripts/ci/build-pg-textsearch.sh Builds pg_textsearch and stages its install tree for caching/reuse.
docs/architecture.md Fix and expand hybrid-search examples; document ORDER BY-without-LIMIT gotchas.
.github/workflows/hybrid-search.yml New workflow to run hybrid-search CI on PRs/pushes with pinned actions and log artifacts.
.github/actions/setup-pg-textsearch/action.yml Composite action to checkout, cache, build, and install pg_textsearch at a pinned tag.
Suppressed comments (1)

scripts/ci/textsearch-hybrid.sh:89

  • PostgreSQL is started with trust auth and (by default) still listens on localhost TCP. Even with --auth-host=reject, it's safer to explicitly disable TCP listeners for this ephemeral test instance by setting listen_addresses=''.
"$PG_BINDIR/pg_ctl" -D "$PGDATA" -l "$PGLOG" \
    -o "-p $PGPORT -k $TMPDIR_BASE -c shared_preload_libraries=pg_textsearch" \
    start

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

PGLOG="$TMPDIR_BASE/postgres.log"

echo "==> Creating temporary PostgreSQL instance (port $PGPORT)"
"$PG_BINDIR/initdb" -D "$PGDATA" --no-locale -E UTF8 -A trust > /dev/null
@erimatnor
erimatnor force-pushed the feature/hybrid-search-ci-tests branch from 614df56 to ae8c8b3 Compare September 1, 2026 21:42
@erimatnor
erimatnor force-pushed the feature/hybrid-search-ci-tests branch from ae8c8b3 to 22fce19 Compare September 9, 2026 06:58
The RRF example used an inner JOIN between the two ranked CTEs, which
silently drops any document found by only one signal -- defeating the
stated point of fusing independent rankings. Use a FULL JOIN between the
two ranked lists instead. A LEFT JOIN from the base table with an
IS NOT NULL OR filter also keeps every candidate, but the planner cannot
push that OR into the joins and ends up scanning the whole base table to
fuse two short lists; the FULL JOIN touches only the candidates. Each
CTE also gets its own ORDER BY ... LIMIT, since a window function does
not restrict which rows survive.

Also documents how each index scan sizes its output, since the two work
differently. A PRISM scan sizes its top-k from the query's LIMIT,
including inside a CTE, and returns what work_mem affords when there is
no usable LIMIT; prism.query_limit caps it by hand. A pg_textsearch scan
learns the LIMIT through the planner, and without one scores a
default_limit batch and re-runs with a doubled batch while the executor
keeps pulling; it only ever emits documents with nonzero term overlap.
The safe pattern is a direct LIMIT on each signal's own recall CTE.
… queries

Adds CI coverage for the hybrid search patterns pg_textsearch and
pg_vectorsearch are jointly designed to support: Reciprocal Rank Fusion via
dual CTEs, and filter-then-rerank in both directions (BM25 recall with
vector rerank, and vector recall with BM25 rerank). The test corpus is
synthetic rather than a real dataset -- five topics with disjoint
vocabulary and one-hot embeddings -- so the correct answer is known by
construction instead of derived from whatever the query happens to
return, and the suite stays fast and network-free.

Building pg_textsearch is the expensive, cacheable part, so it is
split out from running the tests: build-pg-textsearch.sh and
install-pg-textsearch.sh are the single build/install path shared by
local runs and CI, and the new setup-pg-textsearch composite action
wraps them with a cache keyed on the pinned release tag, mirroring how
setup-pg-debug caches PostgreSQL itself. textsearch-hybrid.sh then
either reuses that staged build (CI) or builds from source directly
(local dev, no cache involved).
build-pg-textsearch.sh passed STAGE_DIR straight through to
`make -C "$SRC_DIR" ... install DESTDIR="$STAGE_DIR"`. -C changes make's
working directory to $SRC_DIR before DESTDIR is evaluated, so a relative
STAGE_DIR resolved against that new directory instead of the caller's --
landing the staged files a level deeper than expected (pg_textsearch/.stage
became pg_textsearch/pg_textsearch/.stage) and leaving the real target
empty. This is exactly what the CI workflow hits, since the composite
action passes the relative "pg_textsearch/.stage"; local runs happened to
dodge it because textsearch-hybrid.sh always hands the script an absolute
path via mktemp. Canonicalize both paths up front so the ambiguity can't
arise regardless of caller.
@erimatnor
erimatnor force-pushed the feature/hybrid-search-ci-tests branch 2 times, most recently from 8024277 to 23ff98f Compare September 28, 2026 22:43
@erimatnor erimatnor changed the title ci(hybrid-search): test pg_textsearch + meerkat hybrid search queries ci(hybrid-search): test pg_textsearch + pg_vectorsearch hybrid search queries Sep 29, 2026
@erimatnor
erimatnor marked this pull request as draft November 10, 2026 10:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants