@hviana/sema 0.1.0 → 0.1.2

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 (131) hide show
  1. package/dist/example/demo.d.ts +1 -0
  2. package/dist/example/demo.js +39 -0
  3. package/dist/example/train_base.d.ts +87 -0
  4. package/dist/example/train_base.js +2216 -0
  5. package/dist/src/alphabet.d.ts +7 -0
  6. package/dist/src/alphabet.js +33 -0
  7. package/dist/src/alu/src/alu.d.ts +185 -0
  8. package/dist/src/alu/src/alu.js +440 -0
  9. package/dist/src/alu/src/expr.d.ts +61 -0
  10. package/dist/src/alu/src/expr.js +318 -0
  11. package/dist/src/alu/src/index.d.ts +11 -0
  12. package/dist/src/alu/src/index.js +19 -0
  13. package/dist/src/alu/src/kernel-arith.d.ts +16 -0
  14. package/dist/src/alu/src/kernel-arith.js +264 -0
  15. package/dist/src/alu/src/kernel-bits.d.ts +19 -0
  16. package/dist/src/alu/src/kernel-bits.js +152 -0
  17. package/dist/src/alu/src/kernel-logic.d.ts +4 -0
  18. package/dist/src/alu/src/kernel-logic.js +60 -0
  19. package/dist/src/alu/src/kernel-nd.d.ts +3 -0
  20. package/dist/src/alu/src/kernel-nd.js +208 -0
  21. package/dist/src/alu/src/kernel-numeric.d.ts +54 -0
  22. package/dist/src/alu/src/kernel-numeric.js +366 -0
  23. package/dist/src/alu/src/operation.d.ts +168 -0
  24. package/dist/src/alu/src/operation.js +189 -0
  25. package/dist/src/alu/src/parser.d.ts +212 -0
  26. package/dist/src/alu/src/parser.js +469 -0
  27. package/dist/src/alu/src/resonance.d.ts +55 -0
  28. package/dist/src/alu/src/resonance.js +126 -0
  29. package/dist/src/alu/src/text.d.ts +31 -0
  30. package/dist/src/alu/src/text.js +73 -0
  31. package/dist/src/alu/src/value.d.ts +109 -0
  32. package/dist/src/alu/src/value.js +300 -0
  33. package/dist/src/alu/test/alu.test.d.ts +1 -0
  34. package/dist/src/alu/test/alu.test.js +764 -0
  35. package/dist/src/bytes.d.ts +14 -0
  36. package/dist/src/bytes.js +59 -0
  37. package/dist/src/config.d.ts +114 -0
  38. package/dist/src/config.js +96 -0
  39. package/dist/src/derive/src/deduction.d.ts +125 -0
  40. package/dist/src/derive/src/deduction.js +155 -0
  41. package/dist/src/derive/src/index.d.ts +7 -0
  42. package/dist/src/derive/src/index.js +11 -0
  43. package/dist/src/derive/src/priority-queue.d.ts +20 -0
  44. package/dist/src/derive/src/priority-queue.js +73 -0
  45. package/dist/src/derive/src/rewrite.d.ts +56 -0
  46. package/dist/src/derive/src/rewrite.js +100 -0
  47. package/dist/src/derive/src/trie.d.ts +90 -0
  48. package/dist/src/derive/src/trie.js +217 -0
  49. package/dist/src/derive/test/derive.test.d.ts +1 -0
  50. package/dist/src/derive/test/derive.test.js +122 -0
  51. package/dist/src/extension.d.ts +37 -0
  52. package/dist/src/extension.js +7 -0
  53. package/dist/src/geometry.d.ts +137 -0
  54. package/dist/src/geometry.js +430 -0
  55. package/dist/src/index.d.ts +15 -0
  56. package/dist/src/index.js +21 -0
  57. package/dist/src/ingest-cache.d.ts +41 -0
  58. package/dist/src/ingest-cache.js +161 -0
  59. package/dist/src/mind/articulation.d.ts +6 -0
  60. package/dist/src/mind/articulation.js +99 -0
  61. package/dist/src/mind/attention.d.ts +72 -0
  62. package/dist/src/mind/attention.js +894 -0
  63. package/dist/src/mind/canonical.d.ts +29 -0
  64. package/dist/src/mind/canonical.js +88 -0
  65. package/dist/src/mind/graph-search.d.ts +270 -0
  66. package/dist/src/mind/graph-search.js +847 -0
  67. package/dist/src/mind/index.d.ts +5 -0
  68. package/dist/src/mind/index.js +5 -0
  69. package/dist/src/mind/junction.d.ts +95 -0
  70. package/dist/src/mind/junction.js +262 -0
  71. package/dist/src/mind/learning.d.ts +47 -0
  72. package/dist/src/mind/learning.js +201 -0
  73. package/dist/src/mind/match.d.ts +111 -0
  74. package/dist/src/mind/match.js +422 -0
  75. package/dist/src/mind/mechanisms/alu.d.ts +4 -0
  76. package/dist/src/mind/mechanisms/alu.js +29 -0
  77. package/dist/src/mind/mechanisms/cast.d.ts +35 -0
  78. package/dist/src/mind/mechanisms/cast.js +447 -0
  79. package/dist/src/mind/mechanisms/confluence.d.ts +24 -0
  80. package/dist/src/mind/mechanisms/confluence.js +213 -0
  81. package/dist/src/mind/mechanisms/cover.d.ts +6 -0
  82. package/dist/src/mind/mechanisms/cover.js +179 -0
  83. package/dist/src/mind/mechanisms/extraction.d.ts +67 -0
  84. package/dist/src/mind/mechanisms/extraction.js +342 -0
  85. package/dist/src/mind/mechanisms/recall.d.ts +13 -0
  86. package/dist/src/mind/mechanisms/recall.js +151 -0
  87. package/dist/src/mind/mind.d.ts +147 -0
  88. package/dist/src/mind/mind.js +300 -0
  89. package/dist/src/mind/pipeline-mechanism.d.ts +142 -0
  90. package/dist/src/mind/pipeline-mechanism.js +213 -0
  91. package/dist/src/mind/pipeline.d.ts +20 -0
  92. package/dist/src/mind/pipeline.js +185 -0
  93. package/dist/src/mind/primitives.d.ts +43 -0
  94. package/dist/src/mind/primitives.js +162 -0
  95. package/dist/src/mind/rationale.d.ts +134 -0
  96. package/dist/src/mind/rationale.js +162 -0
  97. package/dist/src/mind/reasoning.d.ts +15 -0
  98. package/dist/src/mind/reasoning.js +162 -0
  99. package/dist/src/mind/recognition.d.ts +20 -0
  100. package/dist/src/mind/recognition.js +223 -0
  101. package/dist/src/mind/resonance.d.ts +23 -0
  102. package/dist/src/mind/resonance.js +0 -0
  103. package/dist/src/mind/trace.d.ts +15 -0
  104. package/dist/src/mind/trace.js +73 -0
  105. package/dist/src/mind/traverse.d.ts +100 -0
  106. package/dist/src/mind/traverse.js +447 -0
  107. package/dist/src/mind/types.d.ts +174 -0
  108. package/dist/src/mind/types.js +84 -0
  109. package/dist/src/rabitq-hnsw/src/database.d.ts +200 -0
  110. package/dist/src/rabitq-hnsw/src/database.js +388 -0
  111. package/dist/src/rabitq-hnsw/src/heap.d.ts +22 -0
  112. package/dist/src/rabitq-hnsw/src/heap.js +89 -0
  113. package/dist/src/rabitq-hnsw/src/hnsw.d.ts +125 -0
  114. package/dist/src/rabitq-hnsw/src/hnsw.js +474 -0
  115. package/dist/src/rabitq-hnsw/src/index.d.ts +10 -0
  116. package/dist/src/rabitq-hnsw/src/index.js +6 -0
  117. package/dist/src/rabitq-hnsw/src/prng.d.ts +19 -0
  118. package/dist/src/rabitq-hnsw/src/prng.js +36 -0
  119. package/dist/src/rabitq-hnsw/src/rabitq.d.ts +95 -0
  120. package/dist/src/rabitq-hnsw/src/rabitq.js +283 -0
  121. package/dist/src/rabitq-hnsw/src/store.d.ts +162 -0
  122. package/dist/src/rabitq-hnsw/src/store.js +825 -0
  123. package/dist/src/rabitq-hnsw/test/hnsw.test.d.ts +1 -0
  124. package/dist/src/rabitq-hnsw/test/hnsw.test.js +948 -0
  125. package/dist/src/store-sqlite.d.ts +149 -0
  126. package/dist/src/store-sqlite.js +702 -0
  127. package/dist/src/store.d.ts +638 -0
  128. package/dist/src/store.js +1618 -0
  129. package/dist/src/vec.d.ts +31 -0
  130. package/dist/src/vec.js +109 -0
  131. package/package.json +1 -1
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,39 @@
1
+ // demo.ts — one short session that drives the WHOLE pipeline from one memory.
2
+ //
3
+ // We give Sema a handful of plain notes, then ask things that no single note
4
+ // answers. The headline query is the third one: from three worked examples Sema
5
+ // learns the shape of "X was painted by Y", lifts the painter out of a sentence
6
+ // it has NEVER seen, and then — in the same pass — reasons forward to a separate
7
+ // fact about that painter. The reply contains no word from the question. That is
8
+ // retrieval, generalization, and reasoning composing as a single act, with every
9
+ // step traceable back to the notes behind it.
10
+ import { Mind } from "../src/index.js";
11
+ import { SQliteStore } from "../src/store-sqlite.js";
12
+ async function main() {
13
+ const mind = new Mind({ store: new SQliteStore({ path: ":memory:" }) });
14
+ const ask = async (q) => (await mind.respondText(q)).trim();
15
+ // ── Jot down what we know. Each line is just (context → what follows). ──
16
+ await mind.ingest([
17
+ // One relation, shown three times — a pattern taught purely by example:
18
+ ["The Mona Lisa was painted by Leonardo da Vinci.", "Leonardo da Vinci"],
19
+ ["The Starry Night was painted by Vincent van Gogh.", "Vincent van Gogh"],
20
+ [
21
+ "The Night Watch was painted by Rembrandt van Rijn.",
22
+ "Rembrandt van Rijn",
23
+ ],
24
+ // One stray fact, keyed on a name none of the examples mention:
25
+ ["Pablo Picasso", "Pablo Picasso co-founded the Cubist movement"],
26
+ ]);
27
+ // 1) GENERALIZE — apply the learned pattern to an unseen sentence and read out
28
+ // the painter. "Pablo Picasso" was never given as an answer; Sema locates it
29
+ // by analogy to the three examples.
30
+ console.log(await ask("The Weeping Woman was painted by Pablo Picasso."));
31
+ // → "Pablo Picasso co-founded the Cubist movement"
32
+ // …and, having found the painter, it KEEPS GOING: the name bridges into the
33
+ // one fact it holds about him. The answer appears in no word of the question.
34
+ // 2) COMPUTE — exact arithmetic, grounded right where the notes go silent.
35
+ console.log(await ask("a museum charges 12*4 for a family ticket"));
36
+ // → "48"
37
+ await mind.store.close();
38
+ }
39
+ main();
@@ -0,0 +1,87 @@
1
+ export interface Episode {
2
+ context: string;
3
+ continuation: string;
4
+ }
5
+ export type TrainingItem = string | Episode;
6
+ /** Dedup + trim a concept's items: drop empty/degenerate pairs and exact
7
+ * repeats so a concept never deposits the same form twice. */
8
+ export declare function refineItems(items: TrainingItem[]): TrainingItem[];
9
+ /** One normalized SmolSent row. */
10
+ export interface SmolSentRow {
11
+ src: string;
12
+ trg: string;
13
+ sl: string;
14
+ tl: string;
15
+ }
16
+ /** Normalize a raw datasets-server row into a SmolSentRow, or null when it lacks
17
+ * both sides or a side is implausibly large (a dump, not a sentence). */
18
+ export declare function toSmolSentRow(row: unknown): SmolSentRow | null;
19
+ /** Translate ONE SmolSent pair into SEMA facts: the two sentences are one
20
+ * meaning in two languages, so bind them BOTH ways. refineItems drops the
21
+ * degenerate case where src === trg. */
22
+ export declare function smolSentRowToItems(row: SmolSentRow): TrainingItem[];
23
+ /** One normalized Aya row. */
24
+ export interface AyaRow {
25
+ inputs: string;
26
+ targets: string;
27
+ language: string;
28
+ }
29
+ /** Normalize a raw datasets-server row object into an AyaRow, or null when it
30
+ * lacks a usable prompt/answer or a field is implausibly large (a dump, not a
31
+ * cognitive example). Trims surrounding whitespace; keeps inner text verbatim
32
+ * (human prose, possibly multi-paragraph). */
33
+ export declare function toAyaRow(row: unknown): AyaRow | null;
34
+ /** Translate ONE Aya row into SEMA training items. A row is a single human
35
+ * (question → answer) exchange — exactly one FACT, the (inputs → targets) edge.
36
+ * No standalone-answer experience and no one-exchange "cumulative" walk: a lone
37
+ * Q→A is not multi-turn, and both would only replicate the same edge. */
38
+ export declare function ayaRowToItems(row: AyaRow): TrainingItem[];
39
+ /** A single oasst2 message node (the fields we use; the tree nests via replies). */
40
+ interface OasstNode {
41
+ role?: string;
42
+ text?: string;
43
+ rank?: number | null;
44
+ deleted?: boolean;
45
+ replies?: OasstNode[];
46
+ }
47
+ /** One conversational turn extracted from a tree. */
48
+ export interface OasstTurn {
49
+ role: string;
50
+ text: string;
51
+ }
52
+ /** Collapse a conversation tree to ONE linear path: at each node, descend into
53
+ * its best-ranked, non-deleted reply (rank 0 preferred; unranked sorts last).
54
+ * Returns the ordered turns (already strictly alternating in this corpus). */
55
+ export declare function bestOasstPath(root: OasstNode): OasstTurn[];
56
+ /** Translate ONE multi-turn oasst2 conversation into SEMA training items.
57
+ *
58
+ * This is the ONE stage where cumulative continuous context is truly necessary:
59
+ * the data is a real multi-turn dialogue, and what must be learned is how each
60
+ * turn follows from the WHOLE conversation so far — not from the previous turn
61
+ * alone. The conversation is emitted ONLY as the accumulated walk; standalone
62
+ * turn experiences and local adjacent-pair facts are NOT emitted (they are
63
+ * subsumed by it and would merely replicate the content).
64
+ *
65
+ * The walk is byte-for-byte the pattern proven in test/13-conversation.test.mjs
66
+ * ("teachConversation"): each turn is the continuation of all prior turns joined
67
+ * by "\n", with BARE turn text — NO "User:/Assistant:" labels. Roles already
68
+ * alternate by position in an oasst2 best-path (the root is a prompter), so a
69
+ * label adds nothing the position does not, while a clean continuation matches
70
+ * the test's recall (predictNext queries bare prior turns) and lets a turn share
71
+ * its gist with the same text elsewhere (e.g. an Aya question stored bare).
72
+ *
73
+ * Returns [] for a conversation below the multi-turn threshold, so callers can
74
+ * simply skip empties. */
75
+ export declare function oasstConversationToItems(turns: OasstTurn[]): TrainingItem[];
76
+ /** One normalized General-Knowledge row. */
77
+ export interface GenKnowRow {
78
+ question: string;
79
+ answer: string;
80
+ }
81
+ /** Normalize a raw datasets-server row into a GenKnowRow, or null when it lacks
82
+ * a usable question/answer or a side is implausibly large (corruption). */
83
+ export declare function toGenKnowRow(row: unknown): GenKnowRow | null;
84
+ /** Translate ONE General-Knowledge row into SEMA items: exactly one
85
+ * (question → answer) FACT. refineItems drops a degenerate question === answer. */
86
+ export declare function genKnowRowToItems(row: GenKnowRow): TrainingItem[];
87
+ export {};