Skip to content

fix: PostgreSQL custom image with AGE/pg_textsearch + classical hybrid query#23

Merged
Kaiohz merged 1 commit into
mainfrom
feat/add-postgres-image-cd
Apr 26, 2026
Merged

fix: PostgreSQL custom image with AGE/pg_textsearch + classical hybrid query#23
Kaiohz merged 1 commit into
mainfrom
feat/add-postgres-image-cd

Conversation

@Kaiohz
Copy link
Copy Markdown
Collaborator

@Kaiohz Kaiohz commented Apr 26, 2026

Fixes PostgreSQL database on K3s to support both LightRAG and classical hybrid search.

@@ -147,9 +147,9 @@ async def search(
langchain_id AS chunk_id,
content,
langchain_metadata->>'file_path' AS file_path,
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Review du Code

📊 Score: 8/10

✅ Points Positifs

Fix correct et minimaliste :

  • La qualification explicite ag_catalog.to_bm25query résout le problème de résolution de fonction.
  • L'extension pg_textsearch installe ses fonctions dans le schema ag_catalog (Apache AGE), pas dans public. Sans cette qualification, PostgreSQL ne trouve pas la fonction via le search_path par défaut.
  • Changement scope limité (2 lignes) → faible risque de régression.

Sécurité SQL préservée :

  • Les noms de tables/index sont validés par _SQL_IDENTIFIER_RE au constructeur.
  • L'utilisation de f-strings pour les identifiers est sécurisée grâce à cette validation.

🔍 Observations

Le fix fonctionne, mais j'ai relevé quelques points à considérer :

1. Cohérence des dépendances

# Lignes 99-106: _check_extension vérifie pg_textsearch
result = await conn.fetchval(
    "SELECT EXISTS(SELECT 1 FROM pg_extension WHERE extname='pg_textsearch)"
)

Mais to_bm25query vient de Apache AGE (ag_catalog). L'extension age est un prérequis de pg_textsearch.

Suggestion : Ajouter une vérification de l'extension age :

async def _check_extension(self) -> None:
    async with self._pool.acquire() as conn:
        for ext in ["age", "pg_textsearch"]:
            result = await conn.fetchval(
                "SELECT EXISTS(SELECT 1 FROM pg_extension WHERE extname=$1)", ext
            )
            if not result:
                logger.warning(
                    f"Extension {ext} not installed. "
                    f"BM25 ranking requires: CREATE EXTENSION age; CREATE EXTENSION pg_textsearch;"
                )

2. Message de warning à clarifier

Ce message omet age qui est un prérequis. Pour une image PostgreSQL custom (comme indiqué dans le titre de la PR), c'est probablement déjà inclus, mais le message pourrait être plus précis.

3. Schema en constante (optionnel)

Pour éviter les magic strings, on pourrait définir PG_TEXTSEARCH_SCHEMA = "ag_catalog", mais c'est overkill si le schema est fixe.

🎯 Conclusion

Le fix est correct et prêt à merger. Les suggestions ci-dessus sont des améliorations cosmétiques, pas des blockers.

Recommendation: APPROVED

@Kaiohz Kaiohz merged commit 90428d4 into main Apr 26, 2026
1 check passed
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.

1 participant