MCPcopy
hub / github.com/HKUDS/LightRAG / _edit_entity_impl

Function _edit_entity_impl

lightrag/utils_graph.py:268–531  ·  view source on GitHub ↗

Internal helper that edits an entity without acquiring storage locks. This function performs the actual entity edit operations without lock management. It should only be called by public APIs that have already acquired necessary locks. Args: chunk_entity_relation_graph: Graph s

(
    chunk_entity_relation_graph,
    entities_vdb,
    relationships_vdb,
    entity_name: str,
    updated_data: dict[str, str],
    *,
    entity_chunks_storage=None,
    relation_chunks_storage=None,
)

Source from the content-addressed store, hash-verified

266
267
268async def _edit_entity_impl(
269 chunk_entity_relation_graph,
270 entities_vdb,
271 relationships_vdb,
272 entity_name: str,
273 updated_data: dict[str, str],
274 *,
275 entity_chunks_storage=None,
276 relation_chunks_storage=None,
277) -> dict[str, Any]:
278 """Internal helper that edits an entity without acquiring storage locks.
279
280 This function performs the actual entity edit operations without lock management.
281 It should only be called by public APIs that have already acquired necessary locks.
282
283 Args:
284 chunk_entity_relation_graph: Graph storage instance
285 entities_vdb: Vector database storage for entities
286 relationships_vdb: Vector database storage for relationships
287 entity_name: Name of the entity to edit
288 updated_data: Dictionary containing updated attributes (including optional entity_name for renaming)
289 entity_chunks_storage: Optional KV storage for tracking chunks
290 relation_chunks_storage: Optional KV storage for tracking relation chunks
291
292 Returns:
293 Dictionary containing updated entity information
294
295 Note:
296 Caller must acquire appropriate locks before calling this function.
297 If renaming (entity_name in updated_data), this function will check if the new name exists.
298 """
299 new_entity_name = updated_data.get("entity_name", entity_name)
300 is_renaming = new_entity_name != entity_name
301
302 original_entity_name = entity_name
303
304 node_exists = await chunk_entity_relation_graph.has_node(entity_name)
305 if not node_exists:
306 raise ValueError(f"Entity '{entity_name}' does not exist")
307 node_data = await chunk_entity_relation_graph.get_node(entity_name)
308
309 if is_renaming:
310 existing_node = await chunk_entity_relation_graph.has_node(new_entity_name)
311 if existing_node:
312 raise ValueError(
313 f"Entity name '{new_entity_name}' already exists, cannot rename"
314 )
315
316 new_node_data = {**node_data, **updated_data}
317 new_node_data["entity_id"] = new_entity_name
318
319 if "entity_name" in new_node_data:
320 del new_node_data[
321 "entity_name"
322 ] # Node data should not contain entity_name field
323
324 if is_renaming:
325 logger.info(f"Entity Edit: renaming `{entity_name}` to `{new_entity_name}`")

Callers 1

aedit_entityFunction · 0.85

Calls 15

compute_mdhash_idFunction · 0.85
setFunction · 0.85
make_relation_chunk_keyFunction · 0.85
_persist_graph_updatesFunction · 0.85
get_entity_infoFunction · 0.85
getMethod · 0.45
has_nodeMethod · 0.45
get_nodeMethod · 0.45
infoMethod · 0.45
upsert_nodeMethod · 0.45
get_node_edgesMethod · 0.45

Tested by

no test coverage detected