migrate_kg_overhaul

One-time migration for the knowledge graph overhaul.

Nondestructive – safe to run multiple times. Performs:

  1. Creates vector + range indexes for new entity labels (Rule, Directive, Role).

  2. Creates the pinned range index on ALL entity labels (including the 9 pre-existing ones).

  3. Backfills pinned = false on 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 / pinned range indexes exist for every label in ENTITY_LABELS (including the new Rule / Directive / Role labels), then backfills pinned = false on 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 the FalkorDB client) and drives the knowledge graph named by GRAPH_NAME via create_node_vector_index, create_node_range_index, and Cypher query calls; “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’s main via asyncio.run; not imported elsewhere.

Parameters:
  • redis_url (str) – Redis connection URL whose pool also backs FalkorDB.

  • ssl_kwargs (dict | None) – Optional SSL/mTLS keyword arguments forwarded to aioredis.from_url (typically from Config.redis_ssl_kwargs).

Return type:

None

Returns:

None.

Raises:

SystemExit – Exits with status 1 if the initial Redis ping fails.

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_URL or redis://localhost:6379/0), and best-effort loads SSL/mTLS settings from Config.redis_ssl_kwargs so the migration can reach a TLS-protected Redis. It then drives the migration by handing those values to migrate through asyncio.run.

Invoked only from this module’s if __name__ == "__main__" guard; it has no in-repo callers and prints progress to stdout.

Return type:

None

Returns:

None.

Raises:

SystemExit – Exits with status 1 if the migration raises, or via argparse when given invalid arguments.