diff --git a/lightrag/kg/postgres_impl.py b/lightrag/kg/postgres_impl.py index 97d3316c..bcee7fa2 100644 --- a/lightrag/kg/postgres_impl.py +++ b/lightrag/kg/postgres_impl.py @@ -1049,10 +1049,10 @@ class PGGraphStorage(BaseGraphStorage): Returns: Normalized node ID suitable for Cypher queries """ - # Remove quotes - normalized_id = node_id.strip('"') # Escape backslashes + normalized_id = node_id normalized_id = normalized_id.replace("\\", "\\\\") + normalized_id = normalized_id.replace('"', '\\"') return normalized_id async def initialize(self): diff --git a/lightrag/operate.py b/lightrag/operate.py index 84e1364e..f653d479 100644 --- a/lightrag/operate.py +++ b/lightrag/operate.py @@ -157,8 +157,8 @@ async def _handle_single_entity_extraction( return None # Clean and validate entity name - entity_name = clean_str(record_attributes[1]).strip('"') - if not entity_name.strip(): + entity_name = clean_str(record_attributes[1]).strip() + if not entity_name: logger.warning( f"Entity extraction error: empty entity name in: {record_attributes}" ) diff --git a/lightrag/utils.py b/lightrag/utils.py index 37400069..913c39f3 100644 --- a/lightrag/utils.py +++ b/lightrag/utils.py @@ -1385,7 +1385,12 @@ def normalize_extracted_info(name: str, is_entity=False) -> str: name = re.sub(r"(?<=[a-zA-Z0-9])\s+(?=[\u4e00-\u9fa5])", "", name) # Remove English quotation marks from the beginning and end - name = name.strip('"').strip("'") + if ( + len(name) >= 2 + and name.startswith('"') + and name.endswith('"') + ): + name = name[1:-1] if is_entity: # remove Chinese quotes