ai-visibility-index / code /avi_package.py
jacobezra93's picture
Mirror the Zenodo deposit
c2f75e6 verified
Raw History Blame Contribute Delete
5.02 kB
# -*- coding: utf-8 -*-
"""Build the public data package for an AI Visibility Index edition.
usage: avi_package.py EDITION RUN [RUN ...] e.g. avi_package.py 2026-09 2026-08 2026-09
Writes ai_index/editions/<EDITION>/public/ :
results.csv one row per (month, market, Google top-3 business, engine)
summary.json all published rates with 95% intervals
answers.json prompts, the Google top 3, and every AI answer in full
avi_matcher.py the exact matching code
README.txt fields, method, license
"""
import json, os, shutil, subprocess, sys
HERE = os.path.dirname(os.path.abspath(__file__))
edition, runs = sys.argv[1], sys.argv[2:]
out = os.path.join(HERE, "ai_index", "editions", edition, "public")
os.makedirs(out, exist_ok=True)
subprocess.run([sys.executable, os.path.join(HERE, "avi_score.py"), *runs,
"--json", os.path.join(out, "summary.json"),
"--csv", os.path.join(out, "results.csv")], check=True, capture_output=True)
shutil.copy(os.path.join(HERE, "avi_matcher.py"), os.path.join(out, "avi_matcher.py"))
markets = []
for run in runs:
d = json.load(open(os.path.join(HERE, "ai_index", f"index_{run}_full.json")))
m = d.get("methodology", {})
stored_full = m.get("answer_text") == "stored in full"
filled = {(f["category"], f["city"]): f["collected_utc"] for f in d.get("filled_markets", [])}
for r in d["rows"]:
markets.append({
"month": run, "category": r["category"], "city": r["city"],
"collected_utc": filled.get((r["category"], r["city"]), d.get("generated_utc")),
"google_maps_top3": [{k: b.get(k) for k in ("name", "domain", "address", "rating", "reviews")}
for b in r["top3"]],
"answers": {e: a.get("text", "") for e, a in r["answers"].items()},
"answer_text_complete": stored_full or None,
})
json.dump({
"edition": edition,
"license": "CC BY 4.0, cite as: SEMPITE AI Visibility Index, " + edition + ", sempite.com/research/ai-visibility-index/",
"prompts": {
"google_maps": "{category} in {city} (DataForSEO google/maps/live/advanced, United States, top 3 map results)",
"chatgpt": "I need a {category} in {city}. Who are the best {category}s there? Please recommend specific businesses by name. (gpt-4o-mini via DataForSEO, web search off)",
"chatgpt_web": "same prompt, web search on (from September 2026)",
"google_ai": "best {category} in {city} (Google AI Mode via DataForSEO, United States)",
},
"notes": [
"August 2026 stored only the first 1,500 characters of each answer and no business websites. "
"Its ChatGPT answers were all shorter than that and are complete; every Google AI Mode answer was cut, "
"so August AI Mode rates are not comparable and are not published.",
"July 2026 raw answers were overwritten by a software fault on 1 August 2026 and cannot be re-scored.",
],
"markets": markets,
}, open(os.path.join(out, "answers.json"), "w"), ensure_ascii=False, indent=1)
open(os.path.join(out, "README.txt"), "w").write(f"""SEMPITE AI Visibility Index, {edition} edition: public data
https://sempite.com/research/ai-visibility-index/
License: CC BY 4.0. Cite as: SEMPITE AI Visibility Index, {edition}, sempite.com/research/ai-visibility-index/
WHAT IT MEASURES
For 50 local markets (plumber, dentist, personal injury lawyer, real estate agent, HVAC contractor
x New York, Los Angeles, Chicago, Houston, Phoenix, Philadelphia, San Antonio, San Diego, Dallas, Miami)
we take the top 3 Google Maps businesses and check whether AI assistants name them when asked for a
recommendation. A business counts as "mentioned" if avi_matcher.py finds its name (or its website) in the answer.
FILES
results.csv month, category, city, engine, maps_position (1-3), business, domain, rating, reviews,
mentioned (True/False), answer_truncated (True where the stored answer was cut short)
summary.json every published rate, per month and engine, with 95% Wilson intervals
answers.json the Google top 3 and every AI answer in full, per market, with the prompts used
avi_matcher.py the matching rule (Python 3, no dependencies). Re-run it over answers.json to reproduce results.csv.
ENGINES
chatgpt gpt-4o-mini, web search off (answers from the model's own knowledge)
chatgpt_web gpt-4o-mini, web search on (September 2026 onward)
google_ai Google AI Mode
Engines with no answer for a market are excluded from that market, never counted as a miss.
KNOWN LIMITS
August 2026 AI Mode answers were stored truncated and are excluded from published rates.
July 2026 raw data no longer exists. July and August 2026 figures published before 18 September 2026
used an earlier matching rule that overstated visibility; see the correction on the page.
""")
print("\n".join(sorted(os.listdir(out))))
for f in sorted(os.listdir(out)):
print(f, os.path.getsize(os.path.join(out, f)))