test(llm): live CPT-run guard checks against a plain frozenset (3.8 min to 2 s) (S1)
Some checks failed
CI / lint (push) Successful in 57s
CI / notebooks-smoke (push) Successful in 2m19s
Deploy / changes (push) Successful in 17s
Infra CI / notebooks (push) Successful in 1m35s
CI / test (push) Failing after 5m17s
Infra CI / zotero (push) Successful in 32s
Infra CI / docs (push) Successful in 1m35s
Infra CI / api (push) Successful in 1m30s
Infra CI / llm (push) Successful in 1m25s
Infra CI / bcda (push) Successful in 2m16s
Deploy / notebooks (push) Has been skipped
Deploy / zotero (push) Has been skipped
Infra CI / mc (push) Successful in 49s
Deploy / docs (push) Has been skipped
Deploy / api (push) Successful in 2m1s
Deploy / bcda (push) Successful in 2m33s
Deploy / mc (push) Has been skipped
Deploy / llm (push) Successful in 1m45s
Deploy / report (push) Successful in 16s
Some checks failed
CI / lint (push) Successful in 57s
CI / notebooks-smoke (push) Successful in 2m19s
Deploy / changes (push) Successful in 17s
Infra CI / notebooks (push) Successful in 1m35s
CI / test (push) Failing after 5m17s
Infra CI / zotero (push) Successful in 32s
Infra CI / docs (push) Successful in 1m35s
Infra CI / api (push) Successful in 1m30s
Infra CI / llm (push) Successful in 1m25s
Infra CI / bcda (push) Successful in 2m16s
Deploy / notebooks (push) Has been skipped
Deploy / zotero (push) Has been skipped
Infra CI / mc (push) Successful in 49s
Deploy / docs (push) Has been skipped
Deploy / api (push) Successful in 2m1s
Deploy / bcda (push) Successful in 2m33s
Deploy / mc (push) Has been skipped
Deploy / llm (push) Successful in 1m45s
Deploy / report (push) Successful in 16s
This commit is contained in:
@@ -105,23 +105,28 @@ def ama_index():
|
||||
tail and elements, plus section guidelines. Built once per session."""
|
||||
from market.edgar import AmaIndex
|
||||
|
||||
# SELECT DISTINCT: the runs are the same, far fewer rows to tokenize
|
||||
con = duckdb.connect(str(REPLICA), read_only=True)
|
||||
try:
|
||||
texts = [
|
||||
t
|
||||
for (t,) in con.execute(
|
||||
"SELECT descriptor FROM pfs.cpt_code UNION ALL "
|
||||
"SELECT DISTINCT t FROM ("
|
||||
"SELECT descriptor AS t FROM pfs.cpt_code UNION ALL "
|
||||
"SELECT stem FROM pfs.cpt_code UNION ALL "
|
||||
"SELECT tail FROM pfs.cpt_code UNION ALL "
|
||||
"SELECT unnest(elements) FROM pfs.cpt_code UNION ALL "
|
||||
"SELECT guideline FROM pfs.cpt_section"
|
||||
"SELECT guideline FROM pfs.cpt_section)"
|
||||
).fetchall()
|
||||
if t
|
||||
]
|
||||
finally:
|
||||
con.close()
|
||||
assert texts, "pfs.cpt_code is empty; nothing to guard against"
|
||||
return AmaIndex.of(texts)
|
||||
# AmaIndex.of builds the runs; a plain frozenset copy is what the checks
|
||||
# intersect with, because set.isdisjoint on the frozenset *subclass* takes
|
||||
# a slow generic path (about 60 ms per call against 181k runs).
|
||||
return frozenset(AmaIndex.of(texts))
|
||||
|
||||
|
||||
def _strings(x):
|
||||
@@ -149,13 +154,19 @@ def _prose_segments(text):
|
||||
def test_live_no_eight_word_cpt_runs(cfg, slices, ama_index):
|
||||
"""No served string shares an 8-word run with licensed CPT text."""
|
||||
from llm import policy
|
||||
from market.edgar import shares_ama_run
|
||||
from market.edgar import _WORD
|
||||
|
||||
def shares_run(text, n=8): # same tokenization as market.edgar.shares_ama_run
|
||||
w = _WORD.findall(text.lower())
|
||||
return not {tuple(w[i : i + n]) for i in range(len(w) - n + 1)}.isdisjoint(
|
||||
ama_index
|
||||
)
|
||||
|
||||
served = {**slices, "contents": policy.load_contents(cfg)}
|
||||
hits = []
|
||||
for name, body in served.items():
|
||||
for text in _strings(body):
|
||||
if any(shares_ama_run(seg, ama_index) for seg in _prose_segments(text)):
|
||||
if any(shares_run(seg) for seg in _prose_segments(text)):
|
||||
hits.append(name)
|
||||
break
|
||||
assert not hits, f"8-word CPT run shared in slices {hits}"
|
||||
|
||||
Reference in New Issue
Block a user