Internal linking is still one of the few SEO levers where machine intelligence can produce compounding returns without turning your site into a link farm.
A content engine is only as sharp as its retrieval layer. Seed an LLM with a flat keyword list and you get flat output; seed it with a ranked map of demand versus coverage and it starts to behave like a system. The useful automation for SEO is not “generate fifty posts.“ It is a Python job that compares live Search Console demand to your existing content graph, clusters both, and emits machine-readable briefs with evidence. The pipeline is unglamorous: query data in, embeddings and clusters through, gap scores out, tasks to the content engine. That is the glue code worth owning.
Pull query/page pairs from the Search Console API for ninety days. Normalize hard: lowercase, trim whitespace, fold punctuation, collapse near-duplicates, and drop branded terms with a configurable regex. Aggregate impressions, clicks, average position, and CTR by query and by landing page. Do not throw away low-volume long-tail queries; they often carry the intent labels that head terms hide. Persist raw and aggregated tables as Parquet so you are not hammering the API every time you tweak a threshold. Add a page inventory from the sitemap or CMS API: title, H1, H2s, meta description, body text, canonical, last modified, and internal link count. Strip boilerplate with trafilatura or html2text before you embed anything.
Embed queries and content separately. Sentence-transformer models give you local cost control; hosted embeddings may give better retrieval quality, so benchmark on your own corpus. Cache every vector by content hash, because re-embedding unchanged docs is the fastest way to turn a clever script into a cron-driven money fire. Index vectors in FAISS or pgvector and keep metadata in SQLite or Postgres. Store title, heading, and body-chunk embeddings independently; a page can cover a query in an H2 even when its title is fuzzy. Chunk body copy into roughly three-hundred-to-five-hundred-token windows with overlap, then retain both chunk vectors and a page-level centroid; that way a single strong section can match a query even when the rest of the page is off-topic.
Cluster query embeddings with HDBSCAN or agglomerative clustering using cosine distance, then tune min_cluster_size against your niche. Label clusters with c-TF-IDF or an LLM constrained to short, stable labels. Cluster your content embeddings the same way. Align demand clusters to coverage clusters using centroid similarity plus lexical overlap on head terms and entities. The result is a matrix of query demand against content coverage. Gaps are clusters with weak or missing coverage, meaningful aggregate impressions, poor average position, and CTR below expectation for that rank. Score them with log impressions, position opportunity, CTR gap, and business priority; normalize to a hundred-point scale so the content team can triage.
The script should emit tasks, not prose. A JSON record per gap should include cluster ID, representative queries, existing URLs, intent label, gap score, recommended format, internal-link candidates, and evidence snippets. Feed those records into the AI content engine as briefs with hard constraints: cover named entities, cite sources, avoid cannibalizing existing URLs, include schema, and stay within a word budget. For existing pages, emit update tasks such as add section, retitle, merge, redirect, or improve internal links. Route each record as new content or existing-page refresh, and include the priority and evidence that justifies the assignment. This is where automation earns trust: the LLM gets a bounded assignment backed by data instead of a blank prompt.
Engineering hygiene matters. Use argparse or typer for a CLI, YAML for thresholds, pydantic for task schemas, structured logs, retries with backoff, and quota-aware API calls. Make runs idempotent and incremental. Pin embedding and labeling model versions. Keep an eval set of fifty known gaps and track precision at twenty plus human acceptance rate. Gate auto-publish behind review. Cache LLM labels. Version raw data, scores, and prompts. Run weekly, not continuously, unless your inventory changes that fast.
The savvy move is to treat content engines as downstream of data quality. Python’s job is to make demand, coverage, and opportunity legible; the LLM writes only after the brief passes evals. Build the smallest pipeline that produces useful gap tasks, measure whether editors accept them, then expand. Skip the dashboard until the CSV is actually driving decisions. That turns AI content automation from a slot machine into a repeatable SEO system.



