epimetheus: fix connect.py title→slug mismatch in vector-search edges

claim_title payloads wrote unresolvable human-readable titles into
frontmatter related fields. Switched to claim_path with slug extraction
so reciprocal edges in merge.py can resolve targets. Renamed
neighbor_titles→neighbor_slugs throughout for consistency.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
m3taversal 2026-04-14 12:16:20 +01:00
parent fe78a2e42d
commit 5f287ae9c8

View file

@ -63,7 +63,7 @@ def _build_search_text(content: str) -> str:
return " ".join(parts) return " ".join(parts)
def _add_related_edges(claim_path: str, neighbor_titles: list[str]) -> bool: def _add_related_edges(claim_path: str, neighbor_slugs: list[str]) -> bool:
"""Add related edges to a claim's frontmatter. Returns True if modified.""" """Add related edges to a claim's frontmatter. Returns True if modified."""
try: try:
with open(claim_path) as f: with open(claim_path) as f:
@ -87,10 +87,10 @@ def _add_related_edges(claim_path: str, neighbor_titles: list[str]) -> bool:
# Add new edges # Add new edges
added = [] added = []
for title in neighbor_titles: for slug in neighbor_slugs:
if title.strip().lower() not in existing_lower: if slug.strip().lower() not in existing_lower:
added.append(title) added.append(slug)
existing_lower.add(title.strip().lower()) existing_lower.add(slug.strip().lower())
if not added: if not added:
return False return False
@ -167,27 +167,28 @@ def connect_new_claims(
stats["skipped_no_neighbors"] += 1 stats["skipped_no_neighbors"] += 1
continue continue
# Extract neighbor titles # Extract neighbor slugs (filename stems, not titles — reciprocal edges need resolvable names)
neighbor_titles = [] neighbor_slugs = []
for hit in hits: for hit in hits:
payload = hit.get("payload", {}) payload = hit.get("payload", {})
title = payload.get("claim_title", "") claim_path_qdrant = payload.get("claim_path", "")
if title: if claim_path_qdrant:
neighbor_titles.append(title) slug = claim_path_qdrant.rsplit("/", 1)[-1].replace(".md", "")
neighbor_slugs.append(slug)
if not neighbor_titles: if not neighbor_slugs:
stats["skipped_no_neighbors"] += 1 stats["skipped_no_neighbors"] += 1
continue continue
# Add edges to the new claim's frontmatter # Add edges to the new claim's frontmatter
if _add_related_edges(claim_path, neighbor_titles): if _add_related_edges(claim_path, neighbor_slugs):
stats["connected"] += 1 stats["connected"] += 1
stats["edges_added"] += len(neighbor_titles) stats["edges_added"] += len(neighbor_slugs)
stats["connections"].append({ stats["connections"].append({
"claim": os.path.basename(claim_path), "claim": os.path.basename(claim_path),
"neighbors": neighbor_titles, "neighbors": neighbor_slugs,
}) })
logger.info("Connected %s%d neighbors", os.path.basename(claim_path), len(neighbor_titles)) logger.info("Connected %s%d neighbors", os.path.basename(claim_path), len(neighbor_slugs))
else: else:
stats["skipped_no_neighbors"] += 1 stats["skipped_no_neighbors"] += 1