@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.
@@ -0,0 +1,102 @@
1
+ import { GuardedKB, KnowledgeBase } from "factbag/kb";
2
+ import { Chunk, Corpus, Metadata } from "factbag/corpus";
3
+ import { Entity, PredicateDeclaration, Scalar } from "factbag/dsl";
4
+ import { TypeSafeClient } from "@typesafe-ai/sdk";
5
+ /** Default minimum probability for admitting signed evidence. @beta */
6
+ export declare const DEFAULT_MINIMUM_PROBABILITY = .4;
7
+ /** Default maximum probability gap from the strongest signed outcome. @beta */
8
+ export declare const DEFAULT_AMBIGUITY_MARGIN = 0;
9
+ /** Whether heuristic predicate and symbol filtering is enabled by default. @beta */
10
+ export declare const DEFAULT_ROUTING_ENABLED: boolean;
11
+ /** Default inclusive probability threshold for retaining a predicate. @beta */
12
+ export declare const DEFAULT_PREDICATE_THRESHOLD = .3;
13
+ /** Default inclusive probability threshold for retaining a symbol. @beta */
14
+ export declare const DEFAULT_SYMBOL_THRESHOLD = .3;
15
+ /** Default candidate product size above which symbol filtering runs. @beta */
16
+ export declare const DEFAULT_CANDIDATE_PRODUCT_CUTOFF = 16;
17
+ /** How classification and resolution use a model's answers, whichever model gives them. @beta */
18
+ type Settings = {
19
+ /** Minimum probability for admitting signed evidence or retracting a passage, default 0.4. */
20
+ readonly minimumProbability?: number;
21
+ /** Classification: maximum gap from the strongest signed outcome. Resolution: required RETRACT lead over KEEP. Default 0. */
22
+ readonly ambiguityMargin?: number;
23
+ /** Enable heuristic predicate and symbol filtering, default false. */
24
+ readonly routing?: boolean;
25
+ /** Inclusive probability at which a predicate is kept for a passage, default 0.3. */
26
+ readonly predicateThreshold?: number;
27
+ /** Inclusive probability at which a symbol is kept for a passage, default 0.3. */
28
+ readonly symbolThreshold?: number;
29
+ /** Run symbol filtering if a retained predicate with non-Boolean roles exceeds this raw Cartesian product, default 16. */
30
+ readonly candidateProductCutoff?: number;
31
+ /** Questions per request when work can be split, up to the provider's limit. Defaults to the provider's choice. */
32
+ readonly batchSize?: number;
33
+ };
34
+ /** Settings with every default applied. @beta */
35
+ type Normalized = Readonly<Required<Settings>>;
36
+ /**
37
+ * Candidate values for each requested field, by predicate and then by field name. Open
38
+ * fields are `String`, `Number`, `Date`, and entity fields. The same value may be offered
39
+ * to any number of fields.
40
+ * @beta
41
+ */
42
+ type SymbolAnswer = ReadonlyMap<PredicateDeclaration, Readonly<Record<string, readonly (Scalar | Entity)[]>>>;
43
+ /**
44
+ * Candidate symbols found in a fixed set of chunks. How and when it reads them, and what
45
+ * it caches between queries, is up to the implementation. An entity's type and id are its
46
+ * identity, so the ids it mints decide which mentions are the same entity.
47
+ * @beta
48
+ */
49
+ type ChunkSymbolExtractor = {
50
+ /** Candidate values for exactly the requested fields of each requested predicate. */
51
+ readonly query: (requests: ReadonlyMap<PredicateDeclaration, readonly string[]>) => SymbolAnswer | Promise<SymbolAnswer>;
52
+ };
53
+ /** Build an extractor over the chunks it will be queried about. @beta */
54
+ type CreateChunkSymbolExtractor = (chunks: readonly Chunk[]) => ChunkSymbolExtractor;
55
+ /** One opaque unit of work. Its effects are written to the run’s knowledge base. @beta */
56
+ type Job = {
57
+ readonly execute: () => Promise<void>;
58
+ };
59
+ /** A single-cursor stream of jobs sharing an independent output knowledge base. @beta */
60
+ type Run = IterableIterator<Job> & {
61
+ readonly kb: KnowledgeBase;
62
+ };
63
+ /**
64
+ * Jev settings. Model, timeout, and retry settings belong to the SDK client. `batchSize`
65
+ * defaults to 64 questions per request; TypeSafe sets no upper limit.
66
+ *
67
+ * @beta
68
+ */
69
+ export type Config = Settings & {
70
+ /** Defaults to a lazy TypeSafeClient configured from TYPESAFE_* environment variables. */
71
+ readonly client?: TypeSafeClient;
72
+ };
73
+ /** Normalize settings once, sharing a lazy SDK client when reused across runs. @beta */
74
+ export declare function createConfig(config?: Config): Normalized & Config;
75
+ /**
76
+ * Parse corpus evidence into a new knowledge base using guarded predicate operations.
77
+ * Validate available predicates eagerly and return a lazy iterator of executable jobs.
78
+ * Bare KBs expose all known predicates; explicit guards retain their permission policy.
79
+ * Only job.execute() makes a remote call. The consumer owns pacing and concurrency.
80
+ * With `createChunkSymbolExtractor`, open-ended and entity fields also take the values
81
+ * each chunk offers, so they need no finite domain up front.
82
+ * @beta
83
+ */
84
+ export declare function classifier<M extends Metadata = Metadata>(input: {
85
+ corpus: Corpus<M>;
86
+ input: KnowledgeBase | GuardedKB;
87
+ config?: Config;
88
+ createChunkSymbolExtractor?: CreateChunkSymbolExtractor;
89
+ }): Run;
90
+ /**
91
+ * Settle contradictions in a knowledge base by reading each one's evidence together.
92
+ * Find every atom with evidence of both signs and return a lazy iterator of jobs, one per
93
+ * contradiction. Each job sends all of the contradiction's passages to Jev in one request
94
+ * and asks, for each passage, whether its account still stands. Evidence from superseded
95
+ * passages is retracted from `kb`; the rest is kept, so the solver decides what the
96
+ * surviving evidence means. The input KB is not modified. Throws during construction if
97
+ * conflicting evidence has no source, and propagates corpus errors for sources that are not
98
+ * resolvable chunk IDs. The consumer owns pacing and concurrency.
99
+ * @beta
100
+ */
101
+ export declare function resolver<M extends Metadata = Metadata>(corpus: Corpus<M>, kb: KnowledgeBase, config?: Config): Run;
102
+ export type { ChunkSymbolExtractor, CreateChunkSymbolExtractor, Job, Normalized, Run, Settings, SymbolAnswer };