6b26bf28a7
index_store.py сканирует папку карточек, считает отпечаток каждой (embed_fn инъекцией) и складывает индекс nisha/roditel/sinonimy/path/vector; save_index/load_index — JSON roundtrip. build_index.py — CLI ручной пересборки индекса (провайдер эмбеддингов через ALEX_EMBED). TDD: тест падал на ModuleNotFoundError до реализации, затем 2 passed (плюс полный пакет brain — 12 passed, регрессий нет). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
28 lines
886 B
Python
28 lines
886 B
Python
from pathlib import Path
|
||
from brain.index_store import build_index, save_index, load_index
|
||
|
||
FIX = Path(__file__).parent / "fixtures"
|
||
|
||
|
||
def fake_embed(text):
|
||
return [float(len(text)), float(text.lower().count("а"))]
|
||
|
||
|
||
def test_build_index_reads_all_cards():
|
||
idx = build_index(FIX, embed_fn=fake_embed)
|
||
names = {e["nisha"] for e in idx}
|
||
assert "Медицина" in names
|
||
assert any(n.startswith("стоматология") for n in names)
|
||
stoma = next(e for e in idx if e["nisha"].startswith("стоматология"))
|
||
assert stoma["roditel"] == "Медицина"
|
||
assert "импланты" in stoma["sinonimy"]
|
||
assert len(stoma["vector"]) == 2
|
||
|
||
|
||
def test_save_and_load_roundtrip(tmp_path):
|
||
idx = build_index(FIX, embed_fn=fake_embed)
|
||
p = tmp_path / "nishi_index.json"
|
||
save_index(idx, p)
|
||
back = load_index(p)
|
||
assert back == idx
|