Repository navigation
Description
Production search on large projects reads whole tables per query. On a 1 CU Neon compute those reads mostly miss the cache, so a hybrid search running alone has a p50 of 12.8 s, and under MCP fan-out searches time out at 30 s. Full evidence (EXPLAIN plans, Logfire spans, costs): https://github.com/basicmachines-co/basic-memory-cloud/issues/2610#issuecomment-6283405950
Measured on a tenant with 480k vector chunks and 95k FTS chunks, on core 91d83d6 (includes #1746). Four other large tenants show the same shape.
Defects, in priority order
- Admission count (
pgvector_index.PgVectorIndex.search,if admission is not None):SELECT count(*) FROM (... JOIN ... LIMIT :exact_cap)plans as a parallel hash join over both full tables. LIMIT cannot short-circuit the hash build. Measured on a 480k-chunk tenant: 8.2 s cold, 4.2 s warm, 318k pages. Fix ideas: decide from per-project manifest counts (or counts cached per scope and type), or count fromsearch_vector_chunksalone with an index-only scan on(project_id, source_type, embedding_status). Acceptance: under 50 ms and under 1k pages at 480k chunks. - FTS predicate placement (
compile_fts_filter/document_fts_vector_sql): the document-vector predicate and its per-operandEXISTSsubqueries run on every row in scope, before the candidate join, because of the planner's 1-row estimate. Fix ideas: aMATERIALIZEDcandidate CTE joined by primary key, with operand presence computed in one grouped pass oversearch_index_fts_chunksrestricted to candidates (bool_or(tsv @@ op_i)persearch_index_id). Acceptance: pages touched scale with candidate count, not scope size. - Chunk candidate leg uses a seq scan. The GIN index on
search_index_fts_chunks.textsearchable_index_colloses to a seq scan because TOAST is not costed. Each scan detoasts about 375 MB. Make the GIN path explicit. - Count:
PostgresFts.countrepeats the full FTS cost. Replace it with alimit+1has-more probe, or a capped count. - Manifest join: the HNSW candidate path fetches fat
search_vector_chunksheap rows only to check status columns. Add a covering index or move the status columns.
Test
Include a reproduction harness: 300k+ chunk fixture, cold cache (restart, or pg_prewarm off), and report EXPLAIN (ANALYZE, BUFFERS) page counts, not only timings. Warm-cache benchmarks hide all of this. The #1746 numbers were warm.
Cloud is adding a per-tenant search concurrency guard separately. Raising compute is a stopgap only: until the admission count is fixed, its 2.5 GB sweep flushes most of a larger cache.
Activity
claude commentedon Oct 20, 2026
Claude finished @phernandez's task in 17s —— View job
Triage
cloudbecause the impact is on large hosted tenants.Notes
gh search issues).search_vector_chunksalone.EXPLAIN (ANALYZE, BUFFERS)page counts) should be written first. It would let each fix be checked against the targets.FOR UPDATEand no wider transactions.This was triage only. I made no code changes.
perf(core): read FTS chunk candidates from the GIN index
perf(core): count admitted vector chunks from the manifest alone (#1793)
perf(core): run FTS text conditions only on the GIN candidates (#1794)
perf(core): read FTS chunk candidates from the GIN index (#1795)
perf(core): collect multiword FTS operand matches through GIN (#1802)
perf(core): send one-word Postgres text searches through the indexed …