@odla-ai/kg 0.3.2 → 0.4.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.
- package/dist/chunk-T6SYIVST.js +376 -0
- package/dist/chunk-T6SYIVST.js.map +1 -0
- package/dist/index.cjs +410 -36
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +330 -5
- package/dist/index.d.ts +330 -5
- package/dist/index.js +249 -38
- package/dist/index.js.map +1 -1
- package/dist/lenses-C7Q7Gvnx.d.cts +123 -0
- package/dist/lenses-C7Q7Gvnx.d.ts +123 -0
- package/dist/temporal/index.cjs +1 -689
- package/dist/temporal/index.cjs.map +1 -1
- package/dist/temporal/index.d.cts +4 -565
- package/dist/temporal/index.d.ts +4 -565
- package/dist/temporal/index.js +20 -977
- package/dist/temporal/index.js.map +1 -1
- package/package.json +3 -3
- package/dist/chunk-V3N2GRYU.js +0 -73
- package/dist/chunk-V3N2GRYU.js.map +0 -1
- package/dist/sources-nJyD0JUP.d.cts +0 -256
- package/dist/sources-nJyD0JUP.d.ts +0 -256
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import { Value } from '@odla-ai/db';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* The output of a connector: one acquired item. Exactly one of `text` or
|
|
5
|
+
* `fragment` is set — `text` goes through LLM extraction, `fragment` is already
|
|
6
|
+
* ontology-typed and goes straight to the graph writer (structured feeds).
|
|
7
|
+
*/
|
|
8
|
+
interface RawItem {
|
|
9
|
+
url: string;
|
|
10
|
+
title: string;
|
|
11
|
+
date?: string;
|
|
12
|
+
sourceName: string;
|
|
13
|
+
sourceKind: string;
|
|
14
|
+
watch?: string | null;
|
|
15
|
+
text?: string;
|
|
16
|
+
fragment?: GraphFragment;
|
|
17
|
+
}
|
|
18
|
+
/** A graph node = an odla-db entity in a namespace, keyed by a natural key. */
|
|
19
|
+
interface GraphNode {
|
|
20
|
+
type: string;
|
|
21
|
+
key: string;
|
|
22
|
+
attrs: Record<string, Value>;
|
|
23
|
+
}
|
|
24
|
+
/** A graph edge = an odla-db `link` from one node to another by forward label. */
|
|
25
|
+
interface GraphEdge {
|
|
26
|
+
from: {
|
|
27
|
+
type: string;
|
|
28
|
+
key: string;
|
|
29
|
+
};
|
|
30
|
+
to: {
|
|
31
|
+
type: string;
|
|
32
|
+
key: string;
|
|
33
|
+
};
|
|
34
|
+
label: string;
|
|
35
|
+
}
|
|
36
|
+
/** The single shape the graph writer consumes, whatever produced it. */
|
|
37
|
+
interface GraphFragment {
|
|
38
|
+
nodes: GraphNode[];
|
|
39
|
+
edges: GraphEdge[];
|
|
40
|
+
}
|
|
41
|
+
/** What an extractor turns a text RawItem into: a fragment plus a prose summary. */
|
|
42
|
+
interface ExtractResult {
|
|
43
|
+
fragment: GraphFragment;
|
|
44
|
+
summary: string;
|
|
45
|
+
}
|
|
46
|
+
/** Provider-agnostic LLM usage accounting. */
|
|
47
|
+
interface Usage {
|
|
48
|
+
calls: number;
|
|
49
|
+
inputTokens: number;
|
|
50
|
+
outputTokens: number;
|
|
51
|
+
}
|
|
52
|
+
/** Create zeroed provider-agnostic usage totals for one pipeline run. */
|
|
53
|
+
declare function emptyUsage(): Usage;
|
|
54
|
+
/** Mutate an accumulator by adding call, input-token, and output-token totals. */
|
|
55
|
+
declare function addUsage(into: Usage, more: Usage): void;
|
|
56
|
+
|
|
57
|
+
/** A 2-D point in a normalized layout/map space (for the geo proximity lens). */
|
|
58
|
+
interface XY {
|
|
59
|
+
x: number;
|
|
60
|
+
y: number;
|
|
61
|
+
}
|
|
62
|
+
/** One undirected weighted pair, with (capped) bridging node ids as evidence. */
|
|
63
|
+
interface WeightedPair {
|
|
64
|
+
a: string;
|
|
65
|
+
b: string;
|
|
66
|
+
w: number;
|
|
67
|
+
via: string[];
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Bridge → target sets through a REIFIED relationship node (affiliation,
|
|
71
|
+
* funding_round, record): every reified node with a `bridgeLabel` edge to the
|
|
72
|
+
* bridge and a `targetLabel` edge to a target contributes that target to the
|
|
73
|
+
* bridge's set. Ids are `type:key`.
|
|
74
|
+
*/
|
|
75
|
+
declare function reifiedBridgeTargets(fragment: GraphFragment, opts: {
|
|
76
|
+
reified: string;
|
|
77
|
+
bridgeLabel: string;
|
|
78
|
+
targetLabel: string;
|
|
79
|
+
}): Map<string, Set<string>>;
|
|
80
|
+
/** Direct-edge targets: `from` node id → set of `to` node ids for one label. */
|
|
81
|
+
declare function directTargets(fragment: GraphFragment, label: string): Map<string, Set<string>>;
|
|
82
|
+
/** Compose A→B with B→C into A→C (e.g. person→companies ∘ company→counties). */
|
|
83
|
+
declare function composeTargets(ab: Map<string, Set<string>>, bc: Map<string, Set<string>>): Map<string, Set<string>>;
|
|
84
|
+
/**
|
|
85
|
+
* The bipartite projection: targets sharing a bridge become pairs, weight =
|
|
86
|
+
* number of distinct shared bridges. `maxPerBridge` skips promiscuous hubs
|
|
87
|
+
* (a bridge touching 40 targets says little about any pair). Deterministic
|
|
88
|
+
* pair order (a < b, then sorted).
|
|
89
|
+
*/
|
|
90
|
+
declare function projectBridges(bridges: Map<string, Set<string>>, opts?: {
|
|
91
|
+
maxPerBridge?: number;
|
|
92
|
+
viaCap?: number;
|
|
93
|
+
}): WeightedPair[];
|
|
94
|
+
/**
|
|
95
|
+
* Temporal cohort pairs: each node links to its k nearest neighbors in
|
|
96
|
+
* arrival time, weight decaying with the gap (0.5 per halfLife). Nodes
|
|
97
|
+
* without a date contribute nothing.
|
|
98
|
+
*/
|
|
99
|
+
declare function timePairs(arrivals: Map<string, number>, opts?: {
|
|
100
|
+
k?: number;
|
|
101
|
+
halfLifeDays?: number;
|
|
102
|
+
}): WeightedPair[];
|
|
103
|
+
/**
|
|
104
|
+
* Spatial proximity pairs: k nearest neighbors in normalized map space,
|
|
105
|
+
* weight decaying with distance (0.5 per halfDist). Nodes without a
|
|
106
|
+
* position contribute nothing. O(n²) — fine for the ≤1k-node universes
|
|
107
|
+
* lenses operate on.
|
|
108
|
+
*/
|
|
109
|
+
declare function geoPairs(positions: Map<string, XY>, opts?: {
|
|
110
|
+
k?: number;
|
|
111
|
+
halfDist?: number;
|
|
112
|
+
}): WeightedPair[];
|
|
113
|
+
/**
|
|
114
|
+
* Blend lens edge sets: each set is normalized to a max weight of 1 (a lens
|
|
115
|
+
* with big raw counts must not drown the others), scaled by its slider
|
|
116
|
+
* weight, and summed per pair. Zero-weight lenses drop out entirely.
|
|
117
|
+
*/
|
|
118
|
+
declare function blendPairs(sets: Array<{
|
|
119
|
+
pairs: WeightedPair[];
|
|
120
|
+
weight: number;
|
|
121
|
+
}>): WeightedPair[];
|
|
122
|
+
|
|
123
|
+
export { type ExtractResult as E, type GraphFragment as G, type RawItem as R, type Usage as U, type WeightedPair as W, type XY as X, type GraphEdge as a, type GraphNode as b, addUsage as c, blendPairs as d, emptyUsage as e, composeTargets as f, directTargets as g, geoPairs as h, projectBridges as p, reifiedBridgeTargets as r, timePairs as t };
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import { Value } from '@odla-ai/db';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* The output of a connector: one acquired item. Exactly one of `text` or
|
|
5
|
+
* `fragment` is set — `text` goes through LLM extraction, `fragment` is already
|
|
6
|
+
* ontology-typed and goes straight to the graph writer (structured feeds).
|
|
7
|
+
*/
|
|
8
|
+
interface RawItem {
|
|
9
|
+
url: string;
|
|
10
|
+
title: string;
|
|
11
|
+
date?: string;
|
|
12
|
+
sourceName: string;
|
|
13
|
+
sourceKind: string;
|
|
14
|
+
watch?: string | null;
|
|
15
|
+
text?: string;
|
|
16
|
+
fragment?: GraphFragment;
|
|
17
|
+
}
|
|
18
|
+
/** A graph node = an odla-db entity in a namespace, keyed by a natural key. */
|
|
19
|
+
interface GraphNode {
|
|
20
|
+
type: string;
|
|
21
|
+
key: string;
|
|
22
|
+
attrs: Record<string, Value>;
|
|
23
|
+
}
|
|
24
|
+
/** A graph edge = an odla-db `link` from one node to another by forward label. */
|
|
25
|
+
interface GraphEdge {
|
|
26
|
+
from: {
|
|
27
|
+
type: string;
|
|
28
|
+
key: string;
|
|
29
|
+
};
|
|
30
|
+
to: {
|
|
31
|
+
type: string;
|
|
32
|
+
key: string;
|
|
33
|
+
};
|
|
34
|
+
label: string;
|
|
35
|
+
}
|
|
36
|
+
/** The single shape the graph writer consumes, whatever produced it. */
|
|
37
|
+
interface GraphFragment {
|
|
38
|
+
nodes: GraphNode[];
|
|
39
|
+
edges: GraphEdge[];
|
|
40
|
+
}
|
|
41
|
+
/** What an extractor turns a text RawItem into: a fragment plus a prose summary. */
|
|
42
|
+
interface ExtractResult {
|
|
43
|
+
fragment: GraphFragment;
|
|
44
|
+
summary: string;
|
|
45
|
+
}
|
|
46
|
+
/** Provider-agnostic LLM usage accounting. */
|
|
47
|
+
interface Usage {
|
|
48
|
+
calls: number;
|
|
49
|
+
inputTokens: number;
|
|
50
|
+
outputTokens: number;
|
|
51
|
+
}
|
|
52
|
+
/** Create zeroed provider-agnostic usage totals for one pipeline run. */
|
|
53
|
+
declare function emptyUsage(): Usage;
|
|
54
|
+
/** Mutate an accumulator by adding call, input-token, and output-token totals. */
|
|
55
|
+
declare function addUsage(into: Usage, more: Usage): void;
|
|
56
|
+
|
|
57
|
+
/** A 2-D point in a normalized layout/map space (for the geo proximity lens). */
|
|
58
|
+
interface XY {
|
|
59
|
+
x: number;
|
|
60
|
+
y: number;
|
|
61
|
+
}
|
|
62
|
+
/** One undirected weighted pair, with (capped) bridging node ids as evidence. */
|
|
63
|
+
interface WeightedPair {
|
|
64
|
+
a: string;
|
|
65
|
+
b: string;
|
|
66
|
+
w: number;
|
|
67
|
+
via: string[];
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Bridge → target sets through a REIFIED relationship node (affiliation,
|
|
71
|
+
* funding_round, record): every reified node with a `bridgeLabel` edge to the
|
|
72
|
+
* bridge and a `targetLabel` edge to a target contributes that target to the
|
|
73
|
+
* bridge's set. Ids are `type:key`.
|
|
74
|
+
*/
|
|
75
|
+
declare function reifiedBridgeTargets(fragment: GraphFragment, opts: {
|
|
76
|
+
reified: string;
|
|
77
|
+
bridgeLabel: string;
|
|
78
|
+
targetLabel: string;
|
|
79
|
+
}): Map<string, Set<string>>;
|
|
80
|
+
/** Direct-edge targets: `from` node id → set of `to` node ids for one label. */
|
|
81
|
+
declare function directTargets(fragment: GraphFragment, label: string): Map<string, Set<string>>;
|
|
82
|
+
/** Compose A→B with B→C into A→C (e.g. person→companies ∘ company→counties). */
|
|
83
|
+
declare function composeTargets(ab: Map<string, Set<string>>, bc: Map<string, Set<string>>): Map<string, Set<string>>;
|
|
84
|
+
/**
|
|
85
|
+
* The bipartite projection: targets sharing a bridge become pairs, weight =
|
|
86
|
+
* number of distinct shared bridges. `maxPerBridge` skips promiscuous hubs
|
|
87
|
+
* (a bridge touching 40 targets says little about any pair). Deterministic
|
|
88
|
+
* pair order (a < b, then sorted).
|
|
89
|
+
*/
|
|
90
|
+
declare function projectBridges(bridges: Map<string, Set<string>>, opts?: {
|
|
91
|
+
maxPerBridge?: number;
|
|
92
|
+
viaCap?: number;
|
|
93
|
+
}): WeightedPair[];
|
|
94
|
+
/**
|
|
95
|
+
* Temporal cohort pairs: each node links to its k nearest neighbors in
|
|
96
|
+
* arrival time, weight decaying with the gap (0.5 per halfLife). Nodes
|
|
97
|
+
* without a date contribute nothing.
|
|
98
|
+
*/
|
|
99
|
+
declare function timePairs(arrivals: Map<string, number>, opts?: {
|
|
100
|
+
k?: number;
|
|
101
|
+
halfLifeDays?: number;
|
|
102
|
+
}): WeightedPair[];
|
|
103
|
+
/**
|
|
104
|
+
* Spatial proximity pairs: k nearest neighbors in normalized map space,
|
|
105
|
+
* weight decaying with distance (0.5 per halfDist). Nodes without a
|
|
106
|
+
* position contribute nothing. O(n²) — fine for the ≤1k-node universes
|
|
107
|
+
* lenses operate on.
|
|
108
|
+
*/
|
|
109
|
+
declare function geoPairs(positions: Map<string, XY>, opts?: {
|
|
110
|
+
k?: number;
|
|
111
|
+
halfDist?: number;
|
|
112
|
+
}): WeightedPair[];
|
|
113
|
+
/**
|
|
114
|
+
* Blend lens edge sets: each set is normalized to a max weight of 1 (a lens
|
|
115
|
+
* with big raw counts must not drown the others), scaled by its slider
|
|
116
|
+
* weight, and summed per pair. Zero-weight lenses drop out entirely.
|
|
117
|
+
*/
|
|
118
|
+
declare function blendPairs(sets: Array<{
|
|
119
|
+
pairs: WeightedPair[];
|
|
120
|
+
weight: number;
|
|
121
|
+
}>): WeightedPair[];
|
|
122
|
+
|
|
123
|
+
export { type ExtractResult as E, type GraphFragment as G, type RawItem as R, type Usage as U, type WeightedPair as W, type XY as X, type GraphEdge as a, type GraphNode as b, addUsage as c, blendPairs as d, emptyUsage as e, composeTargets as f, directTargets as g, geoPairs as h, projectBridges as p, reifiedBridgeTargets as r, timePairs as t };
|