fix(postgres): stop rebuilding every BM25 index on startup - #55
Merged
Merged
Conversation
ensureBM25IndexConfig compared the quoted form text_config='<cfg>' against pg_get_indexdef(), which renders the option unquoted (text_config=simple). The check could never match, so every startup dropped and rebuilt every BM25 index and logged 'BM25 index text_config differs' with a current_def that already carried the wanted config. On an instance with ~90 collections that is ~90 index rebuilds per start (186 such log lines over two restarts). Extract the value from the index definition instead, accepting both the quoted and the unquoted form, and compare it case-insensitively. A different config still triggers the rebuild, as before. The bug came in with the env-configurable text_config (mudler#52). Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Stefan Walcz <stefan.walcz@walcz.de>
mudler
approved these changes
Sep 30, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
ensureBM25IndexConfigbuilds the expected string astext_config='<cfg>'(quoted) and looks for it in the output ofpg_get_indexdef(). PostgreSQL renders the option unquoted:The check can never match, so every startup drops and rebuilds every BM25 index, even when nothing changed. On our instance (~90 collections) that meant ~90 index rebuilds per start: 186 of these log lines over two restarts. It also hides the one case the check exists for, a real config change.
Fix
Extract the
text_configvalue from the index definition with a small regex that accepts the quoted and the unquoted form (including schema-qualified configs such aspublic.de_en), and compare it case-insensitively. A different config still drops the index and triggers the rebuild, as before.The bug came in with the env-configurable
text_config(#52, ours).Tests
rag/engine/postgres_bm25_config_test.go, pure function, no database needed:pg_get_indexdef→ matchtext_configat all → no matchgo test ./rag/engine/ -args -ginkgo.focus=bm25IndexHasTextConfig: 5 passed. Without the fix the new tests do not build (the helper is new).gofmt,go vetclean.🤖 Generated with Claude Code