Files
portal/knowledge/aleksandra/brain/tests/test_index_store.py
T
Дмитрий 6b26bf28a7 feat(brain): построение индекса ниш из карточек + CLI-пересборка
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>
2026-07-17 08:20:19 +03:00

28 lines
886 B
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
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