From 6d880076f686235dd75d47dd4441a27b2540ecb0 Mon Sep 17 00:00:00 2001 From: Adeel Ahmad Date: Thu, 15 Oct 2026 11:03:22 +0000 Subject: [PATCH 1/3] feat(entities): let the decision model type names the rules leave as terms Analysis asks the decision model (Jev or Laya, when set up) what each new Term of a recording is, in one call, and keeps the types it is sure of. Settings > Analysis > Names the rules can't type (analysis.typing) can let the language model answer too, or turn it off. Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_018MeaEgM8m7rTjbkKVQVsrT --- CHANGELOG.md | 5 + DEVLOG.md | 8 +- docs/assistant.md | 2 + docs/processing.md | 15 +++ fastapi_backend/app/domain/analyze.py | 26 +++++ fastapi_backend/app/domain/decide.py | 63 +++++++++++ fastapi_backend/app/domain/name_types.py | 66 +++++++++++- fastapi_backend/app/domain/settings.py | 1 + fastapi_backend/app/domain/store.py | 4 +- fastapi_backend/archive.example.yaml | 1 + fastapi_backend/tests/api/_assist.py | 2 +- .../tests/domain/test_name_types.py | 102 +++++++++++++++++- fastapi_backend/tests/fake_jev.py | 7 +- fastapi_backend/tests/fake_llm.py | 10 ++ .../components/settings/bodies.tsx | 1 + nextjs-frontend/components/settings/model.ts | 12 +++ threat-model.md | 1 + threat-model.yaml | 3 +- 18 files changed, 321 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 480bc2fee..742feb437 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,11 @@ The backend (`fastapi_backend`) and the frontend (`nextjs-frontend`) are version ## Unreleased +- **The decision model types the names the rules can't.** When Jev or Laya is set up, analysis asks it what each new + Term of a recording is (a person, an organisation, a product...), with the lines it's said in, in one call per + recording, and keeps the types it is sure of. Settings › Analysis › Names the rules can't type (`analysis.typing`) + can also let the language model answer, or turn it off; the language model is never asked by default + ([Names the rules can't type](docs/processing.md#entities-and-the-graph-explorer)). - **Names get their real types, not Term.** The built-in extractor now tells people, places, organisations, events, works and dates apart without a model: by a title or role before a name, a given name, the word a name ends or starts with (Corp, University of, Summit, Act, River), lists of countries, regions and large cities and of diff --git a/DEVLOG.md b/DEVLOG.md index 7ffb5f13b..fd1ad0cc0 100644 --- a/DEVLOG.md +++ b/DEVLOG.md @@ -34,8 +34,12 @@ organisations and products, holidays), the words a name starts or ends with, rol verbs of saying after it and the namespace's named speakers; a recording gives each name one type. Upgrade step `entity-types` retypes old analysis-made Terms, skipping types people or agents set (graph history and audit log). -Refine later: the decision model (Jev or Laya) for the names the rules leave as Terms, in analysis and as an action -on existing Terms (next PR); place, name and brand lists for more languages and regions (Custom vocabulary in +Then the decision model: `analysis.typing` (`auto` by default: Jev or Laya when set up, never the language model; +`model` lets the language model answer; `rules` none) asks about a recording's new Terms in one `decide.choose_all` +call, with two lines each, and keeps answers above `decisions.act_above`. + +Refine later: an action that asks the model about existing Terms (API, MCP, a button on the Entities page; next PR); +offer the namespace's own types to the model too; ask about names in the hybrid mode's new entities; place, name and brand lists for more languages and regions (Custom vocabulary in Settings covers one install's own names); type existing entities again when a later recording gives better evidence (needs a marker for types people set, kept out of the versioned rows); "Google Cloud"-like names (a known company, then a word) as products. diff --git a/docs/assistant.md b/docs/assistant.md index b01c44ac2..4c390f5ec 100644 --- a/docs/assistant.md +++ b/docs/assistant.md @@ -503,6 +503,8 @@ The assistant makes routine choices for you instead of asking. The first is wher `import_files` without a namespace picks one from the namespaces you can add to, judging from their descriptions, what's in them lately, the file names and your message. You're asked only when it isn't sure: below `decisions.act_above` (0.8) confidence it lists the namespaces, its best guess first. +Analysis takes routine choices too: what a name the rules can't type is (a person, an organisation, a product...; +[Names the rules can't type](processing.md#entities-and-the-graph-explorer)). A **decision model** answers these: Jev, typesafe.ai's System One, which takes a few hundred milliseconds and costs a fraction of an LLM call. Set its key in **Settings → AI assistant → Routine choices**, or `TYPESAFE_API_KEY` in `.env`. diff --git a/docs/processing.md b/docs/processing.md index 7e37803b1..8e6a61d9e 100644 --- a/docs/processing.md +++ b/docs/processing.md @@ -171,6 +171,21 @@ reads each name and the words around it (`app/domain/name_types.py`): topic, or retyped on the Entities page (one at a time or ticked together). Names listed in Settings › Analysis › Custom vocabulary (`Name | TYPE`) always get the type given there. +**Names the rules can't type.** When a [decision model](assistant.md#routine-choices) is set up (Jev with its key, or +Laya), analysis asks it what each new Term of a recording is, with the first two lines it's said in, and keeps the type +when it is sure (`decisions.act_above`, 0.8). Names that are already entities aren't asked again, and the short form of +a longer name in the same recording ("Johnson" of "Sarah Johnson") takes that name's type. The names of a recording go +in one call (up to 20 a call and 40 a recording; Laya, which reads less, one at a time). Each call is in Activity and +counts toward budgets, and none is made once the budget's hard limit is reached. Settings › Analysis › **Names the rules +can't type** (`analysis.typing`) chooses: + +- `auto` (the default): the decision model when one is set up, else nothing; the language model is never asked. +- `model`: the decision model, else the language model, in one call per recording too. +- `rules`: no model; the names stay Terms. + +A name the model isn't sure of stays a Term, and so do all of them when it can't be reached. Names a workflow's nodes +typed, and names mapped onto a fixed list ([Entity setup](#entity-setup)), aren't asked. + A name gets one type per recording, the one most of its lines give it, so "Lee" after "Dr Lee" is a person too. "And" no longer joins two names into one ("Kenya and Nigeria" are two places). The given names are mostly the US Census Bureau's frequent first names of 1990 (public domain); the other lists are written for Lens. With diff --git a/fastapi_backend/app/domain/analyze.py b/fastapi_backend/app/domain/analyze.py index ee0cad2f5..7b97a7cc0 100644 --- a/fastapi_backend/app/domain/analyze.py +++ b/fastapi_backend/app/domain/analyze.py @@ -446,6 +446,30 @@ def one_type(seg_ents): return [[(n, best.get(ent_key(n), t)) for n, t in es] for es in seg_ents] +def model_types(db, cfg, nid, segs, seg_ents): + """The terms of a recording that aren't entities yet, given the type a model is sure of (name_types.ask). A short + form of a longer name said here ("Johnson" of "Sarah Johnson") takes that name's type later, so it isn't asked.""" + if not name_types.asking(cfg): + return seg_ents + terms = {} + for es in seg_ents: + for n, t in es: + k = ent_key(n) + if k and t == "TERM": + terms.setdefault(k, n) + keys = {ent_key(n) for es in seg_ents for n, _ in es} + terms = {k: n for k, n in terms.items() if not any(L.endswith(" " + k) for L in keys)} + if terms: + have = set(db.values("SELECT VALUE key FROM entity WHERE space = $s AND key IN $k", s=nid, k=sorted(terms))) + have |= set(db.values("SELECT VALUE key FROM entity_alias WHERE space = $s AND key IN $k", s=nid, k=sorted(terms))) + terms = {k: n for k, n in terms.items() if k not in have} + if not terms: + return seg_ents + texts = [s["text"] for s in segs] + typed = name_types.ask(cfg, {k: (n, name_types.said_in(n, texts)) for k, n in terms.items()}) + return [[(n, typed.get(ent_key(n), t) if t == "TERM" else t) for n, t in es] for es in seg_ents] if typed else seg_ents + + def analyze_recording(db, cfg, rid, seg_ents=None, say=None): """Entities, keywords, sections and talk statistics. `seg_ents` (per line, [(name, type)]) replaces the extractor: a workflow's save entities node passes what its nodes found.""" @@ -486,6 +510,8 @@ def analyze_recording(db, cfg, rid, seg_ents=None, say=None): have = {ent_key(n) for n, _ in es} es.extend(h for h in hints if ent_key(h[0]) not in have) seg_ents = one_type(seg_ents) + if given is None and not listed: # names the rules can't tell: a model may (Settings › Analysis) + seg_ents = model_types(db, cfg, nid, segs, seg_ents) if setup["types"] and not listed: # the namespace (or collection) keeps only some types seg_ents = [[(n, t) for n, t in es if entity_setup.keeps(setup, t)] for es in seg_ents] surface = {t: c.most_common(1)[0][0] for t, c in ts.items()} diff --git a/fastapi_backend/app/domain/decide.py b/fastapi_backend/app/domain/decide.py index e1c6a9621..dbc46aa06 100644 --- a/fastapi_backend/app/domain/decide.py +++ b/fastapi_backend/app/domain/decide.py @@ -212,6 +212,69 @@ def choose(cfg, question, options, state): } +def choose_all(cfg, asks, state, language_model=True): + """Several choices about one `state` in one call: `asks` is {id: (question, options)}; returns {id: decision} as + `choose` gives them, for the questions answered. The language model answers when no decision model can, unless + `language_model` is False. Raises Undecided when nothing can answer.""" + asks = {q: (text, dict(o)) for q, (text, o) in asks.items() if o} + if not asks: + return {} + how = engine(cfg) + if how in ENGINES: + questions = {q: {"type": "choice", "instructions": text, "criteria": o} for q, (text, o) in asks.items()} + try: + answers = ENGINES[how](cfg, questions, state) + out = {} + for q, (_, o) in asks.items(): + a = answers.get(q) or {} + if a.get("choice") in o: + probs = a.get("probabilities") or {a["choice"]: a.get("confidence", 0)} + out[q] = {"choice": a["choice"], "confidence": float(a.get("confidence") or 0), "ranked": _ranked(probs), "by": how} + return out + except Undecided as e: + if not language_model: + raise + log.warning("decision model (%s) failed, asking the language model: %s", how, e) + how = "llm" if llm.configured(cfg) else None + if how != "llm" or not language_model: + raise Undecided("no decision model is set up" if not language_model else "no decision model or language model is set up") + ids = {f"q{i}": q for i, q in enumerate(asks)} + one = { + i: { + "type": "object", + "properties": {"choice": {"type": "string", "enum": list(asks[q][1])}, "confidence": {"type": "number"}}, + "required": ["choice", "confidence"], + } + for i, q in ids.items() + } + schema = {"type": "object", "properties": {"answers": {"type": "object", "properties": one}}, "required": ["answers"]} + listed = "\n\n".join(f"{i}: {asks[q][0]}\n" + "\n".join(f"- {k}: {v}" for k, v in asks[q][1].items()) for i, q in ids.items()) + try: + reply = llm.json_out( + cfg, + "You take routine decisions. For each question pick the one option that fits, by its name, and say how sure " + "you are from 0 to 1: below 0.8 when the evidence is thin or two options fit.", + f"Questions:\n\n{listed}\n\nState:\n{_state(state)}", + schema, + ) + except llm.LLMError as e: + raise Undecided(str(e)) from None + out = {} + for i, q in ids.items(): + a, options = (reply.get("answers") or {}).get(i) or {}, asks[q][1] + if a.get("choice") not in options: + continue + conf = min(1.0, max(0.0, float(a.get("confidence") or 0))) + rest = (1 - conf) / max(1, len(options) - 1) + out[q] = { + "choice": a["choice"], + "confidence": conf, + "ranked": _ranked({k: conf if k == a["choice"] else rest for k in options}), + "by": "llm", + } + return out + + def sure(cfg, decision): """Whether a decision is sure enough to act on without asking.""" return decision["confidence"] >= float((cfg.get("decisions") or {}).get("act_above") or 0.8) diff --git a/fastapi_backend/app/domain/name_types.py b/fastapi_backend/app/domain/name_types.py index a31c77fe5..ce41e5f56 100644 --- a/fastapi_backend/app/domain/name_types.py +++ b/fastapi_backend/app/domain/name_types.py @@ -9,7 +9,9 @@ - PLACE: countries, regions, states and large cities (lexicon/places.txt); EVENT: holidays; DATE: days and months. - ORG, PRODUCT: well-known organisations and products (lexicon/organisations.txt, products.txt), and for PRODUCT a name with a number in it (iPhone 16). -A name none of these place is a TERM: a single unknown word (a brand, a project) needs a model to tell. +A name none of these place is a TERM: a single unknown word (a brand, a project) needs a model to tell. `ask` gives +such names to the decision model, with the lines they're said in (Settings › Analysis › Types the rules can't tell, +`analysis.typing`): by default only when a decision model is set up (Jev or Laya), never the language model. The given names are mostly the US Census Bureau's frequent first names of 1990 (public domain), with others added by hand; the places, organisations and products are written by hand (lexicon/). Words that are names but mostly something else on their own (Will, @@ -19,10 +21,14 @@ from __future__ import annotations import functools +import logging import pathlib import re +from . import decide + HERE = pathlib.Path(__file__).parent / "lexicon" +log = logging.getLogger("lens") TITLES = { "Dr", "Mr", @@ -298,3 +304,61 @@ def guess(name, lines=(), people=frozenset()): t = kind(words, people=people) return t return max(votes, key=lambda t: (votes[t], t == "PERSON")) if votes else None + + +# ---------- what the rules can't tell, a model may ---------- +ASKED = ("PERSON", "ORG", "PRODUCT", "PLACE", "EVENT", "WORK", "TERM") # the types a model picks from +TYPINGS = ("auto", "model", "rules") +BATCH = 20 # names in one call +MOST = 40 # names asked about at once (one recording, or one go of type_terms) +LINES = 2 # lines a name is said in, given with it + + +def _typing(cfg): + return (cfg.get("analysis") or {}).get("typing") or "auto" + + +def asking(cfg): + """Which model gives types to the names the rules leave terms (`analysis.typing`), or None: with "auto" (the + default) the decision model when one is set up (Jev or Laya), with "model" the language model too when none is, + with "rules" none. Decisions turned off (decisions.engine: off) is none either.""" + want = _typing(cfg) + how = decide.engine(cfg) + if want == "rules" or how is None: + return None + return how if how in decide.ENGINES or want == "model" else None + + +def said_in(name, lines, most=LINES): + """The first `most` lines `name` is said in, each cut to a sentence's length.""" + pat = re.compile(rf"(? option, sure of it; None (or no option) falls back to `answer` status = 200 def log_message(self, *a): @@ -22,6 +23,10 @@ def do_POST(self): answers = {} for name, q in body["questions"].items(): first = next(iter(q["criteria"])) + got = Handler.pick(q["instructions"], body["state"]) if Handler.pick else None + if got: + answers[name] = {"type": "choice", "choice": got, "confidence": 0.95, "probabilities": {got: 0.95}} + continue answers[name] = Handler.answer or {"type": "choice", "choice": first, "confidence": 1.0, "probabilities": {first: 1.0}} data = json.dumps({"model": "jev-1.13.0", "answers": answers, "usage": {"input_tokens": 400, "output_tokens": 40}}).encode() self.send_response(Handler.status) @@ -32,7 +37,7 @@ def do_POST(self): def start(cfg, key="jev-key"): - Handler.seen, Handler.answer, Handler.status = [], None, 200 + Handler.seen, Handler.answer, Handler.pick, Handler.status = [], None, None, 200 srv = http.server.ThreadingHTTPServer(("127.0.0.1", 0), Handler) threading.Thread(target=srv.serve_forever, daemon=True).start() cfg["decisions"] = {**cfg.get("decisions", {}), "base_url": f"http://127.0.0.1:{srv.server_address[1]}/v1", "api_key": key} diff --git a/fastapi_backend/tests/fake_llm.py b/fastapi_backend/tests/fake_llm.py index 55ed02f90..0d62d645a 100644 --- a/fastapi_backend/tests/fake_llm.py +++ b/fastapi_backend/tests/fake_llm.py @@ -15,6 +15,7 @@ class Handler(http.server.BaseHTTPRequestHandler): blind = False # behave like a server whose model can't see images names = None # namespace names suggested for a question (auto_scope.py) decision = None # the answer to a decision (decide.py) when no decision model is set up; else the first option + pick = None # a function (question) -> option, for several decisions in one call (decide.choose_all); else the first cypher_script = [] # Cypher to answer graph questions with (graph_ask.py), in order podcast_script = None # the lines a podcast script comes back with (podcasts.write), else a built-in one usage = None # token counts to report with each answer (and as a streamed answer's last chunk), like OpenAI @@ -215,6 +216,15 @@ def do_POST(self): title = re.search(r"^Title: (.*)$", text, re.M).group(1) first = text.split("Note:\n", 1)[1].strip().splitlines()[0] content = json.dumps({"title": "Capsid plan" if title == "Untitled" else title, "summary": f"About {first}"}) + elif set(schema.get("properties", {})) == {"answers"}: + # several decisions at once (decide.choose_all): Handler.pick's option for each question, else the first + asked = dict(re.findall(r"^(q\d+): (.*)$", body["messages"][-1]["content"], re.M)) + answers = {} + for i, a in schema["properties"]["answers"]["properties"].items(): + options = a["properties"]["choice"]["enum"] + got = Handler.pick(asked.get(i, "")) if Handler.pick else None + answers[i] = {"choice": got or options[0], "confidence": 0.9} + content = json.dumps({"answers": answers}) elif set(schema.get("properties", {})) == {"choice", "confidence"}: content = json.dumps(Handler.decision or {"choice": schema["properties"]["choice"]["enum"][0], "confidence": 0.9}) elif body.get("response_format"): diff --git a/nextjs-frontend/components/settings/bodies.tsx b/nextjs-frontend/components/settings/bodies.tsx index 2898d6be7..39a8b7899 100644 --- a/nextjs-frontend/components/settings/bodies.tsx +++ b/nextjs-frontend/components/settings/bodies.tsx @@ -251,6 +251,7 @@ export function SectionBody({ ctx }: { ctx: BodyCtx }) { )} {raw("analysis.entities") === "spacy" && } + yaml > json. Regenerate whenever the prose changes. schema: threat-model-sidecar/v2 project: lens -prose_version: "threat-model.md@sha256:44475d4514f343e65a581b45ce853b957961abe7f49de464f7da9972569857cb" +prose_version: "threat-model.md@sha256:2e578665b1ae8a2b7603b4a07cd5c17a1a4eb028655d371c5f1bce26ecc1a81c" model_status: under-review triage_policy: strict confidence: {documented: 204, maintainer: 46, inferred: 91, assumption: 8} @@ -1870,6 +1870,7 @@ known_misuses: - {id: km-wide-web-networks, components: [outbound], pattern: "Wide LENS_WEB_NETWORKS", x-why-unsafe: "Editors, and iCal feed redirects, can then reach those networks", safer_alternative: "List single hosts", x-provenance-basis: "§1.6 web_networks row; §1.13 private networks row", provenance: {kind: documented, source: 'docs/configuration.md "loopback and cloud metadata addresses stay out"'}} - {id: km-push-token-in-url, components: [optional], pattern: "Webhook push token in a URL that proxies log", x-why-unsafe: "The token is a credential in the path", safer_alternative: "Use the header form", x-provenance-basis: "§1.13 row 'Keep logs that record request paths private'", provenance: {kind: documented, source: 'docs/sensors.md "Ways in"'}} - {id: km-hosted-model-sensitive, components: [assistant], pattern: "Pointing the assistant at a hosted model for sensitive archives", x-why-unsafe: "Assets' text leaves the machine", safer_alternative: "Use a local model server", x-provenance-basis: "§1.13 row 'Pick model and speech servers you trust'", provenance: {kind: maintainer, date: "2026-10"}} + - {id: km-hosted-decision-model-sensitive, components: [assistant], pattern: "A hosted decision model (Jev) for sensitive archives", x-why-unsafe: "Routine choices send it excerpts, notes and the lines that name what analysis can't type", safer_alternative: "Use Laya, or set Settings › Analysis › Names the rules can't type to Leave them terms", x-provenance-basis: "§1.13 row 'Pick model and speech servers you trust'", provenance: {kind: maintainer, date: "2026-10"}} # ---------------------------------------------------------------- §1.15 known_non_findings: From edc7d44af3ba96bc808e810e471571eda97e74a5 Mon Sep 17 00:00:00 2001 From: Adeel Ahmad Date: Thu, 15 Oct 2026 11:06:52 +0000 Subject: [PATCH 2/3] fix(entities): keep vocabulary terms and plain question ids when the model types names Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_018MeaEgM8m7rTjbkKVQVsrT --- fastapi_backend/app/domain/analyze.py | 10 ++++++---- fastapi_backend/app/domain/decide.py | 8 ++++---- fastapi_backend/tests/domain/test_name_types.py | 6 ++++++ 3 files changed, 16 insertions(+), 8 deletions(-) diff --git a/fastapi_backend/app/domain/analyze.py b/fastapi_backend/app/domain/analyze.py index 7b97a7cc0..0860a9069 100644 --- a/fastapi_backend/app/domain/analyze.py +++ b/fastapi_backend/app/domain/analyze.py @@ -446,16 +446,18 @@ def one_type(seg_ents): return [[(n, best.get(ent_key(n), t)) for n, t in es] for es in seg_ents] -def model_types(db, cfg, nid, segs, seg_ents): +def model_types(db, cfg, nid, segs, seg_ents, gaz=()): """The terms of a recording that aren't entities yet, given the type a model is sure of (name_types.ask). A short - form of a longer name said here ("Johnson" of "Sarah Johnson") takes that name's type later, so it isn't asked.""" + form of a longer name said here ("Johnson" of "Sarah Johnson") takes that name's type later, and a name the custom + vocabulary (`gaz`) lists is the type it says, a term too; neither is asked.""" if not name_types.asking(cfg): return seg_ents + listed = {ent_key(g[0]) for g in gaz} terms = {} for es in seg_ents: for n, t in es: k = ent_key(n) - if k and t == "TERM": + if k and t == "TERM" and k not in listed: terms.setdefault(k, n) keys = {ent_key(n) for es in seg_ents for n, _ in es} terms = {k: n for k, n in terms.items() if not any(L.endswith(" " + k) for L in keys)} @@ -511,7 +513,7 @@ def analyze_recording(db, cfg, rid, seg_ents=None, say=None): es.extend(h for h in hints if ent_key(h[0]) not in have) seg_ents = one_type(seg_ents) if given is None and not listed: # names the rules can't tell: a model may (Settings › Analysis) - seg_ents = model_types(db, cfg, nid, segs, seg_ents) + seg_ents = model_types(db, cfg, nid, segs, seg_ents, gaz) if setup["types"] and not listed: # the namespace (or collection) keeps only some types seg_ents = [[(n, t) for n, t in es if entity_setup.keeps(setup, t)] for es in seg_ents] surface = {t: c.most_common(1)[0][0] for t, c in ts.items()} diff --git a/fastapi_backend/app/domain/decide.py b/fastapi_backend/app/domain/decide.py index dbc46aa06..d91b1795c 100644 --- a/fastapi_backend/app/domain/decide.py +++ b/fastapi_backend/app/domain/decide.py @@ -219,14 +219,15 @@ def choose_all(cfg, asks, state, language_model=True): asks = {q: (text, dict(o)) for q, (text, o) in asks.items() if o} if not asks: return {} + ids = {f"q{i}": q for i, q in enumerate(asks)} # plain names for the questions, whatever the caller's ids how = engine(cfg) if how in ENGINES: - questions = {q: {"type": "choice", "instructions": text, "criteria": o} for q, (text, o) in asks.items()} + questions = {i: {"type": "choice", "instructions": asks[q][0], "criteria": asks[q][1]} for i, q in ids.items()} try: answers = ENGINES[how](cfg, questions, state) out = {} - for q, (_, o) in asks.items(): - a = answers.get(q) or {} + for i, q in ids.items(): + a, o = answers.get(i) or {}, asks[q][1] if a.get("choice") in o: probs = a.get("probabilities") or {a["choice"]: a.get("confidence", 0)} out[q] = {"choice": a["choice"], "confidence": float(a.get("confidence") or 0), "ranked": _ranked(probs), "by": how} @@ -238,7 +239,6 @@ def choose_all(cfg, asks, state, language_model=True): how = "llm" if llm.configured(cfg) else None if how != "llm" or not language_model: raise Undecided("no decision model is set up" if not language_model else "no decision model or language model is set up") - ids = {f"q{i}": q for i, q in enumerate(asks)} one = { i: { "type": "object", diff --git a/fastapi_backend/tests/domain/test_name_types.py b/fastapi_backend/tests/domain/test_name_types.py index 59bc70cbf..550cc849b 100644 --- a/fastapi_backend/tests/domain/test_name_types.py +++ b/fastapi_backend/tests/domain/test_name_types.py @@ -176,6 +176,12 @@ def test_the_decision_model_types_what_the_rules_cant(db, cfg, folder, jev): assert len(jev.seen) == 1 # an entity already: not asked again +def test_a_term_the_custom_vocabulary_lists_isnt_asked(db, cfg, folder, jev): + cfg["analysis"]["gazetteer"] = ["Quillmark"] # a term, as the vocabulary says + jev.pick = _quillmark + assert _analysed(db, cfg, folder)["Quillmark"] == "TERM" and not jev.seen + + def test_a_type_the_model_isnt_sure_of_stays_a_term(db, cfg, folder, jev): jev.answer = {"type": "choice", "choice": "ORG", "confidence": 0.5, "probabilities": {"ORG": 0.5, "PRODUCT": 0.4}} assert _analysed(db, cfg, folder)["Quillmark"] == "TERM" From bec640ce600e2aaf476a0e99629b539e3b587d00 Mon Sep 17 00:00:00 2001 From: Adeel Ahmad Date: Sat, 17 Oct 2026 04:07:12 +0000 Subject: [PATCH 3/3] docs(readme): list the decision model's typing as built, with its checks Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_018MeaEgM8m7rTjbkKVQVsrT --- README.md | 5 +++-- docs/requirements.md | 1 + 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index efb4f94d9..1c786bdb4 100644 --- a/README.md +++ b/README.md @@ -118,8 +118,9 @@ listed under [In progress](#in-progress), and what comes next under [Planned](#p SPARQL, and see as it was at any version. Every entity has its own page at a wiki address (`/wiki//`), and entities, topics and people are edited and merged from their lists, the graph or an asset, with Undo instead of a confirm. Names get their real types (people, places, organisations, events, works) by - rules, without a model. Find what is most like a passage, an asset, a topic or an entity, in a Similar - tab on every asset or by selecting text anywhere, and, with anytopdf, photos by what they show. + rules, without a model, and a decision model types the ones the rules can't. Find what is most like a passage, an + asset, a topic or an entity, in a Similar tab on every asset or by selecting text anywhere, and, with anytopdf, photos + by what they show. ([Graph](docs/graph.md), [entity pages](docs/notes.md#entity-pages), [similar content](docs/processing.md#similar-content), [graph history](docs/graph-history.md), [topics](docs/topics.md), [video](docs/video.md), [NSFW classification](docs/nsfw.md), diff --git a/docs/requirements.md b/docs/requirements.md index 19dbb8caf..4260651c2 100644 --- a/docs/requirements.md +++ b/docs/requirements.md @@ -140,6 +140,7 @@ request, to another check that proves the same thing; loosening a requirement or | Every entity's own page at `/wiki//` | [test_entities.py](https://github.com/adeelahmad/lense/blob/main/fastapi_backend/tests/api/test_entities.py) `test_wiki_addresses`; [wiki-page.test.tsx](https://github.com/adeelahmad/lense/blob/main/nextjs-frontend/__tests__/wiki-page.test.tsx); [journeys.mjs](https://github.com/adeelahmad/lense/blob/main/ci/clicks/journeys.mjs) `entity-find` | | Entities, topics and people edited and merged from their lists, the graph or an asset, with Undo instead of a confirm | [test_entities.py](https://github.com/adeelahmad/lense/blob/main/fastapi_backend/tests/domain/test_entities.py) `test_suggestions_and_merge_undo`; [entities-curate.test.tsx](https://github.com/adeelahmad/lense/blob/main/nextjs-frontend/__tests__/entities-curate.test.tsx); [topics-curate.test.tsx](https://github.com/adeelahmad/lense/blob/main/nextjs-frontend/__tests__/topics-curate.test.tsx); [recording-entities-edit.test.tsx](https://github.com/adeelahmad/lense/blob/main/nextjs-frontend/__tests__/recording-entities-edit.test.tsx); [journeys.mjs](https://github.com/adeelahmad/lense/blob/main/ci/clicks/journeys.mjs) `entity-merge`, `graph-merge`, `speaker-rename` | | Names get their real types (people, places, organisations, events, works) by rules, without a model; older Terms are typed on upgrade | [test_name_types.py](https://github.com/adeelahmad/lense/blob/main/fastapi_backend/tests/domain/test_name_types.py) `test_names_get_the_type_their_words_give`, `test_analysis_types_people_places_and_events`, `test_the_upgrade_types_the_old_terms_and_keeps_what_people_chose` | +| A decision model (Jev or Laya) types the names the rules leave as Terms, in one call, keeping only types it is sure of; Settings › Analysis can leave them Terms | [test_name_types.py](https://github.com/adeelahmad/lense/blob/main/fastapi_backend/tests/domain/test_name_types.py) `test_the_decision_model_types_what_the_rules_cant`, `test_a_type_the_model_isnt_sure_of_stays_a_term`, `test_by_default_the_language_model_isnt_asked`, `test_with_typing_rules_nothing_is_asked` | | What is most like a passage, an asset, a topic or an entity | [test_similar.py](https://github.com/adeelahmad/lense/blob/main/fastapi_backend/tests/api/test_similar.py) `test_like_a_text_by_its_key_words`, `test_like_a_resource_by_words_topics_and_entities`, `test_like_a_topic_and_an_entity`; [similar.test.tsx](https://github.com/adeelahmad/lense/blob/main/nextjs-frontend/__tests__/similar.test.tsx) | | With anytopdf, photos found by what they show | [test_photos.py](https://github.com/adeelahmad/lense/blob/main/fastapi_backend/tests/api/test_photos.py) `test_photos_found_by_what_they_show`, `test_off_by_default` |