@factbag/jev 0.0.0-bootstrap.0 → 0.1.0-alpha.7
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.
- package/CHANGELOG.md +60 -0
- package/LICENSE +202 -0
- package/README.md +315 -5
- package/dist/public/index.d.ts +102 -0
- package/dist/public/index.js +741 -0
- package/docs/README.md +317 -0
- package/package.json +94 -6
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
# @factbag/jev
|
|
2
|
+
|
|
3
|
+
## 0.1.0-alpha.7
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- factbag@0.1.0-alpha.7
|
|
8
|
+
|
|
9
|
+
## 0.0.0-alpha.6
|
|
10
|
+
|
|
11
|
+
### Minor Changes
|
|
12
|
+
|
|
13
|
+
- 6433c6b: Classify open-ended `String`, `Number`, and `Date` fields, and entity fields with no registered entities, over the values each passage offers. Pass `createChunkSymbolExtractor` to `classifier(...)` from `@factbag/jev` or `@factbag/clef` to build an extractor per chunk whose `query` answers candidate values for the open fields of the predicates it classifies. Both packages export the `ChunkSymbolExtractor`, `CreateChunkSymbolExtractor`, and `SymbolAnswer` types.
|
|
14
|
+
|
|
15
|
+
Extracted values are candidates only. An extracted entity is registered in `run.kb.entities` when asserted or denied evidence mentions it; entities the model does not admit evidence for are discarded.
|
|
16
|
+
|
|
17
|
+
### Patch Changes
|
|
18
|
+
|
|
19
|
+
- Updated dependencies [7225a51]
|
|
20
|
+
- Updated dependencies [7f26b45]
|
|
21
|
+
- Updated dependencies [b7c85ff]
|
|
22
|
+
- Updated dependencies [ed6ec84]
|
|
23
|
+
- Updated dependencies [5114b2f]
|
|
24
|
+
- Updated dependencies [15391f2]
|
|
25
|
+
- Updated dependencies [eab3679]
|
|
26
|
+
- Updated dependencies [ecbd8d9]
|
|
27
|
+
- Updated dependencies [e4b343e]
|
|
28
|
+
- factbag@0.0.0-alpha.6
|
|
29
|
+
|
|
30
|
+
## 0.0.0-alpha.5
|
|
31
|
+
|
|
32
|
+
### Minor Changes
|
|
33
|
+
|
|
34
|
+
- 19ac508: **Breaking:** Jev moves from `factbag/jev` to its own package, `@factbag/jev`. Install it alongside `factbag` and `@typesafe-ai/sdk`, which is now a required peer dependency at `^0.7.0`, and import `classifier`, `resolver`, `createConfig`, `Config`, and the `DEFAULT_*` constants from `@factbag/jev`. `factbag` no longer has a Jev entry point or an SDK peer dependency. `@factbag/jev` and `@factbag/clef` are released together with `factbag` and require the same `factbag` version.
|
|
35
|
+
|
|
36
|
+
**Breaking:** `@factbag/jev` has a single entry point. `factbag/jev/classifier`, `factbag/jev/resolve`, `factbag/jev/config`, and `factbag/jev/errors` have no replacement subpaths.
|
|
37
|
+
|
|
38
|
+
Add `batchSize` to Jev's `Config`: how many questions each request holds. It defaults to 64 and has no upper limit. An invalid `batchSize` throws when the config is created or a run is built.
|
|
39
|
+
|
|
40
|
+
Jev's `createConfig` now returns `Normalized & Config`, so `client` is no longer guaranteed on the result.
|
|
41
|
+
|
|
42
|
+
### Patch Changes
|
|
43
|
+
|
|
44
|
+
- Updated dependencies [19ac508]
|
|
45
|
+
- Updated dependencies [19ac508]
|
|
46
|
+
- Updated dependencies [dd3730b]
|
|
47
|
+
- factbag@0.0.0-alpha.5
|
|
48
|
+
|
|
49
|
+
## 0.1.0-next.0
|
|
50
|
+
|
|
51
|
+
### Minor Changes
|
|
52
|
+
|
|
53
|
+
- Publish the initial experimental Factbag packages with native Node ESM artifacts and declarations.
|
|
54
|
+
|
|
55
|
+
### Patch Changes
|
|
56
|
+
|
|
57
|
+
- Updated dependencies
|
|
58
|
+
- @factbag/core@0.1.0-next.0
|
|
59
|
+
- @factbag/corpus@0.1.0-next.0
|
|
60
|
+
- @factbag/guards@0.1.0-next.0
|
package/LICENSE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright 2026 Daniel du Plessis
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
package/README.md
CHANGED
|
@@ -1,11 +1,321 @@
|
|
|
1
1
|
# @factbag/jev
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
`classifier({ corpus, input: kb, config })` returns a lazy iterator of executable
|
|
4
|
+
classification jobs, one per chunk. Constructing and consuming the iterator makes **no remote calls**. The caller
|
|
5
|
+
decides when to execute each job and how much work to run concurrently.
|
|
5
6
|
|
|
6
|
-
The
|
|
7
|
-
|
|
7
|
+
The package has one entry point, `@factbag/jev`, which exports:
|
|
8
|
+
|
|
9
|
+
- `classifier({ corpus, input: kb, config? })`
|
|
10
|
+
- `resolver(corpus, kb, config?)`
|
|
11
|
+
- `createConfig`, `Config`, and the `DEFAULT_*` constants
|
|
12
|
+
|
|
13
|
+
## Install
|
|
8
14
|
|
|
9
15
|
```sh
|
|
10
|
-
npm install factbag@alpha @factbag/jev@alpha
|
|
16
|
+
npm install factbag@alpha @factbag/jev@alpha @typesafe-ai/sdk@^0.7.0
|
|
11
17
|
```
|
|
18
|
+
|
|
19
|
+
`@factbag/jev` is released with `factbag` and needs the same `factbag` version.
|
|
20
|
+
Set `TYPESAFE_API_KEY`, or pass your own `TypeSafeClient` as `config.client`.
|
|
21
|
+
|
|
22
|
+
## Usage
|
|
23
|
+
|
|
24
|
+
```ts
|
|
25
|
+
import { enumeration, predicate } from "factbag/dsl";
|
|
26
|
+
import { KnowledgeBase } from "factbag/kb";
|
|
27
|
+
import { Corpus } from "factbag/corpus";
|
|
28
|
+
import { guard } from "factbag/kb";
|
|
29
|
+
import { classifier } from "@factbag/jev";
|
|
30
|
+
|
|
31
|
+
class Company {
|
|
32
|
+
constructor(
|
|
33
|
+
readonly id: string,
|
|
34
|
+
readonly tradingName: string,
|
|
35
|
+
) {}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const status = predicate(
|
|
39
|
+
"company_status",
|
|
40
|
+
{
|
|
41
|
+
company: Company,
|
|
42
|
+
status: enumeration("active", "dissolved"),
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
description: "The document explicitly establishes this company's legal status.",
|
|
46
|
+
},
|
|
47
|
+
);
|
|
48
|
+
|
|
49
|
+
const kb = new KnowledgeBase();
|
|
50
|
+
kb.entities.add(new Company("company-42", "Harbor"));
|
|
51
|
+
const corpus = new Corpus();
|
|
52
|
+
corpus.add({ documentId: "registry", text: "Harbor is an active company." });
|
|
53
|
+
|
|
54
|
+
// The default TypeSafeClient reads TYPESAFE_API_KEY on the first execute().
|
|
55
|
+
const run = classifier({
|
|
56
|
+
corpus,
|
|
57
|
+
input: guard(kb).permit("assert", status).permit("deny", status),
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
for (const job of run) {
|
|
61
|
+
await job.execute();
|
|
62
|
+
// The consumer may await persistence or a rate limiter here.
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
const enriched = run.kb;
|
|
66
|
+
// kb is unchanged. enriched contains the original knowledge plus new evidence.
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
## Boundary and registration
|
|
70
|
+
|
|
71
|
+
Classification and resolution share one optional, flat `Config`. Create it once
|
|
72
|
+
with `createConfig` to share one lazy client across runs:
|
|
73
|
+
|
|
74
|
+
```ts
|
|
75
|
+
const config = createConfig({ client, minimumProbability: 0.6 });
|
|
76
|
+
const classified = classifier({ corpus, input: kb, config });
|
|
77
|
+
const resolved = resolver(corpus, classified.kb, config);
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
Admission defaults to `{ minimumProbability: 0.4, ambiguityMargin: 0 }`:
|
|
81
|
+
the strongest ASSERT/DENY outcome must reach 0.4 and outrank IRRELEVANT. An exact
|
|
82
|
+
ASSERT/DENY tie admits both. These are convenience defaults, not calibrated probabilities.
|
|
83
|
+
A plainly worded record often scores in the 0.45-0.65 band, so 0.5 loses evidence a reader
|
|
84
|
+
would call clear; a lower bar writes more, and contradictions surface rather than gaps.
|
|
85
|
+
|
|
86
|
+
```ts
|
|
87
|
+
classifier({ corpus, input: kb });
|
|
88
|
+
classifier({ corpus, input: kb, config: { client } });
|
|
89
|
+
classifier({ corpus, input: kb, config: { minimumProbability: 0.8, ambiguityMargin: 0.05 } });
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
- A **guarded KB** retains its exact permit/block policy. `guard(kb)` is default-deny.
|
|
93
|
+
- A **bare KB** permits assert/deny for all predicates referenced in its
|
|
94
|
+
evidence and rules, including rule bodies. There is no global predicate registry.
|
|
95
|
+
- Query permissions do not make a predicate classifiable.
|
|
96
|
+
- Every exposed predicate is validated synchronously during `classifier(...)`.
|
|
97
|
+
Unsupported predicates fail even if the corpus is empty; blocked predicates are
|
|
98
|
+
not registered.
|
|
99
|
+
|
|
100
|
+
`UnsupportedPredicateError` (from `factbag/exceptions`) identifies the predicate and, where applicable, the
|
|
101
|
+
field that cannot be classified. A nonempty metadata description is required.
|
|
102
|
+
|
|
103
|
+
Supported field domains:
|
|
104
|
+
|
|
105
|
+
| Schema field | Candidate values |
|
|
106
|
+
| -------------------------- | ---------------------------------------------------- |
|
|
107
|
+
| `Boolean` | `false`, `true` |
|
|
108
|
+
| `enumeration(...)` | Explicit string, number, or Date members |
|
|
109
|
+
| Entity constructor | Registered instances, plus each chunk's extracted |
|
|
110
|
+
| `String`, `Number`, `Date` | Each chunk's extracted values; unsupported otherwise |
|
|
111
|
+
|
|
112
|
+
Without `createChunkSymbolExtractor`, an entity domain must contain registered instances. Existing scalar facts do not
|
|
113
|
+
turn an open-ended schema into an enum. To model a fixed value, declare it explicitly
|
|
114
|
+
with `enumeration(value)` rather than asking the classifier to discover it.
|
|
115
|
+
|
|
116
|
+
Number and Date enumerations, such as `enumeration(10, 20)` or
|
|
117
|
+
`enumeration(new Date("2026-10-25T00:00:00Z"))`, are classified like string
|
|
118
|
+
enumerations. Dates are sent to the model as ISO strings and retained as `Date`
|
|
119
|
+
values in evidence. The same date in two fields is a valid candidate; only
|
|
120
|
+
repeated entities are excluded.
|
|
121
|
+
|
|
122
|
+
Entity candidates include their enumerable properties, including `id`, plus `type`
|
|
123
|
+
set to the constructor name. They are JSON-encoded when each request is built:
|
|
124
|
+
nested properties are included, dates become ISO strings, and methods are not sent.
|
|
125
|
+
For example, the company above is sent as
|
|
126
|
+
`{ type: "Company", id: "company-42", tradingName: "Harbor" }`.
|
|
127
|
+
Evidence continues to reference the original registered entity. Related KB facts
|
|
128
|
+
are not automatically included in the entity payload.
|
|
129
|
+
|
|
130
|
+
Fields fan out as a Cartesian product. A predicate with no fields has one candidate
|
|
131
|
+
proposition. Every candidate gets an independent `Choice(ASSERT, DENY, IRRELEVANT)`
|
|
132
|
+
question. Assert and deny permissions for the same predicate share one question.
|
|
133
|
+
No enum exclusivity or Boolean equivalence is assumed; those belong to the ruleset.
|
|
134
|
+
|
|
135
|
+
### Passage symbols
|
|
136
|
+
|
|
137
|
+
Pass `createChunkSymbolExtractor` to fill open-ended and entity fields from the text
|
|
138
|
+
being classified. The classifier builds one extractor per job over that job's chunk,
|
|
139
|
+
and asks it for the open fields of the predicates it classifies:
|
|
140
|
+
|
|
141
|
+
```ts
|
|
142
|
+
const run = classifier({
|
|
143
|
+
corpus,
|
|
144
|
+
input: access,
|
|
145
|
+
createChunkSymbolExtractor: (chunks) => {
|
|
146
|
+
const found = scan(chunks);
|
|
147
|
+
return {
|
|
148
|
+
query: (requests) =>
|
|
149
|
+
new Map(
|
|
150
|
+
[...requests].map(([predicate, fields]) => [
|
|
151
|
+
predicate,
|
|
152
|
+
Object.fromEntries(fields.map((name) => [name, found.for(predicate, name)])),
|
|
153
|
+
]),
|
|
154
|
+
),
|
|
155
|
+
};
|
|
156
|
+
},
|
|
157
|
+
});
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
- Open fields are `String`, `Number`, `Date`, and entity fields. Boolean and
|
|
161
|
+
enumeration fields keep their declared domains.
|
|
162
|
+
- `query` receives a map from each predicate to its open field names, and answers with
|
|
163
|
+
a map from each predicate to the values for each field, possibly asynchronously. How
|
|
164
|
+
it finds them, and what it caches, is up to the extractor.
|
|
165
|
+
- The answer must cover exactly the requested predicates and fields, with values each
|
|
166
|
+
field can hold: strings, finite numbers, valid dates, or entities of the field's
|
|
167
|
+
type. Otherwise the job rejects before anything is classified.
|
|
168
|
+
- Scalar fields take exactly the values answered. Entity fields take them alongside
|
|
169
|
+
their registered instances. Extracted entities are only candidates: those that
|
|
170
|
+
asserted or denied evidence mentions are registered in `run.kb.entities`, and the
|
|
171
|
+
rest are discarded.
|
|
172
|
+
- A predicate with a field left empty is skipped for that chunk.
|
|
173
|
+
|
|
174
|
+
An entity's type and `id` are its identity, so the extractor decides which mentions
|
|
175
|
+
are the same entity by the ids it mints. `new Person("Alice")` from two chunks is one
|
|
176
|
+
entity.
|
|
177
|
+
|
|
178
|
+
## Jobs and execution
|
|
179
|
+
|
|
180
|
+
`run` is a single-cursor `IterableIterator`. Each yielded job classifies one chunk
|
|
181
|
+
and exposes only `execute(): Promise<void>`, sending up to `batchSize` questions per
|
|
182
|
+
request. `batchSize` defaults to 64. TypeSafe sets no upper limit. Re-executing a job makes a fresh attempt; a repeated
|
|
183
|
+
success adds fresh evidence.
|
|
184
|
+
|
|
185
|
+
The consumer can execute jobs sequentially, in batches, or through a concurrency
|
|
186
|
+
limiter. Jobs contain no scheduler, rate limiter, retry loop, or error handler.
|
|
187
|
+
`config.client` is optional and defaults to `new TypeSafeClient()`, created on the
|
|
188
|
+
first request. Pass a configured client to set the model, retry, timeout or
|
|
189
|
+
transport, or a scripted one in tests.
|
|
190
|
+
|
|
191
|
+
Request errors propagate unchanged from `execute()`. All answers for a chunk are
|
|
192
|
+
validated before any of that chunk's evidence is written. A failure does not
|
|
193
|
+
terminate the job iterator, remove earlier evidence, or retry automatically.
|
|
194
|
+
The caller can retry the same job or advance to another job.
|
|
195
|
+
|
|
196
|
+
`run.kb` is a live output store. Concurrent jobs add evidence in completion order.
|
|
197
|
+
Existing evidence, rules and entities retain their identities, but the storage
|
|
198
|
+
containers are independent of the input KB. Candidate domains use the construction-
|
|
199
|
+
time KB snapshot; new evidence does not introduce new candidates during a run.
|
|
200
|
+
|
|
201
|
+
## Corpus traversal
|
|
202
|
+
|
|
203
|
+
The classifier reads the whole corpus: every document present at construction
|
|
204
|
+
time. There is no source selection; to classify a subset, pass a
|
|
205
|
+
filtered view such as `corpus.filter((document) => document.metadata["kind"] !== "structured")`.
|
|
206
|
+
Its chunks register in the shared corpus, so evidence resolves from any handle. The adapter always uses a private recursive
|
|
207
|
+
splitter: up to **8,000 Unicode graphemes**, with up to
|
|
208
|
+
**200 graphemes of overlap**, preferring paragraph, line, and word boundaries.
|
|
209
|
+
Short documents remain intact. Jev constructs `chunkers.recursive()` internally;
|
|
210
|
+
source ranges and jobs are produced as iteration advances. The chunker indexes
|
|
211
|
+
the current document's grapheme boundaries when iteration starts.
|
|
212
|
+
|
|
213
|
+
Overlap supplies neighboring context. There is no configurable chunker or context
|
|
214
|
+
expansion step on the classifier API.
|
|
215
|
+
|
|
216
|
+
This is a conservative text-sizing policy, not an exact token budget. Jev 1.13's
|
|
217
|
+
[documented limits](https://docs.typesafe.ai/models) are 32k tokens for state plus
|
|
218
|
+
the longest question and 64k for the whole request. Candidate state, metadata and
|
|
219
|
+
questions also consume that budget; this passage bound alone does not guarantee
|
|
220
|
+
that arbitrarily large candidate batches fit.
|
|
221
|
+
|
|
222
|
+
Requests carry only the passage text. Chunk IDs, document IDs and source ranges are
|
|
223
|
+
kept out of them, so document names and coordinates cannot influence the model.
|
|
224
|
+
|
|
225
|
+
Each evidence source is the exact consumed chunk ID, resolvable through `corpus.resolve(source)`. The ID encodes the document and
|
|
226
|
+
range, and document text is immutable.
|
|
227
|
+
|
|
228
|
+
## Admission and results
|
|
229
|
+
|
|
230
|
+
- When `IRRELEVANT` is at least as probable as either polarity, admit neither.
|
|
231
|
+
- Otherwise, a polarity must meet `minimumProbability` and fall within
|
|
232
|
+
`ambiguityMargin` of the stronger polarity.
|
|
233
|
+
- Only permitted polarities are inserted. Forbidden outcomes are not relabeled or
|
|
234
|
+
renormalized into permitted ones.
|
|
235
|
+
- Both polarities can be admitted, preserving evidence that needs review.
|
|
236
|
+
|
|
237
|
+
New literals carry source, outcome probability,
|
|
238
|
+
candidate IDs, selected choice, SDK confidence, and the full distribution. SDK confidence remains separate from outcome probability. These
|
|
239
|
+
thresholds are application policy, not calibrated defaults.
|
|
240
|
+
|
|
241
|
+
## Optional relevance filtering
|
|
242
|
+
|
|
243
|
+
Set `config: { routing: true }` to reduce the candidate facts sent for classification
|
|
244
|
+
by filtering predicates and values for relevance to each passage. Each chunk job
|
|
245
|
+
first asks which predicates the passage may bear on. For predicates that make claims
|
|
246
|
+
about supplied entities or values, it can also ask which of those symbols the passage
|
|
247
|
+
involves. For example, before classifying ownership claims, it can narrow the list
|
|
248
|
+
of companies to those relevant to the passage. Only combinations of the retained
|
|
249
|
+
symbols are classified.
|
|
250
|
+
|
|
251
|
+
Symbol filtering runs when a retained predicate has symbols to filter and its
|
|
252
|
+
candidate combinations exceed `candidateProductCutoff` (default 16). Each distinct
|
|
253
|
+
symbol is checked once across all surviving predicates and roles. Boolean field
|
|
254
|
+
values are always retained. `predicateThreshold` and `symbolThreshold`
|
|
255
|
+
(default 0.3) are inclusive.
|
|
256
|
+
|
|
257
|
+
Filtering is **off by default**: a false negative in either pass silently drops
|
|
258
|
+
evidence, including denials. Filtering adds requests and does not guarantee cost savings. Run
|
|
259
|
+
`pnpm --filter @factbag/jev demo:staged` to compare both modes on a scripted fixture.
|
|
260
|
+
|
|
261
|
+
## Resolving contradictions
|
|
262
|
+
|
|
263
|
+
Each chunk is classified on its own, so a 2012 removal notice and a 2022
|
|
264
|
+
redesignation can leave the same fact asserted and denied. `resolver` reads those
|
|
265
|
+
passages together and asks, for each one, whether its account still stands. It works
|
|
266
|
+
like `classifier`: construction makes no remote calls, and each job is one request.
|
|
267
|
+
|
|
268
|
+
```ts
|
|
269
|
+
import { resolver } from "@factbag/jev";
|
|
270
|
+
|
|
271
|
+
const resolution = resolver(corpus, run.kb);
|
|
272
|
+
for (const job of resolution) {
|
|
273
|
+
await job.execute();
|
|
274
|
+
}
|
|
275
|
+
const resolved = resolution.kb;
|
|
276
|
+
```
|
|
277
|
+
|
|
278
|
+
- There is one job per atom with evidence of both signs. Its `execute()` sends
|
|
279
|
+
every distinct source passage in one request with a KEEP/RETRACT
|
|
280
|
+
question per passage: does another passage supersede this one for the fact as
|
|
281
|
+
described, including any date it is stated as of? Disagreement alone is not
|
|
282
|
+
supersession, so two documents that merely conflict both stand.
|
|
283
|
+
- The model judges documents, not the fact. Evidence from a retracted passage is removed
|
|
284
|
+
from `resolution.kb`; the rest stays, and the solver decides what the surviving
|
|
285
|
+
evidence means. Retracting every passage leaves the fact `unknown`, which is right:
|
|
286
|
+
the evidence was withdrawn, not disproved.
|
|
287
|
+
- A passage is retracted only when RETRACT reaches `minimumProbability` and leads KEEP by
|
|
288
|
+
more than `ambiguityMargin` (defaults 0.4 and 0). With two outcomes that means RETRACT must
|
|
289
|
+
exceed 0.5 in practice, whatever the minimum. Keeping the evidence is the default,
|
|
290
|
+
so an uncertain answer changes nothing.
|
|
291
|
+
- Every piece of conflicting evidence must have a `source` that resolves in the corpus.
|
|
292
|
+
Construction throws for evidence without a source, naming the atom, and propagates
|
|
293
|
+
corpus errors such as `Invalid chunk ID`, so no job exists until all are readable.
|
|
294
|
+
To resolve a KB with stipulated or tool-sourced evidence, decide those contradictions
|
|
295
|
+
first or resolve a fork without them.
|
|
296
|
+
- `resolution.kb` is an independent copy of the input, which is unchanged.
|
|
297
|
+
Contradictions are independent, so jobs can run in any order or concurrently.
|
|
298
|
+
- A job settles once. Request errors propagate unchanged and leave the job retryable;
|
|
299
|
+
executing it again after it succeeds throws. `config.client` defaults to
|
|
300
|
+
`new TypeSafeClient()`, as for the classifier.
|
|
301
|
+
|
|
302
|
+
## Internal structure
|
|
303
|
+
|
|
304
|
+
This package only connects Jev to the shared workflows in `@factbag/system-one`:
|
|
305
|
+
the TypeSafe client, Jev's batch limits, and the public signatures. Candidate
|
|
306
|
+
selection, admission, prompts, batching, and answer validation live there and are
|
|
307
|
+
bundled into the published package. The same code serves `@factbag/clef`.
|
|
308
|
+
|
|
309
|
+
## Examples and checks
|
|
310
|
+
|
|
311
|
+
Read [Fix one fact, not the whole answer](https://github.com/factbag/factbag/blob/main/providers/jev/docs/README.md) for the narrative, or the
|
|
312
|
+
[example notes](https://github.com/factbag/factbag/blob/main/providers/jev/examples/README.md) for the runnable scenarios.
|
|
313
|
+
|
|
314
|
+
```sh
|
|
315
|
+
pnpm --filter @factbag/jev demo
|
|
316
|
+
pnpm --filter @factbag/jev test
|
|
317
|
+
pnpm --filter @factbag/jev typecheck
|
|
318
|
+
```
|
|
319
|
+
|
|
320
|
+
Demos use the real SDK with MSW HTTP interception; focused unit tests also use
|
|
321
|
+
injected clients. Neither needs credentials or live inference.
|