ltcai 11.4.0 → 11.5.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (86) hide show
  1. package/README.md +55 -44
  2. package/docs/CHANGELOG.md +48 -0
  3. package/docs/COMMUNITY_AND_PLUGINS.md +1 -1
  4. package/docs/DEVELOPMENT.md +1 -1
  5. package/docs/ONBOARDING.md +1 -1
  6. package/docs/OPERATIONS.md +1 -1
  7. package/docs/TRUST_MODEL.md +1 -1
  8. package/docs/WHY_LATTICE.md +1 -1
  9. package/docs/kg-schema.md +1 -1
  10. package/docs/v11.4.0_RUST_FOUNDATION_PLAN.md +11 -6
  11. package/docs/v11.5.0_RUST_COMPLETE_PLAN.md +145 -0
  12. package/docs/v11.5.1_RUST_FULL_LOOP_PLAN.md +85 -0
  13. package/lattice_brain/__init__.py +1 -1
  14. package/lattice_brain/runtime/multi_agent.py +1 -1
  15. package/latticeai/__init__.py +1 -1
  16. package/latticeai/api/agent_worker_seam.py +389 -0
  17. package/latticeai/api/index_jobs.py +145 -0
  18. package/latticeai/core/legacy_compatibility.py +1 -1
  19. package/latticeai/core/marketplace.py +1 -1
  20. package/latticeai/core/messages.py +40 -0
  21. package/latticeai/core/workspace_os_constants.py +1 -1
  22. package/latticeai/runtime/build_phases/features.py +37 -2
  23. package/latticeai/services/architecture_readiness.py +1 -1
  24. package/latticeai/services/product_readiness.py +1 -1
  25. package/package.json +1 -1
  26. package/scripts/check_current_release_docs.mjs +1 -1
  27. package/scripts/check_server_i18n.mjs +2 -0
  28. package/scripts/chunking_parity_corpus.py +449 -0
  29. package/scripts/generate_agent_loop_fixtures.py +907 -0
  30. package/scripts/generate_agent_parity_fixtures.py +752 -0
  31. package/scripts/generate_chunking_parity_fixtures.py +259 -0
  32. package/scripts/generate_rust_parity_fixtures.py +541 -103
  33. package/scripts/parity_fixture_corpus_docgen.py +341 -0
  34. package/scripts/release_screen_claims.json +21 -0
  35. package/src-tauri/Cargo.lock +53 -4
  36. package/src-tauri/Cargo.toml +11 -4
  37. package/src-tauri/src/backend.rs +251 -140
  38. package/src-tauri/src/main.rs +16 -4
  39. package/src-tauri/src/topology.rs +356 -0
  40. package/src-tauri/tauri.conf.json +1 -1
  41. package/static/app/asset-manifest.json +41 -41
  42. package/static/app/assets/{Act-yYpYnn0v.js → Act-Drs_jd-O.js} +1 -1
  43. package/static/app/assets/{AdminConsole-DL3Cr5pL.js → AdminConsole-BqNx5oF6.js} +1 -1
  44. package/static/app/assets/{Brain-C1HBN0Wf.js → Brain-C7bdNmz-.js} +1 -1
  45. package/static/app/assets/{BrainHome-DoXRhUUC.js → BrainHome-DcTnINcI.js} +1 -1
  46. package/static/app/assets/{BrainSignals-6yR6ir5t.js → BrainSignals-Df1MRIPD.js} +1 -1
  47. package/static/app/assets/{Capture-CFIRsFNE.js → Capture-Dgsxvnbx.js} +1 -1
  48. package/static/app/assets/{Chronicle-BZbEgiwN.js → Chronicle-BrkTxJK1.js} +1 -1
  49. package/static/app/assets/{CommandPalette-D2pMxC2I.js → CommandPalette-DDziw7Oj.js} +1 -1
  50. package/static/app/assets/{Library-DwO3yZST.js → Library-CYxeuraA.js} +1 -1
  51. package/static/app/assets/{LivingBrain-Jn1GK0-S.js → LivingBrain-CNp6mvCm.js} +1 -1
  52. package/static/app/assets/{ProductFlow-B-w1R4Oo.js → ProductFlow-BVsowu3Z.js} +1 -1
  53. package/static/app/assets/{ReviewCard-6B27X8Vg.js → ReviewCard-D1LbOfJS.js} +1 -1
  54. package/static/app/assets/{System-DW8F-2xL.js → System-DcRAq7wj.js} +1 -1
  55. package/static/app/assets/arrow-left-BHYmOTWU.js +1 -0
  56. package/static/app/assets/{bot-IM_E_Y12.js → bot-BK2xQ9mN.js} +1 -1
  57. package/static/app/assets/{brain-Ci1CkWjM.js → brain-BZNztFBb.js} +1 -1
  58. package/static/app/assets/{button-COwyqfHM.js → button-CjueubVZ.js} +1 -1
  59. package/static/app/assets/circle-check-CLeWJr67.js +1 -0
  60. package/static/app/assets/{circle-pause-DEM4A1Y5.js → circle-pause-HRjSmpyY.js} +1 -1
  61. package/static/app/assets/{circle-play-C9djDuLd.js → circle-play-CMcKDVwu.js} +1 -1
  62. package/static/app/assets/{cpu-DFdo1gw-.js → cpu-B_MyTfYr.js} +1 -1
  63. package/static/app/assets/{download-SnJL6oqk.js → download-CTy0EByV.js} +1 -1
  64. package/static/app/assets/{folder-open-CqZeDkjE.js → folder-open-DF6bLhTg.js} +1 -1
  65. package/static/app/assets/{hard-drive-j1jJXYYf.js → hard-drive-CpWHG77C.js} +1 -1
  66. package/static/app/assets/{index-_u5iUHDr.js → index-Dd6abJHX.js} +3 -3
  67. package/static/app/assets/index-DxmOfNRi.css +2 -0
  68. package/static/app/assets/{input-B0lPdRQZ.js → input-bVgIRN3s.js} +1 -1
  69. package/static/app/assets/{link-2-CoFbooHS.js → link-2-bg6CG5Vk.js} +1 -1
  70. package/static/app/assets/{permissionCopy-BsyLxtao.js → permissionCopy-DFTf1HDZ.js} +1 -1
  71. package/static/app/assets/{primitives-DEbN-d6p.js → primitives-D7D-sQ3T.js} +1 -1
  72. package/static/app/assets/search-BgSVX6NG.js +1 -0
  73. package/static/app/assets/{share-2-CVtZ_ewX.js → share-2-BLzo7U4L.js} +1 -1
  74. package/static/app/assets/{shield-alert-CBi2GNWM.js → shield-alert-BmngqnsJ.js} +1 -1
  75. package/static/app/assets/{textarea-DNMpB5ih.js → textarea-DOSlAQQ3.js} +1 -1
  76. package/static/app/assets/{useFocusTrap-C83t3GXF.js → useFocusTrap-pZhgeee4.js} +1 -1
  77. package/static/app/assets/{useMutation-DtbJDoyz.js → useMutation-BMDwNk4I.js} +1 -1
  78. package/static/app/assets/{useQuery-Dcp1OChy.js → useQuery-CSjKttRo.js} +1 -1
  79. package/static/app/assets/{utils-BlZr7Pd4.js → utils-D3u_yv7B.js} +1 -1
  80. package/static/app/assets/{workspace-jJY4RuAV.js → workspace-H3bMjYXC.js} +1 -1
  81. package/static/app/index.html +4 -4
  82. package/static/sw.js +1 -1
  83. package/static/app/assets/arrow-left-DXvKg9U6.js +0 -1
  84. package/static/app/assets/circle-check-DfInj-qD.js +0 -1
  85. package/static/app/assets/index-BLPb5lmE.css +0 -2
  86. package/static/app/assets/search-BybIWPNd.js +0 -1
@@ -6,27 +6,23 @@ something keeps proving it is still one. This script is the Python half of that
6
6
  proof: it builds a small, fully deterministic Brain with the **real** write path
7
7
  (``KnowledgeGraphStore._upsert_node`` / ``_upsert_chunk`` / ``_upsert_edge``,
8
8
  the real hash embedder, the real v2 projection and trigram FTS index), then runs
9
- the real ``hybrid_search`` / ``search`` / ``vector_search`` over it and writes
10
- their answers to ``rust/fixtures/golden/``.
11
-
12
- Two consumers read what it writes:
13
-
14
- * ``tests/unit/test_rust_parity_contract.py`` re-runs the Python engines against
15
- the committed database and asserts the goldens still hold — so a change to
16
- Python retrieval semantics fails loudly instead of silently invalidating the
17
- contract the Rust side is pinned to;
18
- * ``rust/lattice-retrieval/tests/parity.rs`` runs the Rust port against the same
19
- database and the same goldens.
20
-
21
- Determinism is the whole design constraint:
22
-
23
- * every timestamp is written by the real code and then **backdated** to a fixed
24
- value, so nothing in the fixture depends on when it was generated;
25
- * ``hybrid_search``'s recency decay calls ``datetime.now()``, so the clock is
26
- frozen at :data:`FROZEN_NOW` (recorded in the manifest for the Rust side);
27
- * LLM concept extraction is forced off, so ``_topic_candidates`` always takes
28
- the rule-based path a port can reproduce;
29
- * every environment knob the retrieval stack reads is pinned to its default.
9
+ the real engines over it and writes their answers to ``rust/fixtures/golden/``.
10
+ The suite set widens with the port (:data:`SUITES`): the search engines
11
+ (v11.4.0); the KG relationship/traverse reads, the service layer, the durable
12
+ history reads and the context assembler (v11.5.0); the document-generation
13
+ search, traversal and context builder (v11.5.1, whose corpus and runners live
14
+ in ``scripts/parity_fixture_corpus_docgen.py``).
15
+
16
+ Two consumers read what it writes: ``tests/unit/test_rust_parity_contract.py``
17
+ re-runs the Python entry points against the committed database and asserts the
18
+ goldens still hold — so a change to Python semantics fails loudly instead of
19
+ silently invalidating the contract the Rust side is pinned to — and
20
+ ``rust/lattice-retrieval/tests/{parity,suites}.rs`` run the Rust ports against
21
+ the same database and the same goldens. Determinism is the whole design
22
+ constraint: every timestamp is written by the real code and then **backdated**;
23
+ every ``datetime.now()`` the ports reach is frozen at :data:`FROZEN_NOW`
24
+ (recorded in the manifest); LLM concept extraction is forced off; every
25
+ environment knob is pinned to its default.
30
26
 
31
27
  Usage::
32
28
 
@@ -36,6 +32,7 @@ Usage::
36
32
  from __future__ import annotations
37
33
 
38
34
  import json
35
+ import logging
39
36
  import os
40
37
  import shutil
41
38
  import sqlite3
@@ -46,20 +43,24 @@ from pathlib import Path
46
43
  from typing import Any, Callable, Dict, Iterator, List, Optional, Tuple
47
44
 
48
45
  REPO_ROOT = Path(__file__).resolve().parents[1]
49
- if str(REPO_ROOT) not in sys.path:
50
- sys.path.insert(0, str(REPO_ROOT))
46
+ # The repo (for the product packages) and this directory: `scripts` is not a
47
+ # package, so the docgen corpus is imported by name off the script directory —
48
+ # the same by-path convention the contract test uses to import this file.
49
+ for _import_root in (REPO_ROOT, Path(__file__).resolve().parent):
50
+ if str(_import_root) not in sys.path:
51
+ sys.path.insert(0, str(_import_root))
52
+
53
+ import parity_fixture_corpus_docgen as docgen # noqa: E402
51
54
 
52
55
  FIXTURE_DIR = REPO_ROOT / "rust" / "fixtures"
53
56
  GOLDEN_DIR = FIXTURE_DIR / "golden"
54
57
  STORE_PATH = FIXTURE_DIR / "parity_store.sqlite"
55
58
 
56
- #: The wall clock ``hybrid_search`` sees. Recency decay is a function of "now",
57
- #: so a golden generated against a moving clock is not a golden.
59
+ #: The wall clock the ports see: a golden built against a moving clock is none.
58
60
  FROZEN_NOW = "2026-08-01T12:00:00"
59
61
 
60
- #: Every environment variable the ported path reads, pinned to the default
61
- #: configuration the port targets (brute backend, RRF off, graph expansion off,
62
- #: cross-encoder rerank off, rewrite on).
62
+ #: Every environment variable the ported path reads, pinned to the configuration
63
+ #: it targets (brute backend, RRF/expansion/rerank off, rewrite on).
63
64
  PINNED_ENV: Dict[str, str] = {
64
65
  "LATTICEAI_VECTOR_DIM": "384",
65
66
  "LATTICEAI_VECTOR_INDEX": "brute",
@@ -80,16 +81,12 @@ WS_BETA = "ws-beta"
80
81
  # ── the corpus ───────────────────────────────────────────────────────────────
81
82
  # (node_id, type, title, summary, metadata, workspace_id, updated_at)
82
83
  #
83
- # Shaped on purpose:
84
- # * every type in ``search()``'s fixed ``type_boost`` set appears, and so do
85
- # types outside it, so the boost is observable;
86
- # * titles/summaries are half Korean and half English, because the tokenizer,
87
- # the query classifier and the concept extractor all branch on script;
88
- # * the ``tie:`` block is five rows sharing one timestamp and one type with
89
- # nothing to match, which pins the (hits, type_boost, updated_at) → id ASC
90
- # tie-break that both engines have to reproduce;
91
- # * two workspaces plus NULL-workspace legacy rows cover all three scoping
92
- # answers (no scoping / empty set / a specific workspace).
84
+ # Shaped on purpose: every ``type_boost`` type appears and so do types outside it;
85
+ # titles/summaries are half Korean (tokenizer, classifier and extractor all branch
86
+ # on script); the ``tie:`` block is five rows sharing one timestamp, one type and
87
+ # nothing to match, pinning the (hits, boost, updated_at) → id ASC tie-break; two
88
+ # workspaces plus NULL-workspace rows cover all three scoping answers (no scoping
89
+ # / empty set / a specific workspace). The v11.5.1 tail is in the docgen corpus.
93
90
  NODES: List[Tuple[str, str, str, str, Dict[str, Any], Optional[str], str]] = [
94
91
  ("dec:fusion-alpha", "Decision", "Hybrid retrieval fusion stays alpha weighted",
95
92
  "We decided the ranking keeps alpha fusion: lexical rank plus max normalized vector score.",
@@ -191,15 +188,14 @@ NODES: List[Tuple[str, str, str, str, Dict[str, Any], Optional[str], str]] = [
191
188
  ("legacy:global-note", "Document", "Legacy global note",
192
189
  "A legacy row with no workspace, visible only with include_legacy_global.",
193
190
  {}, None, "2026-06-20T10:00:00"),
191
+ *docgen.DOCGEN_NODES,
194
192
  ]
195
193
 
196
194
  # (chunk_id, parent_node_id, index, node_title, text, chunk_fields, workspace, updated_at)
197
195
  #
198
- # The shape mirrors ``KnowledgeGraphIngestMixin``: every chunk is BOTH a
199
- # ``Chunk`` node (so the lexical lane can match it and workspace scoping applies)
200
- # and a ``chunks`` row with its own embedding (so the vector lane returns it and
201
- # has to roll it up to its parent). Getting that duality wrong is the whole
202
- # reason chunk-heavy queries are in the query set.
196
+ # The shape mirrors ``KnowledgeGraphIngestMixin``: every chunk is BOTH a ``Chunk``
197
+ # node (lexical lane + workspace scoping) and a ``chunks`` row with its own embedding
198
+ # (vector lane, rolled up to its parent) — the duality chunk-heavy queries pin.
203
199
  CHUNKS: List[Tuple[str, str, int, str, str, Dict[str, Any], Optional[str], str]] = [
204
200
  ("chunk:handbook:1", "doc:handbook", 0, "handbook.pdf chunk 1",
205
201
  "온보딩 체크리스트: 첫째, 폴더를 연결합니다. 둘째, 질문을 합니다. 셋째, 근거를 확인합니다.",
@@ -218,14 +214,75 @@ CHUNKS: List[Tuple[str, str, int, str, str, Dict[str, Any], Optional[str], str]]
218
214
  {"start_char": 900}, WS_BETA, "2026-05-28T13:15:02"),
219
215
  ]
220
216
 
221
- # (from, to, type)
222
- EDGES: List[Tuple[str, str, str]] = [
223
- ("dec:fusion-alpha", "concept:retrieval", "mentions"),
224
- ("dec:fusion-alpha", "concept:ranking", "mentions"),
225
- ("task:parity-harness", "dec:rust-foundation", "relates_to"),
226
- ("doc:handbook", "page:onboarding", "contains"),
227
- ("meeting:weekly", "dec:fusion-alpha", "discusses"),
228
- ("person:jiwon", "task:parity-harness", "owns"),
217
+ # (from, to, type, weight, created_at)
218
+ #
219
+ # Weights and timestamps are assigned rather than inherited: ``relationship_search``
220
+ # orders by ``weight DESC, created_at DESC, id ASC`` and ``traverse`` caps every BFS
221
+ # round with ``ORDER BY weight DESC, id ASC``, so an edge set sharing one weight and
222
+ # one clock proves nothing. Three shapes are deliberate — a weight tie broken by
223
+ # ``created_at`` (``org:lattice``), a weight *and* clock tie broken by edge id
224
+ # (``topic:quality``/``deck:review``), and legacy-global endpoints for scoping. The
225
+ # write door canonicalizes types (``relates_to``/``owns`` → ``MENTIONS``), which is
226
+ # why the goldens record uppercase names the fixture never spells.
227
+ EDGES: List[Tuple[str, str, str, float, str]] = [
228
+ ("dec:fusion-alpha", "concept:retrieval", "mentions", 0.9, "2026-07-01T00:00:00"),
229
+ ("dec:fusion-alpha", "concept:ranking", "mentions", 0.8, "2026-07-02T00:00:00"),
230
+ ("task:parity-harness", "dec:rust-foundation", "relates_to", 1.0, "2026-07-03T00:00:00"),
231
+ ("doc:handbook", "page:onboarding", "contains", 0.7, "2026-07-04T00:00:00"),
232
+ ("meeting:weekly", "dec:fusion-alpha", "discusses", 0.95, "2026-07-05T00:00:00"),
233
+ ("person:jiwon", "task:parity-harness", "owns", 0.6, "2026-07-06T00:00:00"),
234
+ ("person:minseo", "code:build-failure", "owns", 0.6, "2026-07-07T00:00:00"),
235
+ ("meeting:weekly", "task:onboarding-checklist", "discusses", 0.55, "2026-07-08T00:00:00"),
236
+ ("meeting:kickoff", "dec:rust-foundation", "discusses", 0.5, "2026-06-01T00:00:00"),
237
+ ("doc:retrieval-spec", "concept:ranking", "mentions", 0.45, "2026-06-02T00:00:00"),
238
+ ("concept:retrieval", "concept:ranking", "relates_to", 0.4, "2026-06-03T00:00:00"),
239
+ ("file:ranking-notes", "dec:fusion-alpha", "relates_to", 0.35, "2026-06-04T00:00:00"),
240
+ ("code:hybrid-search", "file:ranking-notes", "relates_to", 0.3, "2026-06-05T00:00:00"),
241
+ # Same weight, different clock → created_at DESC decides.
242
+ ("org:lattice", "person:jiwon", "contains", 0.25, "2026-06-06T00:00:00"),
243
+ ("org:lattice", "person:minseo", "contains", 0.25, "2026-06-07T00:00:00"),
244
+ ("slide:fusion", "concept:retrieval", "mentions", 0.25, "2026-06-08T00:00:00"),
245
+ # Same weight AND same clock → the id ASC tie-break is the only thing left.
246
+ ("topic:quality", "deck:review", "relates_to", 0.2, "2026-06-09T00:00:00"),
247
+ ("deck:review", "meeting:weekly", "relates_to", 0.2, "2026-06-09T00:00:00"),
248
+ ("task:onboarding-checklist", "page:onboarding", "relates_to", 0.15, "2026-05-01T00:00:00"),
249
+ ("doc:handbook", "doc:retrieval-spec", "relates_to", 0.1, "2026-05-02T00:00:00"),
250
+ ("tie:a", "tie:b", "relates_to", 1.0, "2026-07-03T00:00:00"),
251
+ *docgen.DOCGEN_EDGES,
252
+ ]
253
+
254
+ # ── the conversation corpus (episodic memory, same database file) ────────────
255
+ # (conversation_id, role, content, user_email, nickname, source, timestamp,
256
+ # workspace_id, organization_id, extra)
257
+ #
258
+ # Every branch the history reads take: two users × three workspaces, NULL and
259
+ # empty-string workspaces (the legacy rows ``_scope_sql`` admits), rows with no
260
+ # ``conversation_id`` (the ``legacy-previous-history`` bucket), a whitespace-only
261
+ # first message (the ``새 대화`` placeholder and its later upgrade), an
262
+ # assistant-first conversation (no upgrade), an empty timestamp (the ``or ""``
263
+ # fallbacks), extra keys ``metadata_json`` merges flat, ko/en content.
264
+ MESSAGES: List[Tuple[Any, ...]] = [
265
+ ("conv-a", "user", "온보딩 체크리스트 어떻게 시작해?", "jiwon@lattice.ai", "지원", "web", "2026-07-20T09:00:00", WS_ALPHA, "org-1", {}),
266
+ ("conv-a", "assistant", "먼저 폴더를 연결하세요. 그다음 질문하면 됩니다.", "jiwon@lattice.ai", None, "web", "2026-07-20T09:00:05", WS_ALPHA, "org-1", {}),
267
+ ("conv-a", "user", "고마워", "jiwon@lattice.ai", "지원", "web", "2026-07-20T09:01:00", WS_ALPHA, "org-1", {"trace_id": "t-1"}),
268
+ ("conv-b", "user", "How does hybrid retrieval ranking work?", "minseo@lattice.ai", "Minseo", "telegram", "2026-07-21T10:00:00", WS_BETA, "org-1", {}),
269
+ ("conv-b", "assistant", "The lexical channel scores one over rank.", "minseo@lattice.ai", None, "telegram", "2026-07-21T10:00:07", WS_BETA, "org-1", {"tokens": 42, "cited": ["doc:retrieval-spec"]}),
270
+ ("conv-c", "user", " \n ", None, None, None, "2026-07-22T08:00:00", None, None, {}),
271
+ ("conv-c", "assistant", "무엇을 도와드릴까요?", None, None, None, "2026-07-22T08:00:05", None, None, {}),
272
+ ("conv-c", "user", "지난주 회의 기록 보여줘", None, None, None, "2026-07-22T08:01:00", None, None, {}),
273
+ (None, "user", "이전 대화 기록입니다", "jiwon@lattice.ai", "지원", "web", "2026-06-01T09:00:00", "", None, {}),
274
+ (None, "assistant", "네, 확인했습니다.", "jiwon@lattice.ai", None, "web", "2026-06-01T09:00:03", "", None, {}),
275
+ (None, "user", "legacy english message about ranking", None, None, None, "", None, None, {}),
276
+ ("conv-d", "user", "빌드 실패 원인 알려줘", "minseo@lattice.ai", "Minseo", "vscode", "2026-07-23T11:00:00", WS_ALPHA, "org-1", {}),
277
+ ("conv-d", "assistant", "컴파일 오류 로그를 확인하세요.", "minseo@lattice.ai", None, "vscode", "2026-07-23T11:00:04", WS_ALPHA, "org-1", {}),
278
+ ("conv-e", "user", "Ranking ties are broken by node id", "jiwon@lattice.ai", "지원", "web", "2026-07-24T12:00:00", WS_BETA, "org-2", {}),
279
+ ("conv-e", "assistant", "Yes — id ascending keeps it stable.", "jiwon@lattice.ai", None, "web", "2026-07-24T12:00:05", WS_BETA, "org-2", {}),
280
+ ("conv-f", "user", "검색 품질을 어떻게 측정하나요? 재현율과 정밀도를 모두 보고 싶고 주간 회의에서 공유할 예정입니다.", None, None, "web", "2026-07-25T13:00:00", None, None, {}),
281
+ ("conv-f", "assistant", "재현율/정밀도 지표는 분기 리뷰 발표자료에 있습니다.", None, None, "web", "2026-07-25T13:00:05", None, None, {}),
282
+ ("conv-g", "assistant", "assistant-first conversation", None, None, "web", "2026-07-26T14:00:00", None, None, {}),
283
+ ("conv-g", "user", "follow up question about ranking", None, None, "web", "2026-07-26T14:00:10", None, None, {}),
284
+ ("conv-h", "user", "Empty user and empty workspace row", "", "", "", "2026-07-27T15:00:00", "", "", {}),
285
+ ("conv-h", "assistant", "회의 결정 사항을 정리했습니다.", "", "", "", "2026-07-27T15:00:06", "", "", {}),
229
286
  ]
230
287
 
231
288
  # ── the query set ────────────────────────────────────────────────────────────
@@ -253,25 +310,178 @@ QUERIES: List[Dict[str, Any]] = [
253
310
  {"key": "ws_alpha", "query": "hybrid retrieval ranking", "allowed": [WS_ALPHA]},
254
311
  {"key": "ws_alpha_legacy", "query": "회의 결정 사항", "allowed": [WS_ALPHA], "legacy": True},
255
312
  {"key": "ws_beta", "query": "온보딩 체크리스트", "allowed": [WS_BETA]},
256
- # A vector floor nothing clears: the lane returns zero rows, which is the
257
- # only way to reach the stale-embedder probe and the lexical-only fusion
258
- # label without breaking the store.
313
+ # A vector floor nothing clears: the stale-embedder probe and the
314
+ # lexical-only fusion label, without breaking the store.
259
315
  {"key": "min_vector_floor", "query": "hybrid retrieval ranking", "min_vector": 0.95},
260
- # A small top_k so the rerank window (top_k * 2) is narrower than the
261
- # candidate list and the cut is observable.
316
+ # top_k small enough that the rerank window (top_k * 2) cuts the candidates.
262
317
  {"key": "top_k_small", "query": "hybrid retrieval ranking", "top_k": 3},
263
- # An explicitly pinned alpha: no policy, so no class, no rewrite and — on a
264
- # query that would otherwise be recency-classed — no age decay either.
318
+ # Pinned alpha: no policy, so no class/rewrite/age decay on a recency query.
265
319
  {"key": "alpha_pinned", "query": "지난주 회의 기록", "alpha": 0.2},
266
- # A limit below the FTS hit count, so `ORDER BY rank LIMIT ?` decides which
267
- # rows exist at all. This is the one place bm25 ordering is observable
268
- # (`search()` re-sorts by id afterwards), and therefore the one place a
269
- # SQLite version difference between the two runtimes could show up.
320
+ # A limit below the FTS hit count, so `ORDER BY rank LIMIT ?` decides which rows
321
+ # exist at all — the one place bm25 ordering (a SQLite version difference) shows.
270
322
  {"key": "fts_rank_cut", "query": "Tie candidate", "limit": 2, "top_k": 2},
271
323
  ]
272
324
 
273
- #: Texts whose tokenizer output, hash pairs and full vectors pin the Rust
274
- #: embedding port bit-for-bit (Korean, English, mixed, symbols, digits).
325
+ #: Every branch of the memories section: a workspace hit, one with no kind and an
326
+ #: empty snippet, a non-workspace row to drop, and one past the limit.
327
+ CONTEXT_MEMORIES: Dict[str, Any] = {
328
+ "results": [
329
+ {"id": "mem-1", "kind": "preference", "snippet": "답변은 한국어로", "score": 0.91, "source": "workspace"},
330
+ {"id": "mem-2", "kind": None, "snippet": "", "score": 0.0, "source": "workspace"},
331
+ {"id": "mem-3", "kind": "decision", "snippet": "ranking keeps alpha fusion", "score": 0.4, "source": "personal"},
332
+ {"id": "mem-4", "kind": "fact", "snippet": "온보딩은 다섯 걸음", "score": 0.3, "source": "workspace"},
333
+ ]
334
+ }
335
+
336
+ #: A ledger with a pathless row, a non-dict row, and more than the ten-row cut.
337
+ CONTEXT_ARTIFACTS: List[Any] = [
338
+ {"path": "notes/ranking.md", "at": "2026-07-20T09:00:00", "run_id": "run-1"},
339
+ {"path": "notes/onboarding.md", "run_id": "run-2"},
340
+ {"path": "", "at": "2026-07-20T09:00:01"},
341
+ "not-a-dict",
342
+ ] + [{"path": f"out/file-{index}.md", "at": None, "run_id": f"r{index}"} for index in range(10)]
343
+
344
+ #: The Phase-2/3 suites: one spec list per ported entry point.
345
+ SUITES: Dict[str, List[Dict[str, Any]]] = {
346
+ "relationship": [
347
+ {"key": "all"},
348
+ {"key": "by_type_mention", "relationship_type": "mention"},
349
+ {"key": "by_type_contains", "relationship_type": "CONTAINS"},
350
+ {"key": "by_type_unknown", "relationship_type": "relates_to"},
351
+ {"key": "by_node", "node_id": "dec:fusion-alpha"},
352
+ {"key": "by_query_ko", "query": "회의"},
353
+ {"key": "by_query_en", "query": "ranking"},
354
+ {"key": "by_query_meta", "query": "lattice"},
355
+ {"key": "combined", "node_id": "dec:fusion-alpha", "relationship_type": "mention", "query": "retrieval"},
356
+ {"key": "limit_one", "limit": 1},
357
+ {"key": "limit_zero", "limit": 0},
358
+ {"key": "limit_over", "limit": 500},
359
+ {"key": "scoped_alpha", "allowed": [WS_ALPHA]},
360
+ {"key": "scoped_alpha_legacy", "allowed": [WS_ALPHA], "legacy": True},
361
+ {"key": "scoped_beta", "allowed": [WS_BETA]},
362
+ {"key": "scoped_empty", "allowed": []},
363
+ {"key": "no_hit", "query": "zzqq wumpus"},
364
+ ],
365
+ "traverse": [
366
+ # 9 clamps to 4 and -1 clamps to 0; both are on purpose.
367
+ *[{"key": f"hub_d{depth}", "node_id": "dec:fusion-alpha", "depth": depth}
368
+ for depth in (0, 1, 2, 3, 9)],
369
+ {"key": "hub_dneg", "node_id": "dec:fusion-alpha", "depth": -1},
370
+ {"key": "leaf_d2", "node_id": "code:hybrid-search", "depth": 2},
371
+ {"key": "isolated", "node_id": "tie:c", "depth": 2},
372
+ {"key": "limit_two", "node_id": "dec:fusion-alpha", "depth": 3, "limit": 2},
373
+ {"key": "limit_five", "node_id": "dec:fusion-alpha", "depth": 3, "limit": 5},
374
+ {"key": "limit_zero", "node_id": "dec:fusion-alpha", "depth": 2, "limit": 0},
375
+ {"key": "limit_over", "node_id": "dec:fusion-alpha", "depth": 2, "limit": 900},
376
+ {"key": "org_hub", "node_id": "org:lattice", "depth": 2},
377
+ {"key": "tie_pair", "node_id": "tie:a", "depth": 2},
378
+ {"key": "scoped_alpha", "node_id": "dec:fusion-alpha", "depth": 2, "allowed": [WS_ALPHA]},
379
+ {"key": "scoped_alpha_legacy", "node_id": "dec:fusion-alpha", "depth": 2, "allowed": [WS_ALPHA], "legacy": True},
380
+ {"key": "scoped_seed_hidden", "node_id": "dec:fusion-alpha", "allowed": [WS_BETA]},
381
+ {"key": "scoped_empty", "node_id": "dec:fusion-alpha", "allowed": []},
382
+ {"key": "empty_id", "node_id": ""},
383
+ {"key": "missing_seed", "node_id": "nope:missing"},
384
+ ],
385
+ "graph_search": [
386
+ {"key": "en_fact", "query": "hybrid retrieval ranking"},
387
+ {"key": "ko_fact", "query": "회의 결정 사항"},
388
+ {"key": "person", "query": "who owns the onboarding checklist"},
389
+ {"key": "code", "query": "빌드 실패 원인"},
390
+ {"key": "expand0", "query": "hybrid retrieval ranking", "expand_depth": 0},
391
+ {"key": "expand3", "query": "hybrid retrieval ranking", "expand_depth": 3},
392
+ {"key": "expand_clamp", "query": "회의 결정 사항", "expand_depth": 9},
393
+ {"key": "limit_small", "query": "hybrid retrieval ranking", "limit": 3},
394
+ {"key": "limit_over", "query": "회의 결정 사항", "limit": 500},
395
+ {"key": "scoped_alpha", "query": "hybrid retrieval ranking", "allowed": [WS_ALPHA]},
396
+ {"key": "scoped_alpha_legacy", "query": "회의 결정 사항", "allowed": [WS_ALPHA], "legacy": True},
397
+ {"key": "scoped_empty", "query": "hybrid retrieval ranking", "allowed": []},
398
+ {"key": "no_hit", "query": "zzqq wumpus nonsense"},
399
+ {"key": "empty_query", "query": ""},
400
+ ],
401
+ "service_hybrid": [
402
+ {"key": "en_fact", "query": "hybrid retrieval ranking"},
403
+ {"key": "ko_recency", "query": "지난주 회의 기록"},
404
+ {"key": "en_code", "query": "vector_search() returns"},
405
+ {"key": "ko_person", "query": "담당자 누구"},
406
+ {"key": "en_filler", "query": " what is the retrieval specification please "},
407
+ # Explicit weights disable BOTH rewrite and age decay on a query that
408
+ # would otherwise get both — that asymmetry is the contract.
409
+ {"key": "pinned_recency", "query": "지난주 회의 기록", "weights": {"keyword": 0.5, "vector": 0.3, "graph": 0.2}},
410
+ {"key": "pinned_partial", "query": "hybrid retrieval ranking", "weights": {"graph": 1.0}},
411
+ {"key": "pinned_zero", "query": "회의 결정 사항", "weights": {"keyword": 0.0, "vector": 0.0, "graph": 0.0}},
412
+ {"key": "limit_small", "query": "hybrid retrieval ranking", "limit": 3},
413
+ {"key": "limit_over", "query": "회의 결정 사항", "limit": 500},
414
+ {"key": "channel_limits", "query": "hybrid retrieval ranking", "keyword_limit": 5, "vector_limit": 5, "graph_limit": 5},
415
+ {"key": "scoped_alpha", "query": "hybrid retrieval ranking", "allowed": [WS_ALPHA]},
416
+ {"key": "scoped_alpha_legacy", "query": "회의 결정 사항", "allowed": [WS_ALPHA], "legacy": True},
417
+ {"key": "scoped_empty", "query": "hybrid retrieval ranking", "allowed": []},
418
+ {"key": "no_hit", "query": "zzqq wumpus nonsense"},
419
+ {"key": "empty_query", "query": ""},
420
+ ],
421
+ "history": [
422
+ {"key": "all"},
423
+ {"key": "limit_two", "limit": 2},
424
+ {"key": "limit_zero", "limit": 0},
425
+ {"key": "conv_a", "conversation_id": "conv-a"},
426
+ {"key": "conv_missing", "conversation_id": "nope"},
427
+ {"key": "conv_null", "conversation_id": ""},
428
+ {"key": "user_jiwon", "user_email": "jiwon@lattice.ai"},
429
+ {"key": "user_jiwon_strict", "user_email": "jiwon@lattice.ai", "legacy": False},
430
+ {"key": "user_unknown", "user_email": "ghost@lattice.ai"},
431
+ {"key": "ws_alpha", "allowed": [WS_ALPHA]},
432
+ {"key": "ws_alpha_strict", "allowed": [WS_ALPHA], "legacy": False},
433
+ {"key": "ws_both_strict", "allowed": [WS_ALPHA, WS_BETA], "legacy": False},
434
+ {"key": "ws_empty_legacy", "allowed": []},
435
+ {"key": "ws_empty_strict", "allowed": [], "legacy": False},
436
+ {"key": "user_and_ws", "user_email": "jiwon@lattice.ai", "allowed": [WS_ALPHA], "legacy": False},
437
+ {"key": "conv_and_user", "conversation_id": "conv-a", "user_email": "jiwon@lattice.ai", "legacy": False},
438
+ {"key": "ws_blank_only", "allowed": [""], "legacy": False},
439
+ ],
440
+ "conversations": [
441
+ {"key": "all"},
442
+ {"key": "user_jiwon", "user_email": "jiwon@lattice.ai"},
443
+ {"key": "user_jiwon_strict", "user_email": "jiwon@lattice.ai", "legacy": False},
444
+ {"key": "ws_alpha_strict", "allowed": [WS_ALPHA], "legacy": False},
445
+ {"key": "ws_beta_strict", "allowed": [WS_BETA], "legacy": False},
446
+ {"key": "ws_empty_strict", "allowed": [], "legacy": False},
447
+ ],
448
+ "conversation_messages": [
449
+ {"key": "conv_a", "conversation_id": "conv-a"},
450
+ {"key": "legacy_bucket", "conversation_id": "legacy-previous-history"},
451
+ {"key": "missing", "conversation_id": "nope"},
452
+ {"key": "scoped_alpha_strict", "conversation_id": "conv-a", "allowed": [WS_ALPHA], "legacy": False},
453
+ {"key": "legacy_bucket_scoped", "conversation_id": "legacy-previous-history", "allowed": [WS_ALPHA], "legacy": False},
454
+ ],
455
+ "history_search": [
456
+ {"key": "ko_hit", "query": "회의"},
457
+ {"key": "ko_partial", "query": "체크리스트"},
458
+ {"key": "en_hit", "query": "ranking"},
459
+ {"key": "case_insensitive", "query": "RANKING"},
460
+ {"key": "blank", "query": " "},
461
+ {"key": "no_hit", "query": "zzqq"},
462
+ {"key": "limit_one", "query": "ranking", "limit": 1},
463
+ {"key": "scoped_strict", "query": "ranking", "allowed": [WS_BETA], "legacy": False},
464
+ ],
465
+ "context_assemble": [
466
+ {"key": "all_seams", "query": "회의 결정 사항", "memories": CONTEXT_MEMORIES, "artifacts": CONTEXT_ARTIFACTS, "notes": "정원 노트: 랭킹은 alpha 융합을 유지한다.", "recent": {"limit": 4}},
467
+ {"key": "knowledge_only", "query": "hybrid retrieval ranking"},
468
+ {"key": "no_seams", "query": "hybrid retrieval ranking", "knowledge": False},
469
+ {"key": "memories_only", "query": "온보딩", "knowledge": False, "memories": CONTEXT_MEMORIES, "memory_limit": 2},
470
+ {"key": "artifacts_only", "query": "온보딩", "knowledge": False, "artifacts": CONTEXT_ARTIFACTS},
471
+ {"key": "notes_blank", "query": "온보딩", "knowledge": False, "notes": " "},
472
+ {"key": "recent_conversation", "query": "온보딩", "knowledge": False, "recent": {"conversation_id": "conv-a", "limit": 10}},
473
+ {"key": "recent_personal_workspace", "query": "온보딩", "knowledge": False, "recent": {"workspace_id": "personal", "limit": 6}},
474
+ {"key": "recent_user_scoped", "query": "온보딩", "knowledge": False, "recent": {"user_email": "jiwon@lattice.ai", "limit": 5}},
475
+ {"key": "budget_tiny", "query": "회의 결정 사항", "memories": CONTEXT_MEMORIES, "artifacts": CONTEXT_ARTIFACTS, "notes": "정원 노트: 랭킹은 alpha 융합을 유지한다.", "recent": {"limit": 4}, "budget": 20},
476
+ {"key": "budget_one", "query": "회의 결정 사항", "memories": CONTEXT_MEMORIES, "artifacts": CONTEXT_ARTIFACTS, "notes": "노트", "recent": {"limit": 4}, "budget": 1},
477
+ {"key": "budget_zero", "query": "회의 결정 사항", "memories": CONTEXT_MEMORIES, "notes": "노트", "budget": 0},
478
+ {"key": "knowledge_limit_one", "query": "hybrid retrieval ranking", "knowledge_limit": 1},
479
+ ],
480
+ # v11.5.1: the document-generation ports, specs and runners alike.
481
+ **docgen.DOCGEN_SUITES,
482
+ }
483
+
484
+ #: Texts whose tokenizer output, hashes and vectors pin the embedding port.
275
485
  EMBEDDING_TEXTS: List[str] = [
276
486
  "hybrid retrieval ranking",
277
487
  "회의 결정 사항",
@@ -283,8 +493,7 @@ EMBEDDING_TEXTS: List[str] = [
283
493
  "a",
284
494
  ]
285
495
 
286
- #: Values that separate CPython's round-half-even from naive scaling, plus the
287
- #: shapes real fusion arithmetic produces.
496
+ #: Values separating CPython round-half-even from naive scaling, plus real shapes.
288
497
  ROUNDING_VALUES: List[float] = [
289
498
  0.0, 1.0, 5e-07, 1.5e-06, 2.5e-06, 2.6535895, 1 / 3, 1 / 7,
290
499
  0.1234565, 0.1234575, 0.9999999999, 123456.7890625, -0.0000005,
@@ -309,13 +518,16 @@ def pinned_environment() -> Iterator[None]:
309
518
 
310
519
  @contextmanager
311
520
  def frozen_clock() -> Iterator[None]:
312
- """Freeze ``hybrid_search``'s ``datetime.now()`` at :data:`FROZEN_NOW`.
521
+ """Freeze every ported ``datetime.now()`` at :data:`FROZEN_NOW`.
313
522
 
314
- Only the recency-class age decay reads the clock, and it reads it through
315
- the ``datetime`` name that ``hybrid.py`` imported — so rebinding that name
316
- is the whole patch.
523
+ Only the recency decay reads the clock, through the ``datetime`` name its
524
+ module imported, so rebinding that name is the whole patch. Three modules
525
+ reach it: the graph-layer and service-layer ``hybrid_search``, and the
526
+ document-generation search's own 14-day half-life.
317
527
  """
528
+ from lattice_brain.graph import retrieval_docgen as docgen_module
318
529
  from lattice_brain.graph.retrieval import hybrid as hybrid_module
530
+ from latticeai.services import search_service as service_module
319
531
 
320
532
  frozen = datetime.fromisoformat(FROZEN_NOW)
321
533
 
@@ -324,20 +536,23 @@ def frozen_clock() -> Iterator[None]:
324
536
  def now(cls, tz=None): # noqa: ARG003 — mirrors datetime.now's signature
325
537
  return frozen
326
538
 
327
- original = hybrid_module.datetime
328
- hybrid_module.datetime = _FrozenDatetime
539
+ modules = (hybrid_module, service_module, docgen_module)
540
+ originals = [module.datetime for module in modules]
541
+ for module in modules:
542
+ module.datetime = _FrozenDatetime
329
543
  try:
330
544
  yield
331
545
  finally:
332
- hybrid_module.datetime = original
546
+ for module, original in zip(modules, originals, strict=True):
547
+ module.datetime = original
333
548
 
334
549
 
335
550
  @contextmanager
336
551
  def rules_only_extraction() -> Iterator[None]:
337
552
  """Force ``_topic_candidates`` down its rule-based path.
338
553
 
339
- The LLM path needs a bound router, which no fixture run has — but "no router
340
- happens to be bound" is an accident, and this contract cannot rest on one.
554
+ The LLM path needs a bound router no fixture run has, but "no router
555
+ happens to be bound" is an accident this contract cannot rest on.
341
556
  """
342
557
  from lattice_brain.graph._kg_common import extraction
343
558
 
@@ -352,10 +567,27 @@ def rules_only_extraction() -> Iterator[None]:
352
567
  def open_store(db_path: Path):
353
568
  """A ``KnowledgeGraphStore`` over ``db_path`` (blobs beside it)."""
354
569
  from lattice_brain.graph import KnowledgeGraphStore
355
-
356
570
  return KnowledgeGraphStore(Path(db_path), Path(db_path).parent / "blobs")
357
571
 
358
572
 
573
+ def open_conversations(db_path: Path):
574
+ """A ``ConversationStore`` over ``db_path`` (the same file as the graph)."""
575
+ from lattice_brain.conversations import ConversationStore
576
+ return ConversationStore(Path(db_path))
577
+
578
+
579
+ def write_conversations(db_path: Path) -> None:
580
+ """Append :data:`MESSAGES` through the real durable-history write path."""
581
+ conversations = open_conversations(db_path)
582
+ for conv_id, role, content, email, nick, source, stamp, workspace, org, extra in MESSAGES:
583
+ conversations.append({
584
+ "conversation_id": conv_id, "role": role, "content": content,
585
+ "user_email": email, "user_nickname": nick, "source": source,
586
+ "timestamp": stamp, "workspace_id": workspace, "organization_id": org,
587
+ **extra,
588
+ })
589
+
590
+
359
591
  def _backdate(conn: sqlite3.Connection, node_id: str, stamp: str) -> None:
360
592
  conn.execute("UPDATE nodes SET created_at=?, updated_at=? WHERE id=?", (stamp, stamp, node_id))
361
593
  conn.execute(
@@ -388,15 +620,15 @@ def build_store(db_path: Path) -> None:
388
620
  conn, chunk_id=chunk_id, source_node=parent, text=text, metadata=metadata
389
621
  )
390
622
  _backdate(conn, chunk_id, stamp)
391
- for from_node, to_node, edge_type in EDGES:
392
- store._upsert_edge(conn, from_node, to_node, edge_type, 1.0, {})
393
- conn.execute(
394
- "UPDATE edges SET created_at=? WHERE from_node=? AND to_node=?",
395
- ("2026-07-01T00:00:00", from_node, to_node),
396
- )
623
+ for from_node, to_node, edge_type, weight, stamp in EDGES:
624
+ # ``_upsert_edge`` stamps ``created_at`` from the wall clock in BOTH
625
+ # tables, and the read path is the ``kgv2_edges`` view over ``edges_v2``:
626
+ # backdating only the legacy table left the ordering moving with the clock.
627
+ edge_id = store._upsert_edge(conn, from_node, to_node, edge_type, weight, {})
628
+ conn.execute("UPDATE edges SET created_at=? WHERE id=?", (stamp, edge_id))
629
+ conn.execute("UPDATE edges_v2 SET created_at=? WHERE id=?", (stamp, edge_id))
397
630
  # ``indexed_at`` decides the candidate scan order (and, when the cap
398
- # bites, which candidates exist at all), so it is assigned explicitly
399
- # rather than inherited from the clock.
631
+ # bites, which candidates exist), so it is assigned rather than inherited.
400
632
  item_ids = [row["item_id"] for row in conn.execute(
401
633
  "SELECT item_id FROM vector_embeddings ORDER BY item_id ASC"
402
634
  ).fetchall()]
@@ -406,9 +638,10 @@ def build_store(db_path: Path) -> None:
406
638
  "UPDATE vector_embeddings SET indexed_at=? WHERE item_id=?", (stamp, item_id)
407
639
  )
408
640
  store.record_embedder_fingerprint()
641
+ write_conversations(db_path)
409
642
 
410
- # Leave one self-contained file behind: checkpoint the WAL, drop back to a
411
- # rollback journal so no -wal/-shm sidecar has to be committed, and compact.
643
+ # One self-contained file: checkpoint the WAL, drop to a rollback journal
644
+ # so no sidecar is committed, and compact.
412
645
  with sqlite3.connect(str(db_path)) as conn:
413
646
  conn.execute("PRAGMA wal_checkpoint(TRUNCATE)")
414
647
  conn.execute("PRAGMA journal_mode=DELETE")
@@ -429,17 +662,12 @@ def _allowed(spec: Dict[str, Any]):
429
662
 
430
663
  ENGINES: Dict[str, Callable[[Any, Dict[str, Any]], Dict[str, Any]]] = {
431
664
  "hybrid": lambda store, spec: store.hybrid_search(
432
- spec["query"],
433
- top_k=spec.get("top_k", 20),
434
- alpha=spec.get("alpha"),
435
- allowed_workspaces=_allowed(spec),
665
+ spec["query"], top_k=spec.get("top_k", 20), alpha=spec.get("alpha"),
666
+ allowed_workspaces=_allowed(spec), min_vector_score=spec.get("min_vector", 0.0),
436
667
  include_legacy_global=spec.get("legacy", False),
437
- min_vector_score=spec.get("min_vector", 0.0),
438
668
  ),
439
669
  "keyword": lambda store, spec: store.search(
440
- spec["query"],
441
- spec.get("limit", 30),
442
- allowed_workspaces=_allowed(spec),
670
+ spec["query"], spec.get("limit", 30), allowed_workspaces=_allowed(spec),
443
671
  include_legacy_global=spec.get("legacy", False),
444
672
  ),
445
673
  "vector": lambda store, spec: store.vector_search(
@@ -454,6 +682,205 @@ def run_engine(store, engine: str, spec: Dict[str, Any]) -> Dict[str, Any]:
454
682
  return ENGINES[engine](store, spec)
455
683
 
456
684
 
685
+ # ── the suites beyond search (v11.5.0/v11.5.1) ───────────────────────────────
686
+ #
687
+ # The Phase-1 engines share one query shape (a query set × an engine set); the
688
+ # later ports do not, so each gets its own spec list and runner, both carried in
689
+ # the manifest so Rust and Python enumerate exactly the same work.
690
+
691
+
692
+ class Harness:
693
+ """Every Python entry point the v11.5.0 goldens are produced from.
694
+
695
+ ``require_auth=False`` is the loopback-owner configuration the native routes
696
+ reproduce: the history scope is whatever the caller passes.
697
+ """
698
+
699
+ def __init__(self, db_path: Path):
700
+ from latticeai.runtime.history_runtime import build_history_query_runtime
701
+ from latticeai.services.chat_service import ChatService
702
+ from latticeai.services.search_service import SearchService
703
+ self.store = open_store(db_path)
704
+ self.service = SearchService(graph_store=self.store)
705
+ self.conversations = open_conversations(db_path)
706
+ self.history_runtime = build_history_query_runtime(
707
+ conversations=self.conversations,
708
+ workspace_service=None,
709
+ require_auth=False,
710
+ logging=logging,
711
+ )
712
+ self.chat = ChatService(store=None, get_history=self.history_runtime["get_history"])
713
+
714
+
715
+ def _allowed_list(spec: Dict[str, Any]):
716
+ """``allowed`` as the graph layer wants it: ``None`` or a set."""
717
+ allowed = spec.get("allowed")
718
+ return None if allowed is None else set(allowed)
719
+
720
+
721
+ def _history_scope(spec: Dict[str, Any]) -> Dict[str, Any]:
722
+ """The identity/workspace scope every history read takes.
723
+
724
+ ``include_legacy_global`` defaults to ``True`` — ``ConversationStore``'s own
725
+ default, the opposite of the graph layer's and an asymmetry a port gets wrong.
726
+ """
727
+ allowed = spec.get("allowed")
728
+ return {
729
+ "user_email": spec.get("user_email"),
730
+ "allowed_workspaces": None if allowed is None else list(allowed),
731
+ "include_legacy_global": spec.get("legacy", True),
732
+ }
733
+
734
+
735
+ def _run_relationship(h: Harness, spec: Dict[str, Any]) -> Dict[str, Any]:
736
+ return h.store.relationship_search(
737
+ query=spec.get("query", ""), node_id=spec.get("node_id", ""),
738
+ relationship_type=spec.get("relationship_type", ""), limit=spec.get("limit", 30),
739
+ allowed_workspaces=_allowed_list(spec),
740
+ include_legacy_global=spec.get("legacy", False),
741
+ )
742
+
743
+
744
+ def _run_traverse(h: Harness, spec: Dict[str, Any]) -> Dict[str, Any]:
745
+ try:
746
+ return h.store.traverse(
747
+ spec.get("node_id", ""), depth=spec.get("depth", 1),
748
+ limit=spec.get("limit", 100), allowed_workspaces=_allowed_list(spec),
749
+ include_legacy_global=spec.get("legacy", False),
750
+ )
751
+ except ValueError as exc:
752
+ # The two documented refusals (blank id, seed invisible to the caller's
753
+ # scope) are contract, so they are recorded rather than skipped; a payload
754
+ # never carries an "error" key, so the golden stays unambiguous.
755
+ return {"error": str(exc)}
756
+
757
+
758
+ def _run_graph_search(h: Harness, spec: Dict[str, Any]) -> Dict[str, Any]:
759
+ return h.service.graph_search(
760
+ spec["query"], limit=spec.get("limit", 30),
761
+ expand_depth=spec.get("expand_depth", 1), allowed_workspaces=_allowed_list(spec),
762
+ include_legacy_global=spec.get("legacy", False),
763
+ )
764
+
765
+
766
+ def _run_service_hybrid(h: Harness, spec: Dict[str, Any]) -> Dict[str, Any]:
767
+ return h.service.hybrid_search(
768
+ spec["query"], limit=spec.get("limit", 30),
769
+ keyword_limit=spec.get("keyword_limit", 30),
770
+ vector_limit=spec.get("vector_limit", 30),
771
+ graph_limit=spec.get("graph_limit", 30), weights=spec.get("weights"),
772
+ allowed_workspaces=_allowed_list(spec),
773
+ include_legacy_global=spec.get("legacy", False),
774
+ )
775
+
776
+
777
+ def _run_history(h: Harness, spec: Dict[str, Any]) -> List[Dict[str, Any]]:
778
+ return h.conversations.history(
779
+ conversation_id=spec.get("conversation_id"), limit=spec.get("limit"),
780
+ **_history_scope(spec),
781
+ )
782
+
783
+
784
+ def _run_conversations(h: Harness, spec: Dict[str, Any]) -> List[Dict[str, Any]]:
785
+ history = h.history_runtime["get_history"](**_history_scope(spec))
786
+ return h.history_runtime["group_history_conversations"](history)
787
+
788
+
789
+ def _run_conversation_messages(h: Harness, spec: Dict[str, Any]) -> List[Dict[str, Any]]:
790
+ return h.history_runtime["get_conversation_messages"](
791
+ spec["conversation_id"], **_history_scope(spec)
792
+ )
793
+
794
+
795
+ def _run_history_search(h: Harness, spec: Dict[str, Any]) -> List[Dict[str, Any]]:
796
+ return h.chat.search_history(
797
+ spec["query"], scope=_history_scope(spec), limit=spec.get("limit", 30),
798
+ conversation_title=h.history_runtime["conversation_title"],
799
+ )
800
+
801
+
802
+ def _context_seams(h: Harness, spec: Dict[str, Any]) -> Dict[str, Any]:
803
+ """The seam set for one context spec — data seams plus the real engines.
804
+
805
+ ``memories`` / ``artifacts`` / ``notes`` are *data* seams: the payload is the
806
+ spec, so both runtimes feed the assembler the same bytes and what is under
807
+ test is the assembler. ``knowledge`` and ``recent`` are real engines — the
808
+ service-layer hybrid search and the durable history reader.
809
+ """
810
+ from latticeai.api.chat_helpers import build_recent_chat_context
811
+
812
+ # Signatures matter: the assembler inspects them to decide which context
813
+ # fields a seam may be handed, so each one declares exactly what it accepts.
814
+ seams: Dict[str, Any] = {}
815
+ if spec.get("memories") is not None:
816
+ memories = spec["memories"]
817
+ seams["memory_recall"] = (
818
+ lambda query, *, user_email=None, workspace_id=None, limit=5: memories
819
+ )
820
+ if spec.get("artifacts") is not None:
821
+ artifacts = spec["artifacts"]
822
+ seams["recent_artifacts"] = (
823
+ lambda *, user_email=None, conversation_id=None, workspace_id=None: artifacts
824
+ )
825
+ if spec.get("knowledge", True):
826
+ # Loopback trust: no workspace scoping, exactly as on the native route.
827
+ seams["hybrid_search"] = (
828
+ lambda query, *, limit=5, user_email=None, workspace_id=None:
829
+ h.service.hybrid_search(query, limit=limit)
830
+ )
831
+ if spec.get("notes") is not None:
832
+ notes = spec["notes"]
833
+ seams["notes_context"] = lambda query, *, user_email=None, workspace_id=None: notes
834
+ if spec.get("recent") is not None:
835
+ recent = spec["recent"]
836
+ seams["recent_chat"] = (
837
+ lambda *, user_email=None, conversation_id=None, workspace_id=None:
838
+ build_recent_chat_context(
839
+ get_history=h.history_runtime["get_history"],
840
+ limit=recent.get("limit", 10),
841
+ include_image_missing_replies=recent.get("images", True),
842
+ user_email=recent.get("user_email"),
843
+ conversation_id=recent.get("conversation_id"),
844
+ workspace_id=recent.get("workspace_id"),
845
+ )
846
+ )
847
+ return seams
848
+
849
+
850
+ def _run_context_assemble(h: Harness, spec: Dict[str, Any]) -> Dict[str, Any]:
851
+ from lattice_brain.context import ContextAssembler
852
+
853
+ assembled = ContextAssembler(**_context_seams(h, spec)).assemble(
854
+ spec["query"], user_email=spec.get("user_email"),
855
+ workspace_id=spec.get("workspace_id"),
856
+ conversation_id=spec.get("conversation_id"), budget=spec.get("budget", 2000),
857
+ memory_limit=spec.get("memory_limit", 5),
858
+ knowledge_limit=spec.get("knowledge_limit", 5),
859
+ )
860
+ return {"text": assembled.text, "approx_tokens": assembled.approx_tokens,
861
+ "trace": assembled.trace()}
862
+
863
+
864
+ SUITE_RUNNERS: Dict[str, Callable[[Harness, Dict[str, Any]], Any]] = {
865
+ "relationship": _run_relationship,
866
+ "traverse": _run_traverse,
867
+ "graph_search": _run_graph_search,
868
+ "service_hybrid": _run_service_hybrid,
869
+ "history": _run_history,
870
+ "conversations": _run_conversations,
871
+ "conversation_messages": _run_conversation_messages,
872
+ "history_search": _run_history_search,
873
+ "context_assemble": _run_context_assemble,
874
+ **docgen.DOCGEN_RUNNERS,
875
+ }
876
+
877
+
878
+ def run_suite(harness: Harness, suite: str, spec: Dict[str, Any]) -> Any:
879
+ """Run one suite spec under the frozen clock and the rule-based extractor."""
880
+ with frozen_clock(), rules_only_extraction():
881
+ return SUITE_RUNNERS[suite](harness, spec)
882
+
883
+
457
884
  def golden_path(engine: str, key: str) -> Path:
458
885
  return GOLDEN_DIR / f"{engine}__{key}.json"
459
886
 
@@ -464,10 +891,8 @@ def golden_payload(engine: str, spec: Dict[str, Any], result: Dict[str, Any]) ->
464
891
  "key": spec["key"],
465
892
  "query": spec["query"],
466
893
  "params": {
467
- "top_k": spec.get("top_k", 20),
468
- "alpha": spec.get("alpha"),
469
- "limit": spec.get("limit", 30),
470
- "min_score": spec.get("min_score", 0.0),
894
+ "top_k": spec.get("top_k", 20), "alpha": spec.get("alpha"),
895
+ "limit": spec.get("limit", 30), "min_score": spec.get("min_score", 0.0),
471
896
  "min_vector_score": spec.get("min_vector", 0.0),
472
897
  "allowed_workspaces": spec.get("allowed"),
473
898
  "include_legacy_global": spec.get("legacy", False),
@@ -476,6 +901,15 @@ def golden_payload(engine: str, spec: Dict[str, Any], result: Dict[str, Any]) ->
476
901
  }
477
902
 
478
903
 
904
+ def suite_payload(suite: str, spec: Dict[str, Any], result: Any) -> Dict[str, Any]:
905
+ """One suite golden: the spec that produced it, verbatim, and the answer.
906
+
907
+ The spec rides along rather than being flattened into a fixed ``params``
908
+ block — these entry points share no parameter shape.
909
+ """
910
+ return {"suite": suite, "key": spec["key"], "spec": spec, "result": result}
911
+
912
+
479
913
  def _dump(path: Path, payload: Any) -> None:
480
914
  path.write_text(
481
915
  json.dumps(payload, ensure_ascii=False, sort_keys=True, indent=2) + "\n",
@@ -511,12 +945,11 @@ def embeddings_golden() -> Dict[str, Any]:
511
945
 
512
946
  def rounding_golden() -> List[Dict[str, float]]:
513
947
  """``round(x, 6)`` for values where the tie rule is observable."""
514
- return [{"input": value, "expected": round(value, 6)} for value in ROUNDING_VALUES]
948
+ return [{"input": v, "expected": round(v, 6)} for v in ROUNDING_VALUES]
515
949
 
516
950
 
517
951
  def manifest() -> Dict[str, Any]:
518
952
  from lattice_brain.embeddings import LocalEmbeddingModel
519
-
520
953
  model = LocalEmbeddingModel()
521
954
  return {
522
955
  "frozen_now": FROZEN_NOW,
@@ -525,6 +958,7 @@ def manifest() -> Dict[str, Any]:
525
958
  "embedding_dim": model.dim,
526
959
  "engines": sorted(ENGINES),
527
960
  "queries": QUERIES,
961
+ "suites": {suite: SUITES[suite] for suite in sorted(SUITES)},
528
962
  "pinned_env": PINNED_ENV,
529
963
  }
530
964
 
@@ -543,12 +977,16 @@ def main() -> int:
543
977
  result = run_engine(store, engine, spec)
544
978
  _dump(golden_path(engine, spec["key"]), golden_payload(engine, spec, result))
545
979
  written += 1
980
+ harness = Harness(STORE_PATH)
981
+ for suite in sorted(SUITES):
982
+ for spec in SUITES[suite]:
983
+ result = run_suite(harness, suite, spec)
984
+ _dump(golden_path(suite, spec["key"]), suite_payload(suite, spec, result))
985
+ written += 1
546
986
  _dump(GOLDEN_DIR / "embeddings_golden.json", embeddings_golden())
547
987
  _dump(GOLDEN_DIR / "rounding_golden.json", rounding_golden())
548
988
  _dump(GOLDEN_DIR / "manifest.json", manifest())
549
- # ``KnowledgeGraphStore.__init__`` creates its blob directory eagerly; the
550
- # fixture has no blobs, and an empty directory beside a committed artefact is
551
- # just a thing for the next reader to wonder about.
989
+ # The store creates its blob directory eagerly and the fixture has no blobs.
552
990
  blob_dir = STORE_PATH.parent / "blobs"
553
991
  if blob_dir.is_dir() and not any(blob_dir.iterdir()):
554
992
  blob_dir.rmdir()