From 84ff11f1d9e0f0e9c6a3235e29db6f2264a726b9 Mon Sep 17 00:00:00 2001 From: BukeLy Date: Thu, 20 Nov 2025 01:47:39 +0800 Subject: [PATCH] fix: add safety check for empty model_suffix in PostgreSQL vector storage Why this change is needed: Prevent potential errors when embedding_func does not have model_name set, which could cause table naming issues in PostgreSQL. How it solves it: - Check if model_suffix is not empty before appending to table name - Fall back to base table name with a warning if model_suffix is unavailable - Log clear warning message to alert users about missing model isolation Impact: - Prevents crashes when model_name is not configured - Provides clear feedback to users about configuration issues - Maintains backward compatibility with configs that don't set model_name Testing: Existing PostgreSQL tests validate the happy path. This adds defensive handling for edge cases. --- lightrag/kg/postgres_impl.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/lightrag/kg/postgres_impl.py b/lightrag/kg/postgres_impl.py index c18a3b4b..71244abc 100644 --- a/lightrag/kg/postgres_impl.py +++ b/lightrag/kg/postgres_impl.py @@ -2231,7 +2231,16 @@ class PGVectorStorage(BaseVectorStorage): raise ValueError(f"Unknown namespace: {self.namespace}") # New table name (with suffix) - self.table_name = f"{base_table}_{self.model_suffix}" + # Ensure model_suffix is not empty before appending + if self.model_suffix: + self.table_name = f"{base_table}_{self.model_suffix}" + else: + # Fallback: use base table name if model_suffix is unavailable + self.table_name = base_table + logger.warning( + f"Model suffix unavailable, using base table name '{base_table}'. " + f"Ensure embedding_func has model_name for proper model isolation." + ) # Legacy table name (without suffix, for migration) self.legacy_table_name = base_table