Skip to main content
Version: latest

agrag.ingestion.resolved_entities.write_matches_and_rebuild

write_matches_and_rebuild(decisions:list[MatchDecision], *, graph_store:GraphStore, schema:GraphSchema, members:list[Entity], pending_job_id:str | None = None, deferred:DeferredWrites | None = None, tracer:Tracer | None = None, vector_sync:VectorSync | None = None, model_blocks:Sequence[tuple[UUID, UUID]] = (), llm_enabled:bool = True, pending_pair_id:str | None = None, pending_check:Callable[[GraphStoreTransaction], Awaitable[None]] | None = None) -> RebuildResult

Persist admitted matches and rebuild each component they change.

Decisions that would join a keep apart pair, or groups with different number tokens, are refused before any edge is written. The refetch after the admitted writes can return parts that are no longer connected, and each part gets its own resolved entity.

Outside a job, the checks, matches and resolved entities are written in one transaction. For a job's writes they use two transactions, with the resolved-entity summaries between them so a slow summary does not hold the job's lock.

Parameters:

  • decisions (list[MatchDecision]) – The confirmed matches to persist.
  • graph_store (GraphStore) – Where matches and resolved entities are written.
  • schema (GraphSchema) – The schema the members belong to.
  • members (list[Entity]) – The component members the resolved node is computed from.
  • pending_job_id (str | None) – The in-flight Cutover Job's id, tagging the writes until that job commits. None writes untagged rows.
  • deferred (DeferredWrites | None) – Receives writes over committed rows. Required when pending_job_id is set.
  • tracer (Tracer | None) – Passed to description summarization.
  • vector_sync (VectorSync | None) – Removes stale resolved-entity vectors when set.
  • model_blocks (Sequence[tuple[UUID, UUID]]) – Fresh no-match pairs to record as model blocks before the admission check runs.
  • llm_enabled (bool) – Whether a model may summarize the derived entity's description. False keeps this operation LLM-free.
  • pending_pair_id (str | None) – Client-verification pair to check and close in the match write transaction.
  • pending_check (Callable[[GraphStoreTransaction], Awaitable[None]] | None) – Runs in that transaction under the match write lock, before the first write. It raises to abort the write.

Returns:

  • RebuildResult – The rebuilt resolved entities, the derived ids replaced, and the
  • RebuildResult – decisions the admission check refused.

Raises:

  • ValueError – No decisions are supplied, a decision references a member outside the supplied component, or pending_job_id is set and deferred is None.
  • GraphStoreFenceError – The job no longer holds a live lease. Raised under every error policy.
  • ResolvedEntityWriteError – A job's matches were written but its resolved entity was not. The caller must fail the job.