migrate_kg_overhaul
One-time migration for the knowledge graph overhaul.
Nondestructive – safe to run multiple times. Performs:
Creates vector + range indexes for new entity labels (Rule, Directive, Role).
Creates the
pinnedrange index on ALL entity labels (including the 9 pre-existing ones).Backfills
pinned = falseon every existing entity that lacks the property (WHERE e.pinned IS NULL).
Usage:
python migrate_kg_overhaul.py [--redis-url redis://localhost:6379/0]
Reads $REDIS_URL by default.
- async migrate_kg_overhaul.migrate(redis_url, ssl_kwargs=None)[source]
Apply the knowledge-graph overhaul migration to FalkorDB.
Performs the full nondestructive overhaul in three steps: ensures both the vector index and the
name/category/scope_id/pinnedrange indexes exist for every label inENTITY_LABELS(including the newRule/Directive/Rolelabels), then backfillspinned = falseon any existing entity that lacks the property. Each step is idempotent, so re-running this against an already-migrated graph is safe.Opens an async Redis connection at
redis_url(sharing its connection pool with theFalkorDBclient) and drives theknowledgegraph named byGRAPH_NAMEviacreate_node_vector_index,create_node_range_index, and Cypherquerycalls; “already indexed” / “already exists” errors are treated as no-ops. Progress, per-index status, and final node/relationship counts are printed to stdout, and the Redis client is closed on success. Called by this module’smainviaasyncio.run; not imported elsewhere.- Parameters:
- Return type:
- Returns:
None.
- Raises:
SystemExit – Exits with status 1 if the initial Redis
pingfails.
- migrate_kg_overhaul.main()[source]
Parse CLI arguments and run the overhaul migration.
Command-line entry point for
python migrate_kg_overhaul.py. Configures logging, parses--redis-url(defaulting to$REDIS_URLorredis://localhost:6379/0), and best-effort loads SSL/mTLS settings fromConfig.redis_ssl_kwargsso the migration can reach a TLS-protected Redis. It then drives the migration by handing those values tomigratethroughasyncio.run.Invoked only from this module’s
if __name__ == "__main__"guard; it has no in-repo callers and prints progress to stdout.- Return type:
- Returns:
None.
- Raises:
SystemExit – Exits with status 1 if the migration raises, or via
argparsewhen given invalid arguments.