-
Notifications
You must be signed in to change notification settings - Fork 0
perf: force custom plans for the non-inlined retrieval RPCs (round 2, phase 6) #484
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| -- Force custom plans for the non-inlined retrieval RPCs (scale-readiness F1). | ||
| -- | ||
| -- These functions are LANGUAGE sql/plpgsql with SET search_path, which makes | ||
| -- them non-inlinable: their bodies are planned with unknown parameters, and the | ||
| -- planner cannot estimate trigram/tsv selectivity for an unknown text value. | ||
| -- Once a pooled connection caches the resulting generic plan, every call pays | ||
| -- near-seq-scan strategies — match_document_table_facts_text measured 5.3 s per | ||
| -- call on live pooled connections, ~1.1 s with a custom plan (≈4.8x), and the | ||
| -- answer path fans it out up to 3x in parallel per cold request. | ||
| -- | ||
| -- plan_cache_mode = force_custom_plan is results-identical (it changes only | ||
| -- which plan is used, never which rows qualify), so no retrieval eval gate | ||
| -- applies. Applied to the live Clinical KB Database on 2026-07-11 with | ||
| -- before/after verification (identical row counts, steady-state timings | ||
| -- unchanged, generic-plan mode now unreachable); this migration codifies the | ||
| -- setting for other environments. | ||
| -- | ||
| -- Deliberately NOT included: statement_timeout on these functions. A | ||
| -- function-level SET cannot re-arm the timeout for the statement already in | ||
| -- flight, and a role-level timeout would endanger the minutes-long ingestion | ||
| -- RPCs that run under the same service role. Client-disconnect cancellation of | ||
| -- retrieval RPCs is handled app-side via .abortSignal() (see rag.ts withAbort). | ||
|
|
||
| alter function public.match_document_table_facts_text(text, integer, uuid[], uuid) | ||
| set plan_cache_mode = 'force_custom_plan'; | ||
|
|
||
| alter function public.match_document_memory_cards_hybrid(vector, text, integer, double precision, uuid[], uuid) | ||
| set plan_cache_mode = 'force_custom_plan'; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
This migration changes the canonical function definitions via Useful? React with 👍 / 👎. |
||
|
|
||
| alter function public.match_document_index_units_hybrid(vector, text, integer, double precision, uuid[], uuid) | ||
| set plan_cache_mode = 'force_custom_plan'; | ||
|
|
||
| alter function public.match_document_embedding_fields_hybrid(vector, text, integer, double precision, uuid[], uuid) | ||
| set plan_cache_mode = 'force_custom_plan'; | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This file does not set
search_path, so in any migration/SQL execution context whereextensionsis not already on the path, PostgreSQL cannot resolve the unqualifiedvectortype and the migration aborts before applying the plan-cache settings. The repo installs pgvector in theextensionsschema and most signature checks useextensions.vector; qualify these threeALTER FUNCTIONsignatures (or setsearch_path = public, extensions) to make replay independent of the caller's session state.Useful? React with 👍 / 👎.