feat(pg_search): allow extension function schema to be configured - #3759
Open
Sanderhoff-alt wants to merge 1 commit into
Open
feat(pg_search): allow extension function schema to be configured#3759Sanderhoff-alt wants to merge 1 commit into
Sanderhoff-alt wants to merge 1 commit into
Conversation
Strix Security ReviewNo security issues found. Updated for Reviewed by Strix |
Sanderhoff-alt
force-pushed
the
fix/pg-search-function-schema
branch
from
August 24, 2026 10:37
24a5c31 to
b05946a
Compare
- Add HINDSIGHT_API_TEXT_SEARCH_EXTENSION_PG_SEARCH_FUNCTION_SCHEMA configuration parameter (default: "paradedb"). - Validate schema name as PostgreSQL identifier to prevent SQL injection, safely defaulting empty/whitespace to "paradedb". - Pass configured schema through SQLDialect.build_bm25_arm and knowledge_bm25_arm for recall and knowledge pages search. - Update docker-compose template, developer docs, and env examples. - Add test coverage for config validation, recall BM25 arm, and knowledge pages BM25 arm.
Sanderhoff-alt
force-pushed
the
fix/pg-search-function-schema
branch
from
August 24, 2026 10:47
b05946a to
04040c7
Compare
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.
Overview
Fixes #3757.
This PR introduces configuration support for the PostgreSQL
pg_searchfunction schema via theHINDSIGHT_API_TEXT_SEARCH_EXTENSION_PG_SEARCH_FUNCTION_SCHEMAenvironment variable (default:paradedb).Certain managed PostgreSQL cloud providers (and customized PostgreSQL installations) install
pg_searchextension functions (score,boolean,match) under custom schemas such aspgsearchrather than the defaultparadedbschema. This change enables full compatibility with those environments without requiring custom Docker builds or database-level wrapper forwarding functions.Architectural Workflow & Comparison
flowchart TD subgraph Config ["1. Configuration & Startup"] ENV["ENV: HINDSIGHT_API_TEXT_SEARCH_EXTENSION_PG_SEARCH_FUNCTION_SCHEMA"] --> Val{"PG Identifier Validation"} Val -->|"Valid (e.g. pgsearch)"| ConfObj["HindsightConfig.text_search_extension_pg_search_function_schema = 'pgsearch'"] Val -->|"Empty / Unset"| DefaultObj["HindsightConfig.text_search_extension_pg_search_function_schema = 'paradedb'"] Val -->|"Invalid"| Err["Raise ValueError (Prevent Injection)"] end subgraph MemoryRecall ["2. Memory Recall BM25 Query Generation"] ConfObj --> Dialect1["PostgreSQLDialect.build_bm25_arm"] DefaultObj --> Dialect1 Dialect1 --> SQL1["SELECT ... schema.score(id) AS bm25_score<br/>WHERE id @@@ schema.boolean(should => ARRAY[schema.match('text', $4), ...])"] end subgraph KnowledgePages ["3. Knowledge Pages BM25 Query Generation"] ConfObj --> Dialect2["knowledge_bm25_arm"] DefaultObj --> Dialect2 Dialect2 --> SQL2["SELECT ... schema.score(mm.id) AS score<br/>WHERE mm.id @@@ schema.boolean(should => ARRAY[schema.match('name', $3), ...])"] endQuery Generation Comparison
paradedb)pgsearch)paradedb.score(id)pgsearch.score(id)id @@@ paradedb.boolean(...)id @@@ pgsearch.boolean(...)paradedb.match('text', $4)paradedb.match('context', $4)paradedb.match('text_signals', $4)pgsearch.match('text', $4)pgsearch.match('context', $4)pgsearch.match('text_signals', $4)paradedb.match('name', $3)paradedb.match('content', $3)pgsearch.match('name', $3)pgsearch.match('content', $3)Configuration Reference
HINDSIGHT_API_TEXT_SEARCH_EXTENSION_PG_SEARCH_FUNCTION_SCHEMApg_searchfunctions (score,boolean,match).paradedbparadedb,pgsearchFallback & Validation Behavior
unsetparadedb""(Empty string) /" "paradedb"pgsearch"/"PgSearch"pgsearch"123schema"/"pg-search"/"bad;DROP TABLE"ValueErrorDesign Note: Function Schema (
paradedb) vs. Tokenizer Schema (pdb)ParadeDB
pg_searchuses a dual-schema architecture by design:paradedbby default): Hosts query-time functions (score(),boolean(),match()). This is the extension's target schema specified viaCREATE EXTENSION pg_search SCHEMA <name>or configured by cloud distributions.pdb): Hosts pseudo-types for index-time column casting (e.g.(text::pdb.icu),(text::pdb.jieba)). This is an auxiliary schema created by ParadeDB's internal installation DDL (CREATE SCHEMA IF NOT EXISTS pdb;), independent of the target schema.Why the Tokenizer Schema (
pdb) is Kept Fixedpgsearchstill provide standard tokenizer types underpdb(e.g.pdb.icu).pdbtype namespace, as doing so would break ParadeDB's canonical cast syntax across tooling.Technical Changes Summary
hindsight-api-slim/hindsight_api/config.pyHindsightConfigfield, PostgreSQL identifier regex validation, and normalization.hindsight-api-slim/hindsight_api/engine/sql/base.pySQLDialect.build_bm25_arminterface withpg_search_function_schema.hindsight-api-slim/hindsight_api/engine/sql/postgresql.pyhindsight-api-slim/hindsight_api/engine/sql/oracle.pyPostgreSQLDialect.build_bm25_armandknowledge_bm25_arm.hindsight-api-slim/hindsight_api/engine/search/retrieval.pyhindsight-api-slim/hindsight_api/engine/memory_engine.pyHindsightConfigto dialect arm builders..env.exampledocker/docker-compose/pg_search/docker-compose.yamlhindsight-docs/docs/developer/configuration.mdhindsight-api-slim/tests/test_config_validation.pyhindsight-api-slim/tests/test_db_abstraction.pyhindsight-api-slim/tests/test_knowledge_bm25_dispatch.pyTest & Validation Matrix
test_config_validation.pytest_db_abstraction.pytest_knowledge_bm25_dispatch.pytest_env_template.pyty check hindsight_api/lint.sh