@juspay/neurolink 10.3.1 → 10.4.0
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 +6 -0
- package/dist/browser/neurolink.min.js +382 -372
- package/dist/index.d.ts +1 -0
- package/dist/index.js +3 -0
- package/dist/knowledge/context.d.ts +18 -0
- package/dist/knowledge/context.js +91 -0
- package/dist/knowledge/defaults.d.ts +24 -0
- package/dist/knowledge/defaults.js +29 -0
- package/dist/knowledge/engine.d.ts +35 -0
- package/dist/knowledge/engine.js +179 -0
- package/dist/knowledge/index.d.ts +15 -0
- package/dist/knowledge/index.js +15 -0
- package/dist/knowledge/indexCache.d.ts +19 -0
- package/dist/knowledge/indexCache.js +109 -0
- package/dist/knowledge/knowledgeIndex.d.ts +41 -0
- package/dist/knowledge/knowledgeIndex.js +204 -0
- package/dist/knowledge/normalize.d.ts +32 -0
- package/dist/knowledge/normalize.js +74 -0
- package/dist/knowledge/resolve.d.ts +18 -0
- package/dist/knowledge/resolve.js +156 -0
- package/dist/knowledge/retrieval.d.ts +16 -0
- package/dist/knowledge/retrieval.js +221 -0
- package/dist/lib/files/fileTools.d.ts +1 -1
- package/dist/lib/index.d.ts +1 -0
- package/dist/lib/index.js +3 -0
- package/dist/lib/knowledge/context.d.ts +18 -0
- package/dist/lib/knowledge/context.js +92 -0
- package/dist/lib/knowledge/defaults.d.ts +24 -0
- package/dist/lib/knowledge/defaults.js +30 -0
- package/dist/lib/knowledge/engine.d.ts +35 -0
- package/dist/lib/knowledge/engine.js +180 -0
- package/dist/lib/knowledge/index.d.ts +15 -0
- package/dist/lib/knowledge/index.js +16 -0
- package/dist/lib/knowledge/indexCache.d.ts +19 -0
- package/dist/lib/knowledge/indexCache.js +110 -0
- package/dist/lib/knowledge/knowledgeIndex.d.ts +41 -0
- package/dist/lib/knowledge/knowledgeIndex.js +205 -0
- package/dist/lib/knowledge/normalize.d.ts +32 -0
- package/dist/lib/knowledge/normalize.js +75 -0
- package/dist/lib/knowledge/resolve.d.ts +18 -0
- package/dist/lib/knowledge/resolve.js +157 -0
- package/dist/lib/knowledge/retrieval.d.ts +16 -0
- package/dist/lib/knowledge/retrieval.js +222 -0
- package/dist/lib/neurolink.d.ts +14 -1
- package/dist/lib/neurolink.js +112 -3
- package/dist/lib/types/config.d.ts +12 -0
- package/dist/lib/types/conversation.d.ts +1 -1
- package/dist/lib/types/dynamic.d.ts +12 -0
- package/dist/lib/types/generate.d.ts +14 -0
- package/dist/lib/types/index.d.ts +1 -0
- package/dist/lib/types/index.js +1 -0
- package/dist/lib/types/knowledge.d.ts +342 -0
- package/dist/lib/types/knowledge.js +30 -0
- package/dist/lib/types/stream.d.ts +14 -0
- package/dist/neurolink.d.ts +14 -1
- package/dist/neurolink.js +112 -3
- package/dist/types/config.d.ts +12 -0
- package/dist/types/conversation.d.ts +1 -1
- package/dist/types/dynamic.d.ts +12 -0
- package/dist/types/generate.d.ts +14 -0
- package/dist/types/index.d.ts +1 -0
- package/dist/types/index.js +1 -0
- package/dist/types/knowledge.d.ts +342 -0
- package/dist/types/knowledge.js +29 -0
- package/dist/types/stream.d.ts +14 -0
- package/package.json +2 -1
|
@@ -429,7 +429,7 @@ export type SessionMetadata = {
|
|
|
429
429
|
* Report type for agentic loop reports
|
|
430
430
|
* Identifies the platform or category of the report
|
|
431
431
|
*/
|
|
432
|
-
export type AgenticLoopReportType = "META" | "GOOGLEADS" | "GOOGLEGA4" | "OTHER";
|
|
432
|
+
export type AgenticLoopReportType = "META" | "GOOGLEADS" | "GOOGLEGA4" | "SHOPIFY" | "BREEZE" | "OTHER";
|
|
433
433
|
/**
|
|
434
434
|
* Status of an agentic loop report
|
|
435
435
|
*/
|
package/dist/types/dynamic.d.ts
CHANGED
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
* @module types/dynamic
|
|
8
8
|
*/
|
|
9
9
|
import type { AIProviderName } from "../constants/enums.js";
|
|
10
|
+
import type { KnowledgeRequestScope } from "./knowledge.js";
|
|
10
11
|
/**
|
|
11
12
|
* Context passed to context-aware dynamic argument functions.
|
|
12
13
|
* `requestContext` is whatever the consumer passed as `dynamicContext` —
|
|
@@ -39,6 +40,17 @@ export type DynamicArgument<T> = T | (() => T) | (() => Promise<T>) | ((context:
|
|
|
39
40
|
* instead of static values for context-aware resolution.
|
|
40
41
|
*/
|
|
41
42
|
export type DynamicOptions = {
|
|
43
|
+
/**
|
|
44
|
+
* Opt this call into the knowledge grounding configured on the NeuroLink
|
|
45
|
+
* instance. This flag is intentionally static because grounding runs before
|
|
46
|
+
* dynamic arguments are resolved.
|
|
47
|
+
*/
|
|
48
|
+
useKnowledgeGrounding?: boolean;
|
|
49
|
+
/**
|
|
50
|
+
* Enabled integrations used to scope knowledge retrieval for this turn.
|
|
51
|
+
* This scope is intentionally static for the same reason.
|
|
52
|
+
*/
|
|
53
|
+
knowledgeContext?: KnowledgeRequestScope;
|
|
42
54
|
model?: DynamicArgument<string>;
|
|
43
55
|
provider?: DynamicArgument<AIProviderName | string>;
|
|
44
56
|
temperature?: DynamicArgument<number>;
|
package/dist/types/generate.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { AIProviderName } from "../constants/enums.js";
|
|
2
2
|
import type { RAGConfig } from "./rag.js";
|
|
3
|
+
import type { KnowledgeGroundingMetadata, KnowledgeRequestScope } from "./knowledge.js";
|
|
3
4
|
import type { SkillsCallOptions } from "./skills.js";
|
|
4
5
|
import type { AnalyticsData, TokenUsage } from "./analytics.js";
|
|
5
6
|
import type { JsonValue } from "./common.js";
|
|
@@ -545,6 +546,17 @@ export type GenerateOptions = {
|
|
|
545
546
|
onError?: OnErrorCallback;
|
|
546
547
|
/** Pre-validated user context for the request */
|
|
547
548
|
requestContext?: Record<string, unknown>;
|
|
549
|
+
/**
|
|
550
|
+
* Opt this generation call into the knowledge grounding configured on the
|
|
551
|
+
* NeuroLink instance. Defaults to `false` when omitted.
|
|
552
|
+
*/
|
|
553
|
+
useKnowledgeGrounding?: boolean;
|
|
554
|
+
/**
|
|
555
|
+
* Enabled integrations used to scope knowledge retrieval for this turn.
|
|
556
|
+
* Used only when `useKnowledgeGrounding` is true and knowledge grounding is
|
|
557
|
+
* enabled on the NeuroLink instance.
|
|
558
|
+
*/
|
|
559
|
+
knowledgeContext?: KnowledgeRequestScope;
|
|
548
560
|
/** Raw auth token — validated by configured auth provider */
|
|
549
561
|
auth?: {
|
|
550
562
|
token: string;
|
|
@@ -690,6 +702,8 @@ export type GenerateStopReason = "completed" | "step-cap" | "context-cap" | "tim
|
|
|
690
702
|
*/
|
|
691
703
|
export type GenerateResult = {
|
|
692
704
|
content: string;
|
|
705
|
+
/** Knowledge-grounding diagnostics for this turn (present only when grounding ran). */
|
|
706
|
+
knowledge?: KnowledgeGroundingMetadata;
|
|
693
707
|
/**
|
|
694
708
|
* Parsed structured object when a `schema` was requested. Populated from
|
|
695
709
|
* AI-SDK experimental_output, or from text-mode coercion (balanced-scan +
|
package/dist/types/index.d.ts
CHANGED
|
@@ -28,6 +28,7 @@ export * from "./generate.js";
|
|
|
28
28
|
export * from "./grounding.js";
|
|
29
29
|
export * from "./guardrails.js";
|
|
30
30
|
export * from "./hitl.js";
|
|
31
|
+
export * from "./knowledge.js";
|
|
31
32
|
export * from "./livekit.js";
|
|
32
33
|
export * from "./mcp.js";
|
|
33
34
|
export * from "./mcpOutput.js";
|
package/dist/types/index.js
CHANGED
|
@@ -29,6 +29,7 @@ export * from "./generate.js";
|
|
|
29
29
|
export * from "./grounding.js";
|
|
30
30
|
export * from "./guardrails.js";
|
|
31
31
|
export * from "./hitl.js";
|
|
32
|
+
export * from "./knowledge.js";
|
|
32
33
|
export * from "./livekit.js";
|
|
33
34
|
export * from "./mcp.js";
|
|
34
35
|
export * from "./mcpOutput.js";
|
|
@@ -0,0 +1,342 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Knowledge grounding — lexical-first host-supplied knowledge retrieval.
|
|
3
|
+
*
|
|
4
|
+
* A host application owns a structured *knowledge registry*: versioned entries
|
|
5
|
+
* describing concepts, configuration, taxonomies, procedures, and operating
|
|
6
|
+
* rules. NeuroLink owns the
|
|
7
|
+
* generic engine that ingests that registry, builds an in-memory lexical
|
|
8
|
+
* index once per instance, and — independently of tool routing — retrieves a
|
|
9
|
+
* small, token-bounded set of relevant entries before each main model call.
|
|
10
|
+
* The selected entries are attached as *ephemeral context*: visible to the
|
|
11
|
+
* current generation call, never persisted into conversation memory.
|
|
12
|
+
*
|
|
13
|
+
* This is retrieval-augmented generation WITHOUT vector retrieval. The first
|
|
14
|
+
* release ranks with exact identifiers, reviewed aliases, metadata filters,
|
|
15
|
+
* and weighted field-aware BM25 only. No embedding model, embedding service,
|
|
16
|
+
* or vector store is initialized. An LLM reranker and semantic retrieval are
|
|
17
|
+
* deferred behind an explicit evaluation gate.
|
|
18
|
+
*
|
|
19
|
+
* Ownership boundary: NeuroLink defines the contracts below and the engine;
|
|
20
|
+
* it never contains host product content. The host supplies content and
|
|
21
|
+
* per-request scope. The engine stays provider-neutral.
|
|
22
|
+
*
|
|
23
|
+
* Type names are globally prefixed `Knowledge*` to satisfy the repo's
|
|
24
|
+
* unique-type-name rule and to avoid collision with the pre-existing
|
|
25
|
+
* web-search `grounding.ts` vocabulary (`EnhancedGroundingMetadata` et al.),
|
|
26
|
+
* which is a different concept (Google search grounding, not product
|
|
27
|
+
* knowledge).
|
|
28
|
+
*/
|
|
29
|
+
/** What a knowledge entry primarily is. Drives context labelling, not ranking. */
|
|
30
|
+
export type KnowledgeEntryKind = "concept" | "text" | "configuration" | "tool" | "procedure" | "policy" | "troubleshooting";
|
|
31
|
+
/** Lifecycle state. Only `active` entries are retrievable by default. */
|
|
32
|
+
export type KnowledgeStatus = "draft" | "active" | "deprecated";
|
|
33
|
+
/**
|
|
34
|
+
* Retrieval mode. Only `"lexical"` is supported in the first release; the
|
|
35
|
+
* literal is a union of one to reserve a clean upgrade path to `"hybrid"` /
|
|
36
|
+
* `"vector"` without a breaking change.
|
|
37
|
+
*/
|
|
38
|
+
export type KnowledgeRetrievalMode = "lexical";
|
|
39
|
+
/**
|
|
40
|
+
* Confidence class returned with every retrieval so the host prompt can
|
|
41
|
+
* instruct the model to qualify low-confidence answers rather than present
|
|
42
|
+
* them as authoritative.
|
|
43
|
+
*/
|
|
44
|
+
export type KnowledgeRetrievalConfidence = "high" | "medium" | "low" | "none";
|
|
45
|
+
/** The five weighted text fields used by the field-aware lexical scorer. */
|
|
46
|
+
export type KnowledgeFieldName = "title" | "aliases" | "keywords" | "summary" | "body";
|
|
47
|
+
/**
|
|
48
|
+
* The record a host author writes. `id`, `title`, `summary`, `domain`, and
|
|
49
|
+
* `integrations` are required; every other field is optional and omitted
|
|
50
|
+
* optionals fall back to SDK defaults during normalization.
|
|
51
|
+
*/
|
|
52
|
+
export type KnowledgeEntryInput = {
|
|
53
|
+
/** Stable unique id (e.g. "account.multi-step-flow"). Drives exact-match lookup and citations. */
|
|
54
|
+
id: string;
|
|
55
|
+
/** Human-readable name of the concept/setting. Highest-weighted search field. */
|
|
56
|
+
title: string;
|
|
57
|
+
/** One-line searchable description — the short answer when a full body is unnecessary. */
|
|
58
|
+
summary: string;
|
|
59
|
+
/** Primary grouping and the main retrieval filter (e.g. "account-settings"). */
|
|
60
|
+
domain: string;
|
|
61
|
+
/** Integration identifiers this entry applies to. Empty array = applies to all integrations. */
|
|
62
|
+
integrations: string[];
|
|
63
|
+
/** What the entry is (concept, configuration, procedure, …). Default "text". Labels context, not ranking. */
|
|
64
|
+
kind?: KnowledgeEntryKind;
|
|
65
|
+
/** Lifecycle state. Default "active"; only active entries are retrievable. */
|
|
66
|
+
status?: KnowledgeStatus;
|
|
67
|
+
/** Full explanatory content (Markdown). Use only when the summary is insufficient. */
|
|
68
|
+
body?: string;
|
|
69
|
+
/** Reviewed alternate phrasings or raw identifiers that resolve to exact and alias matches. */
|
|
70
|
+
aliases?: string[];
|
|
71
|
+
/** Extra search terms that aid recall but are not full aliases. */
|
|
72
|
+
keywords?: string[];
|
|
73
|
+
/** Ids of directly related entries, pulled in by bounded relationship expansion. */
|
|
74
|
+
relatedEntryIds?: string[];
|
|
75
|
+
/** Id of the parent entry when this is a subtype or child. */
|
|
76
|
+
parentEntryId?: string;
|
|
77
|
+
};
|
|
78
|
+
/**
|
|
79
|
+
* The complete, defaults-resolved record NeuroLink indexes and injects. Omitted
|
|
80
|
+
* optionals are materialized (arrays to `[]`, `body` to `""`, `kind` to "text",
|
|
81
|
+
* `status` to "active") so downstream code never re-checks the resolution chain.
|
|
82
|
+
* Field meanings mirror `KnowledgeEntryInput`.
|
|
83
|
+
*/
|
|
84
|
+
export type NormalizedKnowledgeEntry = {
|
|
85
|
+
id: string;
|
|
86
|
+
title: string;
|
|
87
|
+
summary: string;
|
|
88
|
+
domain: string;
|
|
89
|
+
integrations: string[];
|
|
90
|
+
kind: KnowledgeEntryKind;
|
|
91
|
+
status: KnowledgeStatus;
|
|
92
|
+
body: string;
|
|
93
|
+
aliases: string[];
|
|
94
|
+
keywords: string[];
|
|
95
|
+
relatedEntryIds: string[];
|
|
96
|
+
parentEntryId?: string;
|
|
97
|
+
/** Content version from the source/manifest; appears in citations as [KB:id@version]. */
|
|
98
|
+
version: string;
|
|
99
|
+
};
|
|
100
|
+
/** One catalog inside a build manifest — a source id and its entries. */
|
|
101
|
+
export type KnowledgeManifestCatalog = {
|
|
102
|
+
id: string;
|
|
103
|
+
entries: KnowledgeEntryInput[];
|
|
104
|
+
};
|
|
105
|
+
/**
|
|
106
|
+
* The versioned build artifact a host emits at build time. NeuroLink can
|
|
107
|
+
* consume it directly (each catalog becomes a structured source) so hosts do
|
|
108
|
+
* not need to construct `KnowledgeSource[]` by hand.
|
|
109
|
+
*/
|
|
110
|
+
export type KnowledgeManifest = {
|
|
111
|
+
schemaVersion: string;
|
|
112
|
+
contentVersion: string;
|
|
113
|
+
generatedAt: string;
|
|
114
|
+
catalogs: KnowledgeManifestCatalog[];
|
|
115
|
+
};
|
|
116
|
+
/**
|
|
117
|
+
* A configured knowledge source: inline structured entries passed to the
|
|
118
|
+
* engine. Markdown/provider source kinds were intentionally dropped for now;
|
|
119
|
+
* re-introduce this as a discriminated union (with a `type` tag) if another
|
|
120
|
+
* source kind is needed later.
|
|
121
|
+
*/
|
|
122
|
+
export type KnowledgeSource = {
|
|
123
|
+
id: string;
|
|
124
|
+
version?: string;
|
|
125
|
+
entries: KnowledgeEntryInput[];
|
|
126
|
+
};
|
|
127
|
+
/**
|
|
128
|
+
* Relative weight applied to a lexical match in each field. Title/alias
|
|
129
|
+
* matches outrank body matches. Tunable through evaluation.
|
|
130
|
+
*/
|
|
131
|
+
export type KnowledgeFieldWeights = {
|
|
132
|
+
title: number;
|
|
133
|
+
aliases: number;
|
|
134
|
+
keywords: number;
|
|
135
|
+
summary: number;
|
|
136
|
+
body: number;
|
|
137
|
+
};
|
|
138
|
+
/** Lexical retrieval tuning. All fields optional; the engine supplies defaults. */
|
|
139
|
+
export type KnowledgeRetrievalConfig = {
|
|
140
|
+
/** Retrieval mode. Default: "lexical". */
|
|
141
|
+
mode?: KnowledgeRetrievalMode;
|
|
142
|
+
/** How many scored candidates enter relationship expansion. Default: 24. */
|
|
143
|
+
candidateLimit?: number;
|
|
144
|
+
/** How many primary entries survive into the assembled context. Default: 8. */
|
|
145
|
+
resultLimit?: number;
|
|
146
|
+
/** Cap on relationship-expanded entries added after primary retrieval. Default: 4. */
|
|
147
|
+
relationLimit?: number;
|
|
148
|
+
/** Per-field BM25 weights. */
|
|
149
|
+
fieldWeights?: KnowledgeFieldWeights;
|
|
150
|
+
/** Additive boost for an exact entry-id / configuration-key match. Dominant. Default: 100. */
|
|
151
|
+
exactBoost?: number;
|
|
152
|
+
/** Additive boost for an exact reviewed-alias phrase match. Default: 60. */
|
|
153
|
+
aliasBoost?: number;
|
|
154
|
+
};
|
|
155
|
+
/** Ephemeral-context assembly limits. */
|
|
156
|
+
export type KnowledgeContextConfig = {
|
|
157
|
+
/** Hard token budget for the assembled grounding block. Default: 4000. */
|
|
158
|
+
maxTokens?: number;
|
|
159
|
+
/** Emit `[KB:<id>@<version>]` citations. Default: true. */
|
|
160
|
+
includeCitations?: boolean;
|
|
161
|
+
};
|
|
162
|
+
/**
|
|
163
|
+
* Constructor-level configuration for knowledge grounding. Sources are fixed
|
|
164
|
+
* for the lifetime of a NeuroLink instance so the index can be built once.
|
|
165
|
+
*/
|
|
166
|
+
export type KnowledgeGroundingConfig = {
|
|
167
|
+
/** Master switch. Grounding runs only when true AND at least one source is loaded. */
|
|
168
|
+
enabled: boolean;
|
|
169
|
+
/**
|
|
170
|
+
* Knowledge sources used to build the instance's immutable in-memory index.
|
|
171
|
+
* Required alongside `enabled`; pass an empty array only when intentionally
|
|
172
|
+
* configuring no retrievable content.
|
|
173
|
+
*/
|
|
174
|
+
sources: KnowledgeSource[];
|
|
175
|
+
/** Exclude these domains from retrieval. Empty/omitted means all domains are eligible. */
|
|
176
|
+
blockedDomains?: string[];
|
|
177
|
+
retrieval?: KnowledgeRetrievalConfig;
|
|
178
|
+
context?: KnowledgeContextConfig;
|
|
179
|
+
/** Hard ceiling for one grounding operation before it fails open. Default: 800ms. */
|
|
180
|
+
timeoutMs?: number;
|
|
181
|
+
};
|
|
182
|
+
/**
|
|
183
|
+
* Per-call scope the host attaches to `GenerateOptions` / `StreamOptions`.
|
|
184
|
+
* Supplies the enabled integrations for this turn only.
|
|
185
|
+
*/
|
|
186
|
+
export type KnowledgeRequestScope = {
|
|
187
|
+
/** Installed/enabled integrations used to filter integration-specific entries. */
|
|
188
|
+
enabledIntegrations?: string[];
|
|
189
|
+
};
|
|
190
|
+
/** One bounded recent conversation turn used to contextualize the query. */
|
|
191
|
+
export type KnowledgeConversationTurn = {
|
|
192
|
+
role: "user" | "assistant";
|
|
193
|
+
text: string;
|
|
194
|
+
};
|
|
195
|
+
/**
|
|
196
|
+
* The fully-resolved retrieval request the engine builds internally from the
|
|
197
|
+
* user query, a bounded recent window, and host scope.
|
|
198
|
+
*/
|
|
199
|
+
export type KnowledgeRetrievalRequest = {
|
|
200
|
+
query: string;
|
|
201
|
+
recentTurns: KnowledgeConversationTurn[];
|
|
202
|
+
enabledIntegrations: string[];
|
|
203
|
+
};
|
|
204
|
+
/**
|
|
205
|
+
* The internal search document built from a normalized entry. `exactKeys` and
|
|
206
|
+
* `fields` hold pre-tokenized normalized text. Internal to NeuroLink.
|
|
207
|
+
*/
|
|
208
|
+
export type IndexedKnowledgeDocument = {
|
|
209
|
+
id: string;
|
|
210
|
+
/** Normalized whole-phrase keys for exact/alias resolution. */
|
|
211
|
+
exactKeys: string[];
|
|
212
|
+
/** Per-field normalized token arrays fed to the field-aware BM25 scorer. */
|
|
213
|
+
fields: {
|
|
214
|
+
title: string[];
|
|
215
|
+
aliases: string[];
|
|
216
|
+
keywords: string[];
|
|
217
|
+
summary: string[];
|
|
218
|
+
body: string[];
|
|
219
|
+
};
|
|
220
|
+
};
|
|
221
|
+
/** One lexical match with its per-field score breakdown, for tuning and traces. */
|
|
222
|
+
export type KnowledgeLexicalMatch = {
|
|
223
|
+
id: string;
|
|
224
|
+
score: number;
|
|
225
|
+
fieldScores: Partial<Record<KnowledgeFieldName, number>>;
|
|
226
|
+
};
|
|
227
|
+
/**
|
|
228
|
+
* Structural contract of the field-aware lexical index held in a snapshot. A
|
|
229
|
+
* concrete class in the knowledge runtime module satisfies this shape; typing
|
|
230
|
+
* it structurally keeps this types file free of runtime imports.
|
|
231
|
+
*/
|
|
232
|
+
export type KnowledgeLexicalSearcher = {
|
|
233
|
+
search: (queryTokens: string[], topK: number, eligibleEntryIds?: ReadonlySet<string>) => KnowledgeLexicalMatch[];
|
|
234
|
+
};
|
|
235
|
+
/**
|
|
236
|
+
* Immutable, ready-to-query index built once at client construction. Sessions
|
|
237
|
+
* and turns search this snapshot; it is never mutated in place.
|
|
238
|
+
*/
|
|
239
|
+
export type KnowledgeIndexSnapshot = {
|
|
240
|
+
entriesById: Map<string, NormalizedKnowledgeEntry>;
|
|
241
|
+
/** Normalized entry id or title phrase -> entry ids. */
|
|
242
|
+
exactIndex: Map<string, Set<string>>;
|
|
243
|
+
/** Normalized reviewed alias phrase -> entry ids. */
|
|
244
|
+
aliasIndex: Map<string, Set<string>>;
|
|
245
|
+
/** Entry id -> directly related entry ids, for bounded expansion. */
|
|
246
|
+
relationIndex: Map<string, string[]>;
|
|
247
|
+
/** Field-aware BM25 over all documents. */
|
|
248
|
+
lexical: KnowledgeLexicalSearcher;
|
|
249
|
+
entryCount: number;
|
|
250
|
+
};
|
|
251
|
+
/** A stable citation to a specific knowledge entry version. */
|
|
252
|
+
export type KnowledgeCitation = {
|
|
253
|
+
id: string;
|
|
254
|
+
version: string;
|
|
255
|
+
};
|
|
256
|
+
/**
|
|
257
|
+
* The result of one retrieval: the selected entries, the assembled ephemeral
|
|
258
|
+
* context string, a confidence class, and assembly diagnostics.
|
|
259
|
+
*/
|
|
260
|
+
export type KnowledgeRetrievalResult = {
|
|
261
|
+
entries: NormalizedKnowledgeEntry[];
|
|
262
|
+
assembledContext: string;
|
|
263
|
+
confidence: KnowledgeRetrievalConfidence;
|
|
264
|
+
citations: KnowledgeCitation[];
|
|
265
|
+
/** Ids of the primary (non-expanded) entries, in final order. */
|
|
266
|
+
selectedEntryIds: string[];
|
|
267
|
+
/** Ids added by bounded relationship expansion. */
|
|
268
|
+
expandedEntryIds: string[];
|
|
269
|
+
/** Candidates scored before truncation to the result limit. */
|
|
270
|
+
candidateCount: number;
|
|
271
|
+
/** Estimated token size of `assembledContext`. */
|
|
272
|
+
contextTokens: number;
|
|
273
|
+
/** True when any entry body was truncated or entries were dropped for budget. */
|
|
274
|
+
truncated: boolean;
|
|
275
|
+
durationMs: number;
|
|
276
|
+
};
|
|
277
|
+
/**
|
|
278
|
+
* A block of context assembled for a single generation call without becoming
|
|
279
|
+
* durable conversation. The NeuroLink call boundary injects its content into
|
|
280
|
+
* the effective system prompt and never persists it as a user message.
|
|
281
|
+
*/
|
|
282
|
+
export type EphemeralContext = {
|
|
283
|
+
content: string;
|
|
284
|
+
kind: "knowledge";
|
|
285
|
+
/** Host-supplied reviewed content is trusted reference data. */
|
|
286
|
+
trusted: boolean;
|
|
287
|
+
citations?: KnowledgeCitation[];
|
|
288
|
+
metadata?: Record<string, unknown>;
|
|
289
|
+
};
|
|
290
|
+
/**
|
|
291
|
+
* Aggregate, content-free diagnostics attached to a generation/stream result
|
|
292
|
+
* so the host can evaluate retrieval without the SDK exposing entry bodies.
|
|
293
|
+
*/
|
|
294
|
+
export type KnowledgeGroundingMetadata = {
|
|
295
|
+
retrievalMode: KnowledgeRetrievalMode;
|
|
296
|
+
selectedIds: string[];
|
|
297
|
+
expandedIds: string[];
|
|
298
|
+
candidateCount: number;
|
|
299
|
+
contextTokens: number;
|
|
300
|
+
truncated: boolean;
|
|
301
|
+
durationMs: number;
|
|
302
|
+
confidence?: KnowledgeRetrievalConfidence;
|
|
303
|
+
/** Present when grounding failed open; names the failure class. */
|
|
304
|
+
failureReason?: string;
|
|
305
|
+
};
|
|
306
|
+
/** A single validation problem found while normalizing/indexing a source. */
|
|
307
|
+
export type KnowledgeValidationIssue = {
|
|
308
|
+
level: "error" | "warning";
|
|
309
|
+
code: string;
|
|
310
|
+
message: string;
|
|
311
|
+
entryId?: string;
|
|
312
|
+
sourceId?: string;
|
|
313
|
+
};
|
|
314
|
+
/** Outcome of validating a set of sources before indexing. */
|
|
315
|
+
export type KnowledgeValidationResult = {
|
|
316
|
+
ok: boolean;
|
|
317
|
+
issues: KnowledgeValidationIssue[];
|
|
318
|
+
};
|
|
319
|
+
/** Per-turn input to `KnowledgeGroundingEngine.ground()`. */
|
|
320
|
+
export type KnowledgeGroundingInput = {
|
|
321
|
+
query: string;
|
|
322
|
+
recentTurns?: KnowledgeConversationTurn[];
|
|
323
|
+
scope?: KnowledgeRequestScope;
|
|
324
|
+
};
|
|
325
|
+
/**
|
|
326
|
+
* The engine's per-turn output: the ephemeral context to inject (null on
|
|
327
|
+
* no-match, when disabled, or on fail-open), the aggregate metadata for the
|
|
328
|
+
* result, and the full retrieval for host diagnostics.
|
|
329
|
+
*/
|
|
330
|
+
export type KnowledgeGroundingOutcome = {
|
|
331
|
+
ephemeralContext: EphemeralContext | null;
|
|
332
|
+
metadata: KnowledgeGroundingMetadata;
|
|
333
|
+
retrieval: KnowledgeRetrievalResult | null;
|
|
334
|
+
};
|
|
335
|
+
/** Snapshot of engine health for telemetry and host introspection. */
|
|
336
|
+
export type KnowledgeEngineStatus = {
|
|
337
|
+
enabled: boolean;
|
|
338
|
+
ready: boolean;
|
|
339
|
+
entryCount: number;
|
|
340
|
+
lastError: string | null;
|
|
341
|
+
validationIssues: KnowledgeValidationIssue[];
|
|
342
|
+
};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Knowledge grounding — lexical-first host-supplied knowledge retrieval.
|
|
3
|
+
*
|
|
4
|
+
* A host application owns a structured *knowledge registry*: versioned entries
|
|
5
|
+
* describing concepts, configuration, taxonomies, procedures, and operating
|
|
6
|
+
* rules. NeuroLink owns the
|
|
7
|
+
* generic engine that ingests that registry, builds an in-memory lexical
|
|
8
|
+
* index once per instance, and — independently of tool routing — retrieves a
|
|
9
|
+
* small, token-bounded set of relevant entries before each main model call.
|
|
10
|
+
* The selected entries are attached as *ephemeral context*: visible to the
|
|
11
|
+
* current generation call, never persisted into conversation memory.
|
|
12
|
+
*
|
|
13
|
+
* This is retrieval-augmented generation WITHOUT vector retrieval. The first
|
|
14
|
+
* release ranks with exact identifiers, reviewed aliases, metadata filters,
|
|
15
|
+
* and weighted field-aware BM25 only. No embedding model, embedding service,
|
|
16
|
+
* or vector store is initialized. An LLM reranker and semantic retrieval are
|
|
17
|
+
* deferred behind an explicit evaluation gate.
|
|
18
|
+
*
|
|
19
|
+
* Ownership boundary: NeuroLink defines the contracts below and the engine;
|
|
20
|
+
* it never contains host product content. The host supplies content and
|
|
21
|
+
* per-request scope. The engine stays provider-neutral.
|
|
22
|
+
*
|
|
23
|
+
* Type names are globally prefixed `Knowledge*` to satisfy the repo's
|
|
24
|
+
* unique-type-name rule and to avoid collision with the pre-existing
|
|
25
|
+
* web-search `grounding.ts` vocabulary (`EnhancedGroundingMetadata` et al.),
|
|
26
|
+
* which is a different concept (Google search grounding, not product
|
|
27
|
+
* knowledge).
|
|
28
|
+
*/
|
|
29
|
+
export {};
|
package/dist/types/stream.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { AIProviderName } from "../constants/enums.js";
|
|
2
2
|
import type { EvaluationData } from "./evaluation.js";
|
|
3
3
|
import type { RAGConfig } from "./rag.js";
|
|
4
|
+
import type { KnowledgeGroundingMetadata, KnowledgeRequestScope } from "./knowledge.js";
|
|
4
5
|
import type { SkillsCallOptions } from "./skills.js";
|
|
5
6
|
import type { AnalyticsData, ToolExecutionEvent, ToolExecutionSummary } from "../types/index.js";
|
|
6
7
|
import type { MiddlewareFactoryOptions, OnChunkCallback, OnErrorCallback, OnFinishCallback } from "../types/middleware.js";
|
|
@@ -169,6 +170,17 @@ export type StreamChunk = {
|
|
|
169
170
|
audio: TTSChunk;
|
|
170
171
|
};
|
|
171
172
|
export type StreamOptions = {
|
|
173
|
+
/**
|
|
174
|
+
* Opt this stream call into the knowledge grounding configured on the
|
|
175
|
+
* NeuroLink instance. Defaults to `false` when omitted.
|
|
176
|
+
*/
|
|
177
|
+
useKnowledgeGrounding?: boolean;
|
|
178
|
+
/**
|
|
179
|
+
* Enabled integrations used to scope knowledge retrieval for this turn.
|
|
180
|
+
* Used only when `useKnowledgeGrounding` is true and knowledge grounding is
|
|
181
|
+
* enabled on the NeuroLink instance.
|
|
182
|
+
*/
|
|
183
|
+
knowledgeContext?: KnowledgeRequestScope;
|
|
172
184
|
input: {
|
|
173
185
|
/** Prompt text. Optional for media-only modes (avatar, music) that are driven by uploaded files rather than a prompt. */
|
|
174
186
|
text?: string;
|
|
@@ -552,6 +564,8 @@ export type StreamOptions = {
|
|
|
552
564
|
* Future-ready for multi-modal outputs while maintaining text focus
|
|
553
565
|
*/
|
|
554
566
|
export type StreamResult = {
|
|
567
|
+
/** Knowledge-grounding diagnostics for this turn (present only when grounding ran). */
|
|
568
|
+
knowledge?: KnowledgeGroundingMetadata;
|
|
555
569
|
stream: AsyncIterable<{
|
|
556
570
|
content: string;
|
|
557
571
|
reasoning?: string;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@juspay/neurolink",
|
|
3
|
-
"version": "10.
|
|
3
|
+
"version": "10.4.0",
|
|
4
4
|
"packageManager": "pnpm@10.15.1",
|
|
5
5
|
"description": "TypeScript AI SDK with 24+ LLM providers behind one consistent API. MCP-native (connect any MCP server), voice TTS/STT/realtime, RAG, agents, memory, context compaction. OpenAI · Anthropic · Gemini · Bedrock · Azure · Ollama · DeepSeek · NVIDIA NIM and more.",
|
|
6
6
|
"author": {
|
|
@@ -384,6 +384,7 @@
|
|
|
384
384
|
"p-limit": "^7.3.0",
|
|
385
385
|
"redis": "^5.11.0",
|
|
386
386
|
"tar-stream": "^3.1.8",
|
|
387
|
+
"type-decoder": "^2.3.1",
|
|
387
388
|
"undici": ">=7.24.0 <8.0.0",
|
|
388
389
|
"ws": "^8.20.1",
|
|
389
390
|
"yargs": "^18.0.0",
|