perf(agent): cache lowercased entity names and early-exit in resolve_or_create

resolve_or_create allocated a fresh lowercased String for every entity
on every call (this runs per extracted mention during entity/relation
extraction) and never short-circuited on an exact dist == 0 match,
scoring every remaining entity regardless. Add Entity::name_lower,
computed once at construction (add_entity, and schema.rs's direct-push
load path), and break out of the scan as soon as an exact match is
found.

INT-12
This commit is contained in:
ClawHDF5 Coding Agent
2026-08-17 00:32:20 +00:00
parent 934d053f92
commit 4051d5c16e
2 changed files with 35 additions and 10 deletions
+1
View File
@@ -480,6 +480,7 @@ fn load_knowledge_group(file: &clawhdf5::File) -> Result<KnowledgeCache, MemoryE
cache.entities.push(crate::knowledge::Entity {
id: entity_ids[i] as u64,
name: entity_names[i].clone(),
name_lower: entity_names[i].to_lowercase(),
entity_type: entity_types[i].clone(),
embedding_idx: emb_idxs[i],
..Default::default()