MCPcopy Index your code
hub / github.com/CommonstackAI/UncommonRoute / main

Function main

scripts/build_seed_index.py:29–61  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

27
28
29def main():
30 train_path = Path("uncommon_route/data/v2_splits/train.jsonl")
31 if not train_path.exists():
32 raise FileNotFoundError(f"Run split_data.py first: {train_path}")
33
34 from sentence_transformers import SentenceTransformer
35 model = SentenceTransformer("BAAI/bge-small-en-v1.5")
36
37 rows = []
38 with open(train_path, encoding="utf-8") as f:
39 for line in f:
40 line = line.strip()
41 if line:
42 rows.append(json.loads(line))
43
44 texts, labels = [], []
45 for row in rows:
46 for m in reversed(row.get("messages", [])):
47 if m.get("role") == "user":
48 text = _extract_text(m.get("content", ""))
49 if text.strip():
50 texts.append(text)
51 labels.append(row["target_tier_id"])
52 break
53
54 print(f"Embedding {len(texts)} texts...")
55 embeddings = model.encode(texts, normalize_embeddings=True, show_progress_bar=True)
56
57 out_dir = Path("uncommon_route/data/v2_splits")
58 np.save(out_dir / "seed_embeddings.npy", embeddings)
59 with open(out_dir / "seed_labels.json", "w") as f:
60 json.dump(labels, f)
61 print(f"Saved: {embeddings.shape[0]} embeddings ({embeddings.shape[1]}d) + labels")
62
63
64if __name__ == "__main__":

Callers 1

Calls 5

openFunction · 0.85
_extract_textFunction · 0.85
appendMethod · 0.45
getMethod · 0.45
saveMethod · 0.45

Tested by

no test coverage detected