Daniel.y commited on
Commit
541c1fb
·
unverified ·
2 Parent(s): 6909b06 db3c974

Merge pull request #1423 from tackhwa/main

Browse files

friendly implementation of entity extraction and relationship weight extract for Low-Capability LLMs

Files changed (1) hide show
  1. lightrag/operate.py +3 -3
lightrag/operate.py CHANGED
@@ -152,7 +152,7 @@ async def _handle_single_entity_extraction(
152
  chunk_key: str,
153
  file_path: str = "unknown_source",
154
  ):
155
- if len(record_attributes) < 4 or record_attributes[0] != '"entity"':
156
  return None
157
 
158
  # Clean and validate entity name
@@ -198,7 +198,7 @@ async def _handle_single_relationship_extraction(
198
  chunk_key: str,
199
  file_path: str = "unknown_source",
200
  ):
201
- if len(record_attributes) < 5 or record_attributes[0] != '"relationship"':
202
  return None
203
  # add this record as edge
204
  source = clean_str(record_attributes[1])
@@ -215,7 +215,7 @@ async def _handle_single_relationship_extraction(
215
  edge_source_id = chunk_key
216
  weight = (
217
  float(record_attributes[-1].strip('"').strip("'"))
218
- if is_float_regex(record_attributes[-1])
219
  else 1.0
220
  )
221
  return dict(
 
152
  chunk_key: str,
153
  file_path: str = "unknown_source",
154
  ):
155
+ if len(record_attributes) < 4 or '"entity"' not in record_attributes[0]:
156
  return None
157
 
158
  # Clean and validate entity name
 
198
  chunk_key: str,
199
  file_path: str = "unknown_source",
200
  ):
201
+ if len(record_attributes) < 5 or '"relationship"' not in record_attributes[0]:
202
  return None
203
  # add this record as edge
204
  source = clean_str(record_attributes[1])
 
215
  edge_source_id = chunk_key
216
  weight = (
217
  float(record_attributes[-1].strip('"').strip("'"))
218
+ if is_float_regex(record_attributes[-1].strip('"').strip("'"))
219
  else 1.0
220
  )
221
  return dict(