#!/usr/bin/env python3 """ Rebuild enriched index from existing BINARY index (fast load, skip JSON). Reads v1 binary, enriches titles, re-embeds, saves as v2. """ import os, struct, sys, json, time, urllib.request, urllib.error OPENAI_API_KEY = os.environ.get("OPENAI_API_KEY", "") OPENAI_API = "https://api.openai.com/v1/embeddings" MODEL = "text-embedding-3-small" DIMS = 1536 BATCH_SIZE = 100 INDEX_DIR = os.path.expanduser("~/.boe") BIN_V1 = os.path.join(INDEX_DIR, "index-v1.bin") BIN_V2 = os.path.join(INDEX_DIR, "index-v2.bin") sys.path.insert(0, os.path.dirname(__file__)) from build_enriched_index import LAW_DESCRIPTIONS, enrich_title def load_binary_entries(path): """Load entries from binary index (skip vectors — we'll re-embed).""" entries = [] with open(path, "rb") as f: magic = f.read(4) assert magic == b"BOEI", f"Bad magic: {magic}" version, dims, count = struct.unpack("