Query icon
Log icon
If icon
SlackIncomingWebhook icon
LoopUntil icon
Delete icon
Schedule icon

Evict stale vectors from a Weaviate class and verify the store is clean

Count, delete and re-verify stale Weaviate objects by a retention key with Kestra behind dry-run and auto-remediate gates.

Categories
AIData

This blueprint keeps a Weaviate class free of stale vectors. In a retrieval store the vectors from a retired or re-ingested source keep matching queries they should no longer answer, which bloats the index and drags retrieval quality down. The flow counts the objects whose retention key matches a target value, deletes them behind a safety gate, then re-queries the store and fails if any stale object is left.

This blueprint was created by zkasuran.

Safety

The flow is read-only by default. It deletes only when auto_remediate is true and dry_run is false. In every other mode it reports the candidate count and the exact filter and changes nothing. After a delete it re-counts the stale objects and fails the run while any remain, so a partial clear never passes as success. The schedule ships disabled and pins both gates to safe mode.

How it works

  1. detect runs a Weaviate Query with searchType: FETCH_OBJECTS and a LIKE filter on retention_property, and counts the matching objects through its size output. fetchType: STORE writes the matched rows, holding only retention_property, to Kestra storage instead of the execution context. Plugin-weaviate 2.0+ has no aggregation, so the count is capped at scan_limit (default 10000, which must not exceed the server's QUERY_MAXIMUM_RESULTS); a larger backlog reads as scan_limit and is still cleared by the loop below.
  2. log_detect records the count, the filter and the current mode.
  3. guard acts only when the count is above zero. It posts a findings alert to Slack so the detection is visible even on a dry run.
  4. When auto_remediate is true and dry_run is false, evict_until_clear runs. It is a LoopUntil that batch-deletes the matching objects through weaviate.Delete, re-counts them, then repeats until the count reaches zero or reverify_timeout elapses. failOnMaxReached fails the run if the backlog is not cleared in time.
  5. In any other mode log_report_only records what would be deleted and the store is untouched.
  6. When nothing is stale, log_clean records that there is nothing to evict.
  7. Any task error routes to the errors block, which posts a Slack alert.

A Weaviate batch delete removes at most QUERY_MAXIMUM_RESULTS objects per call; weaviate.Delete repeats it until no match is left, so one pass of the loop usually clears the backlog. The re-count after each delete is what makes a partial clear, for example objects written during the purge, fail instead of reporting success.

What you get

  • A retention guard for a Weaviate class, keyed on any text property you choose.
  • A dry-run mode that shows the candidate count and the exact filter before anyone deletes anything.
  • Automatic eviction that keeps deleting and re-counting until the class is clean or a time budget runs out.
  • A Slack findings alert on detection and a Slack alert on failure.
  • A disabled schedule you can turn on to run the scan every day in safe mode.

Who it's for

  • AI and platform engineers who run a Weaviate store behind a RAG pipeline and need superseded content purged.
  • Data engineers who re-ingest a source and must drop its old vectors first.
  • Teams who want an erasure by subject or tenant key gated and verified rather than fired blind from a script.

Why orchestrate this with Kestra

Weaviate has no retention job and no scheduler. Left alone a class only grows and old vectors keep surfacing in results. Kestra adds the schedule, the dry-run and remediate gates, the Slack alerts and the execution history. The re-query after the delete is a first-class task, so the run proves the store is clean instead of assuming it.

Tested end to end

Run on Kestra 2.0.5 against a self-hosted Weaviate 1.39 instance with anonymous access. A Document class was seeded with 5 current objects and 7 stale objects tagged source=deprecated. The clean path reported 0 and skipped eviction. The detect path found 7. The dry-run path reported 7 and left the count at 7. With the server batch-delete cap set to 3 per call, the remediate path cleared the 7 stale objects over three loop passes (7 to 4 to 1 to 0), left the 5 current objects in place and re-verified 0 remaining. A run pointed at an unreachable endpoint failed and fired the Slack errors block. Every count was confirmed with a direct GraphQL Aggregate call against Weaviate, not only from the Kestra log. The flow was then migrated to the structured Query of plugin-weaviate 2.0 and re-run on Weaviate 1.39 with QUERY_MAXIMUM_RESULTS=3 and scan_limit=3: the dry run reported 3 (the capped count) and deleted nothing, the remediate path's Delete removed all 7 stale objects in one pass, left the 5 current objects in place and re-verified 0 remaining, and the next run took the clean path.

Prerequisites

A reachable Weaviate 1.32+ cluster, reachable over REST and gRPC (port 50051 by default; set grpcHost and grpcPort to override), and a class whose objects carry a text property you can use as a retention key, for example source, tenant, batchId or docId.

Secrets

  • SLACK_WEBHOOK_URL: incoming webhook for the findings and failure alerts.
  • WEAVIATE_API_KEY: bearer key for a hosted cluster. Read on every Weaviate task unless anonymous is true.

Inputs

  • weaviate_url: the cluster endpoint, scheme and host with port.
  • anonymous: set true for a cluster with anonymous access, which skips the API key.
  • class_name: the class to scan.
  • retention_property: the text property that tags each object with its origin or retention key.
  • retention_value: the value that marks an object stale.
  • scan_limit: the most stale objects counted per query, at most the server's QUERY_MAXIMUM_RESULTS.
  • reverify_timeout: the time budget for the eviction and re-verify loop.
  • dry_run: report without deleting. Defaults to true.
  • auto_remediate: allow deletion. Defaults to false.

Quick start

  1. Store SLACK_WEBHOOK_URL as a Kestra secret. Store WEAVIATE_API_KEY too or set the anonymous input to true for a cluster with open access.
  2. Set weaviate_url, class_name, retention_property and retention_value to match your store and run with the other defaults. It reports the stale count and deletes nothing.
  3. When the count looks right, set auto_remediate to true and dry_run to false to evict and re-verify.
  4. Enable the daily_scan trigger to run the safe-mode scan every day.

How to extend

  • Point retention_property at tenant or docId to run an erasure by subject rather than by source.
  • Lower reverify_timeout on a small class or raise it when a very large backlog needs several passes.
  • Add a Pause before evict_until_clear to require human approval in production.
  • Fan the guard across many classes by wrapping it in a Loop over a list of class names.
  • Swap the Slack alert for any other Kestra notification plugin.

Links

See How

New to Kestra?

Use blueprints to kickstart your first workflows.