@devilsdev/rag-pipeline-utils 2.4.4 → 2.5.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/.ragrc.schema.json +83 -192
- package/CHANGELOG.md +345 -0
- package/README.md +418 -117
- package/SECURITY.md +5 -5
- package/dist/experimental.cjs +2 -0
- package/dist/experimental.d.ts +1 -0
- package/dist/experimental.mjs +5 -0
- package/dist/index.cjs +4992 -1242
- package/dist/index.d.ts +80 -2
- package/dist/index.mjs +1 -1
- package/dist/types/agentic/agentic-pipeline.d.ts +103 -0
- package/dist/types/agentic/iterative-retriever.d.ts +85 -0
- package/dist/types/agentic/query-planner.d.ts +145 -0
- package/dist/types/agentic/self-critique.d.ts +45 -0
- package/dist/types/ai/adaptive-retrieval.d.ts +44 -0
- package/dist/types/ai/federation/federated-learning-coordinator.d.ts +62 -0
- package/dist/types/ai/multimodal-processing.d.ts +32 -0
- package/dist/types/ai/multimodal.d.ts +39 -0
- package/dist/types/ai/retrieval-engine.d.ts +37 -0
- package/dist/types/ai/training/model-training-orchestrator.d.ts +31 -0
- package/dist/types/chunking/chunking-engine.d.ts +70 -0
- package/dist/types/chunking/strategies/fixed-size.d.ts +17 -0
- package/dist/types/chunking/strategies/recursive.d.ts +20 -0
- package/dist/types/chunking/strategies/semantic.d.ts +19 -0
- package/dist/types/chunking/strategies/sentence.d.ts +13 -0
- package/dist/types/chunking/strategies/structure-aware.d.ts +19 -0
- package/dist/types/citation/citation-tracker.d.ts +64 -0
- package/dist/types/citation/hallucination-detector.d.ts +40 -0
- package/dist/types/citation/source-mapper.d.ts +37 -0
- package/dist/types/connectors/anthropic-connector.d.ts +92 -0
- package/dist/types/connectors/base-connector.d.ts +87 -0
- package/dist/types/connectors/cohere-connector.d.ts +89 -0
- package/dist/types/connectors/connector-utils.d.ts +110 -0
- package/dist/types/connectors/local-embedder.d.ts +86 -0
- package/dist/types/connectors/memory-retriever.d.ts +91 -0
- package/dist/types/connectors/ollama-connector.d.ts +110 -0
- package/dist/types/connectors/openai-connector.d.ts +114 -0
- package/dist/types/connectors/rag-prompt.d.ts +40 -0
- package/dist/types/cost/cost-calculator.d.ts +152 -0
- package/dist/types/cost/cost-tracker.d.ts +126 -0
- package/dist/types/cost/token-budget.d.ts +110 -0
- package/dist/types/dag/core/error-context.d.ts +239 -0
- package/dist/types/dag/core/execution-scheduler.d.ts +191 -0
- package/dist/types/dag/core/topology-validation.d.ts +226 -0
- package/dist/types/dag/dag-engine.d.ts +156 -0
- package/dist/types/dag/dag-node.d.ts +37 -0
- package/dist/types/dashboard/dashboard-generator.d.ts +127 -0
- package/dist/types/dashboard/metrics-aggregator.d.ts +218 -0
- package/dist/types/debug/execution-tracer.d.ts +57 -0
- package/dist/types/debug/trace-inspector.d.ts +31 -0
- package/dist/types/ecosystem/plugin-certification.d.ts +169 -0
- package/dist/types/enterprise/data-governance.d.ts +203 -0
- package/dist/types/enterprise/multi-tenancy.d.ts +137 -0
- package/dist/types/enterprise/sso-integration.d.ts +420 -0
- package/dist/types/evaluate/context-metrics.d.ts +55 -0
- package/dist/types/evaluate/faithfulness.d.ts +41 -0
- package/dist/types/evaluate/groundedness.d.ts +60 -0
- package/dist/types/evaluate/pipeline-evaluator.d.ts +88 -0
- package/dist/types/evaluate/relevance.d.ts +21 -0
- package/dist/types/evaluate/scoring.d.ts +123 -0
- package/dist/types/experimental.d.ts +15 -0
- package/dist/types/graph/entity-extractor.d.ts +84 -0
- package/dist/types/graph/graph-index.d.ts +49 -0
- package/dist/types/graph/graph-retriever.d.ts +81 -0
- package/dist/types/graph/knowledge-graph.d.ts +129 -0
- package/dist/types/guardrails/guardrails-pipeline.d.ts +63 -0
- package/dist/types/guardrails/injection-detector.d.ts +47 -0
- package/dist/types/guardrails/post-generation-guard.d.ts +61 -0
- package/dist/types/guardrails/pre-retrieval-guard.d.ts +64 -0
- package/dist/types/guardrails/retrieval-guard.d.ts +57 -0
- package/dist/types/mcp/mcp-server.d.ts +85 -0
- package/dist/types/mcp/mcp-tool-builder.d.ts +55 -0
- package/dist/types/reranker/cascade-reranker.d.ts +40 -0
- package/dist/types/reranker/embedding-reranker.d.ts +77 -0
- package/dist/types/reranker/scoring-reranker.d.ts +41 -0
- package/dist/types/retrieval/bm25-search.d.ts +43 -0
- package/dist/types/retrieval/file-vector-store.d.ts +87 -0
- package/dist/types/retrieval/hybrid-retriever.d.ts +35 -0
- package/dist/types/retrieval/rank-fusion.d.ts +10 -0
- package/dist/types/security/jwt-config.d.ts +80 -0
- package/dist/types/security/jwt-validator.d.ts +195 -0
- package/dist/types/security/plugin-sandbox.d.ts +158 -0
- package/dist/types/security/plugin-signature-verifier.d.ts +139 -0
- package/dist/types/security/validator.d.ts +5 -0
- package/dist/types/streaming/embedding-stream.d.ts +65 -0
- package/dist/types/streaming/sse-adapter.d.ts +59 -0
- package/dist/types/streaming/stream-router.d.ts +88 -0
- package/dist/types/streaming/streaming-embedder.d.ts +99 -0
- package/dist/types/streaming/websocket-adapter.d.ts +71 -0
- package/dist/types/templates/scaffold.d.ts +55 -0
- package/dist/types/templates/template-registry.d.ts +63 -0
- package/dist/types/utils/embed-query.d.ts +20 -0
- package/dist/types/utils/logger.d.ts +50 -0
- package/dist/types/utils/rate-limiter.d.ts +66 -0
- package/dist/types/utils/retry.d.ts +27 -0
- package/dist/types/utils/run-abort.d.ts +34 -0
- package/dist/types/utils/secure-logging.d.ts +51 -0
- package/dist/types/utils/structured-logger.d.ts +126 -0
- package/package.json +53 -29
- package/src/agentic/agentic-pipeline.js +75 -7
- package/src/agentic/iterative-retriever.js +47 -10
- package/src/agentic/query-planner.js +329 -78
- package/src/citation/citation-tracker.js +6 -4
- package/src/citation/hallucination-detector.js +2 -2
- package/src/citation/source-mapper.js +15 -28
- package/src/cli/commands/ai.js +101 -0
- package/src/cli/commands/plugin-hub/event-handlers.js +6 -0
- package/src/cli/commands/plugin-hub/hub-commands.js +0 -74
- package/src/cli/commands/plugin-hub/local-commands.js +143 -0
- package/src/cli/commands/plugin-hub.js +96 -36
- package/src/cli/diagnostics/config-checker.js +76 -63
- package/src/cli/diagnostics/environment-checker.js +62 -31
- package/src/cli/diagnostics/plugin-checker.js +36 -89
- package/src/cli/doctor-command.js +39 -5
- package/src/cli/enhanced-cli-commands.js +72 -217
- package/src/cli/handlers/ai-handler.js +364 -0
- package/src/cli/handlers/diagnostics-handler.js +78 -31
- package/src/cli/handlers/ingest-handler.js +28 -22
- package/src/cli/handlers/init-handler.js +148 -25
- package/src/cli/handlers/query-handler.js +41 -26
- package/src/cli/handlers/run-handler.js +16 -167
- package/src/cli/handlers/serve-handler.js +60 -0
- package/src/cli/services/bench-stats.js +54 -0
- package/src/cli/services/benchmark.js +161 -0
- package/src/cli/services/feedback.js +155 -0
- package/src/cli/services/rag-service.js +322 -0
- package/src/cli/shared/cli-utils.js +24 -7
- package/src/cli/shared/config-context.js +21 -0
- package/src/cli/wizard/config-builder.js +81 -0
- package/src/cli/wizard/init-wizard.js +617 -0
- package/src/config/component-factory.js +125 -0
- package/src/config/load-config.js +29 -10
- package/src/config/load-plugin-config.js +46 -2
- package/src/connectors/anthropic-connector.js +93 -55
- package/src/connectors/base-connector.js +74 -19
- package/src/connectors/cohere-connector.js +88 -32
- package/src/connectors/connector-utils.js +302 -0
- package/src/connectors/local-embedder.js +43 -5
- package/src/connectors/memory-retriever.js +108 -15
- package/src/connectors/ollama-connector.js +83 -49
- package/src/connectors/openai-connector.js +108 -44
- package/src/connectors/rag-prompt.js +88 -0
- package/src/core/create-pipeline.js +209 -60
- package/src/core/plugin-registry.js +87 -11
- package/src/cost/cost-calculator.js +205 -32
- package/src/dev/dev-server.js +166 -11
- package/src/dev/hot-reload.js +40 -1
- package/src/ecosystem/plugin-checks.js +181 -0
- package/src/ecosystem/plugin-hub.js +50 -125
- package/src/ecosystem/plugin-installer.js +298 -0
- package/src/ecosystem/plugin-probe.js +127 -0
- package/src/ecosystem/plugin-scanner.js +185 -0
- package/src/ecosystem/tar-extract.js +114 -0
- package/src/enterprise/audit-logging.js +158 -29
- package/src/enterprise/sso-integration.js +715 -228
- package/src/evaluate/context-metrics.js +28 -16
- package/src/evaluate/evaluator.js +3 -3
- package/src/evaluate/faithfulness.js +18 -14
- package/src/evaluate/groundedness.js +43 -12
- package/src/evaluate/pipeline-evaluator.js +35 -8
- package/src/evaluate/scoring.js +251 -3
- package/src/experimental.js +71 -0
- package/src/guardrails/guardrails-pipeline.js +69 -7
- package/src/guardrails/injection-detector.js +283 -0
- package/src/guardrails/post-generation-guard.js +19 -0
- package/src/guardrails/pre-retrieval-guard.js +36 -36
- package/src/guardrails/retrieval-guard.js +58 -8
- package/src/index.js +36 -1
- package/src/loader/document-reader.js +91 -0
- package/src/reranker/cascade-reranker.js +3 -0
- package/src/reranker/embedding-reranker.js +136 -21
- package/src/reranker/llm-reranker.js +79 -12
- package/src/reranker/scoring-reranker.js +3 -0
- package/src/retrieval/bm25-search.js +12 -6
- package/src/retrieval/file-vector-store.js +212 -0
- package/src/retrieval/hybrid-retriever.js +22 -19
- package/src/security/jwt-config.js +13 -2
- package/src/security/jwt-validator.js +134 -30
- package/src/security/plugin-sandbox.js +18 -1
- package/src/security/plugin-signature-verifier.js +245 -70
- package/src/utils/deprecate.js +69 -0
- package/src/utils/embed-query.js +33 -0
- package/src/utils/input-sanitizer.js +19 -4
- package/src/utils/logger.js +34 -4
- package/src/utils/run-abort.js +102 -0
- package/src/ai/federated-learning.js +0 -211
- package/src/ai/federation.js +0 -71
- package/src/ai/index.js +0 -22
- package/src/ai/model-trainer.js +0 -217
- package/src/ai/model-training.js +0 -202
- package/src/ai/multimodal/multi-modal-processor.js +0 -345
- package/src/ai/orchestrator.js +0 -65
- package/src/ai/retrieval/adaptive-retrieval-engine.js +0 -398
- package/src/cli/commands/ai-ml/adaptive-commands.js +0 -178
- package/src/cli/commands/ai-ml/federated-commands.js +0 -207
- package/src/cli/commands/ai-ml/index.js +0 -17
- package/src/cli/commands/ai-ml/multimodal-commands.js +0 -187
- package/src/cli/commands/ai-ml/shared.js +0 -51
- package/src/cli/commands/ai-ml/training-commands.js +0 -228
- package/src/cli/commands/ai-ml.js +0 -386
- package/src/cli/commands/docs.js +0 -228
- package/src/cli/commands/dx.js +0 -538
- package/src/cli/commands/wizard.js +0 -627
- package/src/cli/input-sanitization-middleware.js +0 -356
- package/src/cli/interactive-wizard.js +0 -373
- package/src/cli/templates/development.template.json +0 -64
- package/src/cli/templates/minimal.template.json +0 -33
- package/src/cli/templates/production.template.json +0 -104
- package/src/cli/templates/testing.template.json +0 -45
- package/src/cli/wizard/configuration.js +0 -148
- package/src/cli/wizard/observability.js +0 -79
- package/src/cli/wizard/performance.js +0 -76
- package/src/cli/wizard/plugin-selection.js +0 -297
- package/src/cli/wizard/preview-save.js +0 -172
- package/src/cli/wizard/project-setup.js +0 -66
- package/src/core/pipeline-factory.js +0 -59
- package/src/dag/enhanced-dag-engine.js +0 -894
- package/src/dx/index.js +0 -40
- package/src/dx/integration-templates.js +0 -662
- package/src/dx/performance-profiler.js +0 -968
- package/src/dx/realtime-debugger.js +0 -755
- package/src/dx/visual-pipeline-builder.js +0 -578
- package/src/ingest.js +0 -59
- package/src/pipeline/pipeline.js +0 -18
- package/src/query.js +0 -117
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Common English function words. Ignored when measuring how much of a
|
|
3
|
+
* sentence a document supports, so "the" and "is" cannot ground a claim.
|
|
4
|
+
*/
|
|
5
|
+
export const STOPWORDS: Set<string>;
|
|
6
|
+
/**
|
|
7
|
+
* Content tokens of a sentence: tokens minus stopwords. Falls back to all
|
|
8
|
+
* tokens when nothing is left (e.g. "Yes."), so short sentences are still
|
|
9
|
+
* scored rather than skipped.
|
|
10
|
+
*
|
|
11
|
+
* @param {string[]} tokens
|
|
12
|
+
* @returns {string[]}
|
|
13
|
+
*/
|
|
14
|
+
export function contentTokens(tokens: string[]): string[];
|
|
15
|
+
/**
|
|
16
|
+
* How much of a claim is supported by a document: the (optionally
|
|
17
|
+
* IDF-weighted) fraction of the claim's unique content tokens that appear in
|
|
18
|
+
* the document. Unlike Jaccard against the whole document, this does not
|
|
19
|
+
* shrink as the document gets longer, so a sentence copied verbatim from a
|
|
20
|
+
* long chunk scores 1.
|
|
21
|
+
*
|
|
22
|
+
* Numeric consistency: when `options.claimText` and `options.docText` are
|
|
23
|
+
* given and the claim states a number the document does not contain (see
|
|
24
|
+
* checkNumericConsistency), the score becomes
|
|
25
|
+
* lexicalScore * NUMERIC_MISMATCH_FACTOR (0.4) * matchedNumbers / claimNumbers
|
|
26
|
+
* which is always below 0.4, so the claim fails the default 0.5 threshold.
|
|
27
|
+
*
|
|
28
|
+
* @param {string[]} claimTokens - Tokens of the sentence/claim/query
|
|
29
|
+
* @param {string[]|Set<string>} docTokens - Tokens of the document
|
|
30
|
+
* @param {Map<string, number>|null} [idfWeights] - Optional token weights
|
|
31
|
+
* @param {{ claimText?: string, docText?: string }} [options] - Raw texts
|
|
32
|
+
* enabling the numeric consistency check
|
|
33
|
+
* @returns {number} Support score between 0 and 1
|
|
34
|
+
*/
|
|
35
|
+
export function computeSupportScore(claimTokens: string[], docTokens: string[] | Set<string>, idfWeights?: Map<string, number> | null, options?: {
|
|
36
|
+
claimText?: string;
|
|
37
|
+
docText?: string;
|
|
38
|
+
}): number;
|
|
39
|
+
/**
|
|
40
|
+
* Numeric consistency between a claim and a document: every number the claim
|
|
41
|
+
* states (digits, decimals, percentages or number words) must also appear in
|
|
42
|
+
* the document. Lexical overlap alone would ground "thirty days" against a
|
|
43
|
+
* source that says "twenty days".
|
|
44
|
+
*
|
|
45
|
+
* @param {string} claimText
|
|
46
|
+
* @param {string} docText
|
|
47
|
+
* @returns {{ consistent: boolean, claimNumbers: string[], missing: string[] }}
|
|
48
|
+
*/
|
|
49
|
+
export function checkNumericConsistency(claimText: string, docText: string): {
|
|
50
|
+
consistent: boolean;
|
|
51
|
+
claimNumbers: string[];
|
|
52
|
+
missing: string[];
|
|
53
|
+
};
|
|
54
|
+
/**
|
|
55
|
+
* Extract the numbers stated in a text, as normalised value strings, so
|
|
56
|
+
* "20", "20%", "twenty" and "Twenty" all yield "20", "1,000" yields "1000"
|
|
57
|
+
* and "2.5" yields "2.5".
|
|
58
|
+
*
|
|
59
|
+
* @param {string} text
|
|
60
|
+
* @returns {{ values: string[], parts: string[] }} values: one entry per
|
|
61
|
+
* number as written; parts: values plus each number word on its own
|
|
62
|
+
* (used on the document side so "twenty-five" also supports "20" and "5"
|
|
63
|
+
* is not required)
|
|
64
|
+
*/
|
|
65
|
+
export function extractNumbers(text: string): {
|
|
66
|
+
values: string[];
|
|
67
|
+
parts: string[];
|
|
68
|
+
};
|
|
69
|
+
/**
|
|
70
|
+
* Multiplier applied to the support score when a claim states numbers the
|
|
71
|
+
* document does not contain. Together with the share of matching numbers it
|
|
72
|
+
* keeps the score below 0.4, i.e. under the default 0.5 support threshold.
|
|
73
|
+
*/
|
|
74
|
+
export const NUMERIC_MISMATCH_FACTOR: 0.4;
|
|
75
|
+
/**
|
|
76
|
+
* Score a prompt-answer pair using multiple metrics
|
|
77
|
+
* @param {string} actual - LLM response
|
|
78
|
+
* @param {string} expected - Reference answer
|
|
79
|
+
* @returns {{ bleu: number, rouge: number }}
|
|
80
|
+
*/
|
|
81
|
+
export function scoreAnswer(_actual: any, _expected: any): {
|
|
82
|
+
bleu: number;
|
|
83
|
+
rouge: number;
|
|
84
|
+
};
|
|
85
|
+
/**
|
|
86
|
+
* Version: 0.1.0
|
|
87
|
+
* Path: /src/evaluate/scoring.js
|
|
88
|
+
* Description: Basic scoring metrics (BLEU, ROUGE-L) for RAG output evaluation
|
|
89
|
+
* Author: Ali Kahwaji
|
|
90
|
+
*/
|
|
91
|
+
/**
|
|
92
|
+
* Tokenize a string by words
|
|
93
|
+
* @param {string} text
|
|
94
|
+
* @returns {string[]}
|
|
95
|
+
*/
|
|
96
|
+
export function tokenize(text: string): string[];
|
|
97
|
+
/**
|
|
98
|
+
* Compute BLEU-1 score: unigram precision
|
|
99
|
+
* @param {string[]} candidate - Generated tokens
|
|
100
|
+
* @param {string[]} reference - Reference tokens
|
|
101
|
+
* @returns {number}
|
|
102
|
+
*/
|
|
103
|
+
export function computeBLEU(_candidate: any, _reference: any): number;
|
|
104
|
+
/**
|
|
105
|
+
* Compute ROUGE-L (Longest Common Subsequence) recall
|
|
106
|
+
* @param {string[]} candidate
|
|
107
|
+
* @param {string[]} reference
|
|
108
|
+
* @returns {number}
|
|
109
|
+
*/
|
|
110
|
+
export function computeROUGE(_candidate: any, _reference: any): number;
|
|
111
|
+
/**
|
|
112
|
+
* Split text into sentences on sentence-ending punctuation
|
|
113
|
+
* @param {string} text
|
|
114
|
+
* @returns {string[]}
|
|
115
|
+
*/
|
|
116
|
+
export function splitSentences(text: string): string[];
|
|
117
|
+
/**
|
|
118
|
+
* Compute Jaccard similarity between two token arrays
|
|
119
|
+
* @param {string[]} tokensA
|
|
120
|
+
* @param {string[]} tokensB
|
|
121
|
+
* @returns {number} Similarity score between 0 and 1
|
|
122
|
+
*/
|
|
123
|
+
export function computeJaccardSimilarity(tokensA: string[], tokensB: string[]): number;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { MultiModalProcessor } from "./ai/multimodal";
|
|
2
|
+
import { AdaptiveRetrievalEngine } from "./ai/retrieval-engine";
|
|
3
|
+
import { FederatedLearningCoordinator } from "./ai/federation/federated-learning-coordinator";
|
|
4
|
+
import { ModelTrainingOrchestrator } from "./ai/training/model-training-orchestrator";
|
|
5
|
+
import { DataGovernanceManager } from "./enterprise/data-governance";
|
|
6
|
+
import { TenantManager } from "./enterprise/multi-tenancy";
|
|
7
|
+
import { ResourceMonitor } from "./enterprise/multi-tenancy";
|
|
8
|
+
import { SSOManager } from "./enterprise/sso-integration";
|
|
9
|
+
import { SAMLProvider } from "./enterprise/sso-integration";
|
|
10
|
+
import { OAuth2Provider } from "./enterprise/sso-integration";
|
|
11
|
+
import { ActiveDirectoryProvider } from "./enterprise/sso-integration";
|
|
12
|
+
import { OIDCProvider } from "./enterprise/sso-integration";
|
|
13
|
+
import { PluginSandbox } from "./security/plugin-sandbox";
|
|
14
|
+
import { PluginCertification } from "./ecosystem/plugin-certification";
|
|
15
|
+
export { MultiModalProcessor, AdaptiveRetrievalEngine, FederatedLearningCoordinator, ModelTrainingOrchestrator, DataGovernanceManager, DataGovernanceManager as DataGovernance, TenantManager, ResourceMonitor, SSOManager, SAMLProvider, OAuth2Provider, ActiveDirectoryProvider, OIDCProvider, PluginSandbox, PluginCertification };
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Heuristic entity extraction from text — no LLM required.
|
|
3
|
+
*
|
|
4
|
+
* Uses configurable regex patterns to identify named entities,
|
|
5
|
+
* dates, measurements, URLs, emails, and technical terms.
|
|
6
|
+
*/
|
|
7
|
+
export class EntityExtractor extends EventEmitter<[never]> {
|
|
8
|
+
/**
|
|
9
|
+
* @param {Object} [options={}] - Extractor options
|
|
10
|
+
* @param {Object<string, RegExp>} [options.patterns] - Custom patterns to merge with defaults
|
|
11
|
+
*/
|
|
12
|
+
constructor(options?: {
|
|
13
|
+
patterns?: {
|
|
14
|
+
[x: string]: RegExp;
|
|
15
|
+
};
|
|
16
|
+
});
|
|
17
|
+
patterns: {
|
|
18
|
+
[x: string]: RegExp;
|
|
19
|
+
};
|
|
20
|
+
config: {
|
|
21
|
+
patterns?: {
|
|
22
|
+
[x: string]: RegExp;
|
|
23
|
+
};
|
|
24
|
+
};
|
|
25
|
+
/**
|
|
26
|
+
* Extract entities from a single text string.
|
|
27
|
+
*
|
|
28
|
+
* For each configured pattern type, finds all matches, deduplicates
|
|
29
|
+
* by normalized name, and returns an array of entity descriptors.
|
|
30
|
+
*
|
|
31
|
+
* @param {string} text - Input text to extract entities from
|
|
32
|
+
* @returns {Array<{name: string, type: string, positions: Array<{start: number, end: number}>, frequency: number}>}
|
|
33
|
+
*/
|
|
34
|
+
extract(text: string): Array<{
|
|
35
|
+
name: string;
|
|
36
|
+
type: string;
|
|
37
|
+
positions: Array<{
|
|
38
|
+
start: number;
|
|
39
|
+
end: number;
|
|
40
|
+
}>;
|
|
41
|
+
frequency: number;
|
|
42
|
+
}>;
|
|
43
|
+
/**
|
|
44
|
+
* Extract relationships between entities that co-occur in the same sentence.
|
|
45
|
+
*
|
|
46
|
+
* @param {string} text - Input text
|
|
47
|
+
* @param {Array<{name: string, type: string}>} entities - Previously extracted entities
|
|
48
|
+
* @returns {Array<{from: string, to: string, type: string, context: string}>}
|
|
49
|
+
*/
|
|
50
|
+
extractRelationships(text: string, entities: Array<{
|
|
51
|
+
name: string;
|
|
52
|
+
type: string;
|
|
53
|
+
}>): Array<{
|
|
54
|
+
from: string;
|
|
55
|
+
to: string;
|
|
56
|
+
type: string;
|
|
57
|
+
context: string;
|
|
58
|
+
}>;
|
|
59
|
+
/**
|
|
60
|
+
* Extract entities and relationships from multiple documents.
|
|
61
|
+
*
|
|
62
|
+
* Combines entities across documents and tracks which source
|
|
63
|
+
* document(s) each entity originates from.
|
|
64
|
+
*
|
|
65
|
+
* @param {Array<{id: string, content: string, metadata?: Object}>} documents
|
|
66
|
+
* @returns {{entities: Array, relationships: Array}}
|
|
67
|
+
*/
|
|
68
|
+
extractFromDocuments(documents: Array<{
|
|
69
|
+
id: string;
|
|
70
|
+
content: string;
|
|
71
|
+
metadata?: any;
|
|
72
|
+
}>): {
|
|
73
|
+
entities: any[];
|
|
74
|
+
relationships: any[];
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Default regex patterns for heuristic entity extraction.
|
|
79
|
+
* @type {Object<string, RegExp>}
|
|
80
|
+
*/
|
|
81
|
+
export const DEFAULT_PATTERNS: {
|
|
82
|
+
[x: string]: RegExp;
|
|
83
|
+
};
|
|
84
|
+
import { EventEmitter } from "events";
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Fast entity lookup index for the knowledge graph.
|
|
3
|
+
*
|
|
4
|
+
* Maintains secondary indexes by type, name, and arbitrary properties
|
|
5
|
+
* for efficient querying without full graph traversal.
|
|
6
|
+
*/
|
|
7
|
+
export class GraphIndex {
|
|
8
|
+
/** @type {Map<string, Set<string>>} type -> Set of entity IDs */
|
|
9
|
+
byType: Map<string, Set<string>>;
|
|
10
|
+
/** @type {Map<string, string>} normalized name -> entity ID */
|
|
11
|
+
byName: Map<string, string>;
|
|
12
|
+
/** @type {Map<string, Map<*, Set<string>>>} propertyKey -> Map of value -> Set of entity IDs */
|
|
13
|
+
byProperty: Map<string, Map<any, Set<string>>>;
|
|
14
|
+
/**
|
|
15
|
+
* Index an entity by type, name, and each of its properties.
|
|
16
|
+
* @param {{id: string, type: string, properties: Object}} entity
|
|
17
|
+
*/
|
|
18
|
+
indexEntity(entity: {
|
|
19
|
+
id: string;
|
|
20
|
+
type: string;
|
|
21
|
+
properties: any;
|
|
22
|
+
}): void;
|
|
23
|
+
/**
|
|
24
|
+
* Fuzzy search for entities whose name contains the query (case-insensitive).
|
|
25
|
+
*
|
|
26
|
+
* Results are sorted by relevance: exact matches first, then partial matches.
|
|
27
|
+
*
|
|
28
|
+
* @param {string} query - Search query
|
|
29
|
+
* @returns {string[]} Array of matching entity IDs
|
|
30
|
+
*/
|
|
31
|
+
searchByName(query: string): string[];
|
|
32
|
+
/**
|
|
33
|
+
* Return all entity IDs of a given type.
|
|
34
|
+
* @param {string} type - Entity type
|
|
35
|
+
* @returns {string[]} Array of entity IDs
|
|
36
|
+
*/
|
|
37
|
+
searchByType(type: string): string[];
|
|
38
|
+
/**
|
|
39
|
+
* Return entity IDs matching a property key-value pair.
|
|
40
|
+
* @param {string} key - Property key
|
|
41
|
+
* @param {*} value - Property value
|
|
42
|
+
* @returns {string[]} Array of entity IDs
|
|
43
|
+
*/
|
|
44
|
+
searchByProperty(key: string, value: any): string[];
|
|
45
|
+
/**
|
|
46
|
+
* Clear all indexes.
|
|
47
|
+
*/
|
|
48
|
+
clear(): void;
|
|
49
|
+
}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Retriever that uses a knowledge graph for document retrieval.
|
|
3
|
+
*
|
|
4
|
+
* Combines entity-based graph traversal with token-overlap text scoring
|
|
5
|
+
* to rank and retrieve relevant documents from a corpus.
|
|
6
|
+
*/
|
|
7
|
+
export class GraphRetriever extends EventEmitter<[never]> {
|
|
8
|
+
/**
|
|
9
|
+
* @param {Object} [options={}] - Retriever options
|
|
10
|
+
* @param {number} [options.traversalDepth=2] - Graph traversal depth
|
|
11
|
+
* @param {number} [options.maxResults=10] - Maximum results to return
|
|
12
|
+
* @param {number} [options.entityWeight=0.6] - Weight for entity-graph score
|
|
13
|
+
* @param {number} [options.textWeight=0.4] - Weight for text-overlap score
|
|
14
|
+
* @param {Object} [options.extractorOptions] - Options for the EntityExtractor
|
|
15
|
+
*/
|
|
16
|
+
constructor(options?: {
|
|
17
|
+
traversalDepth?: number;
|
|
18
|
+
maxResults?: number;
|
|
19
|
+
entityWeight?: number;
|
|
20
|
+
textWeight?: number;
|
|
21
|
+
extractorOptions?: any;
|
|
22
|
+
});
|
|
23
|
+
config: any;
|
|
24
|
+
graph: KnowledgeGraph;
|
|
25
|
+
extractor: EntityExtractor;
|
|
26
|
+
index: GraphIndex;
|
|
27
|
+
/** @type {Map<string, {id: string, content: string, metadata: Object}>} */
|
|
28
|
+
documents: Map<string, {
|
|
29
|
+
id: string;
|
|
30
|
+
content: string;
|
|
31
|
+
metadata: any;
|
|
32
|
+
}>;
|
|
33
|
+
/**
|
|
34
|
+
* Store documents, extract entities and relationships, and build the graph.
|
|
35
|
+
*
|
|
36
|
+
* @param {Array<{id: string, content: string, metadata?: Object}>} documents
|
|
37
|
+
* @returns {Promise<void>}
|
|
38
|
+
*/
|
|
39
|
+
store(documents: Array<{
|
|
40
|
+
id: string;
|
|
41
|
+
content: string;
|
|
42
|
+
metadata?: any;
|
|
43
|
+
}>): Promise<void>;
|
|
44
|
+
/**
|
|
45
|
+
* Retrieve documents relevant to a query using graph + text scoring.
|
|
46
|
+
*
|
|
47
|
+
* @param {string|{query: string, topK?: number}} queryOrObj - Query string or options object
|
|
48
|
+
* @param {number} [k] - Number of results (overrides config.maxResults)
|
|
49
|
+
* @returns {Promise<Array<{id: string, score: number, content: string, metadata: Object}>>}
|
|
50
|
+
*/
|
|
51
|
+
retrieve(queryOrObj: string | {
|
|
52
|
+
query: string;
|
|
53
|
+
topK?: number;
|
|
54
|
+
}, k?: number): Promise<Array<{
|
|
55
|
+
id: string;
|
|
56
|
+
score: number;
|
|
57
|
+
content: string;
|
|
58
|
+
metadata: any;
|
|
59
|
+
}>>;
|
|
60
|
+
/**
|
|
61
|
+
* Return basic graph statistics.
|
|
62
|
+
* @returns {{entityCount: number, relationshipCount: number}}
|
|
63
|
+
*/
|
|
64
|
+
getGraphStats(): {
|
|
65
|
+
entityCount: number;
|
|
66
|
+
relationshipCount: number;
|
|
67
|
+
};
|
|
68
|
+
/**
|
|
69
|
+
* Clear all stored data, the graph, and indexes.
|
|
70
|
+
*/
|
|
71
|
+
clear(): void;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Default configuration for the GraphRetriever.
|
|
75
|
+
* @type {Object}
|
|
76
|
+
*/
|
|
77
|
+
export const DEFAULT_CONFIG: any;
|
|
78
|
+
import { EventEmitter } from "events";
|
|
79
|
+
import { KnowledgeGraph } from "./knowledge-graph";
|
|
80
|
+
import { EntityExtractor } from "./entity-extractor";
|
|
81
|
+
import { GraphIndex } from "./graph-index";
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* In-memory knowledge graph with entities and relationships.
|
|
3
|
+
*
|
|
4
|
+
* Stores typed entities and directed relationships between them,
|
|
5
|
+
* supporting traversal, pattern-based querying, and adjacency lookups.
|
|
6
|
+
*/
|
|
7
|
+
export class KnowledgeGraph extends EventEmitter<[never]> {
|
|
8
|
+
/**
|
|
9
|
+
* @param {Object} [options={}] - Graph configuration options
|
|
10
|
+
*/
|
|
11
|
+
constructor(options?: any);
|
|
12
|
+
/** @type {Map<string, {id: string, type: string, properties: Object, labels: string[]}>} */
|
|
13
|
+
entities: Map<string, {
|
|
14
|
+
id: string;
|
|
15
|
+
type: string;
|
|
16
|
+
properties: any;
|
|
17
|
+
labels: string[];
|
|
18
|
+
}>;
|
|
19
|
+
/** @type {Map<string, {id: string, from: string, to: string, type: string, properties: Object}>} */
|
|
20
|
+
relationships: Map<string, {
|
|
21
|
+
id: string;
|
|
22
|
+
from: string;
|
|
23
|
+
to: string;
|
|
24
|
+
type: string;
|
|
25
|
+
properties: any;
|
|
26
|
+
}>;
|
|
27
|
+
/** @type {Map<string, Set<string>>} */
|
|
28
|
+
adjacency: Map<string, Set<string>>;
|
|
29
|
+
options: any;
|
|
30
|
+
_relationshipCounter: number;
|
|
31
|
+
/**
|
|
32
|
+
* Add an entity to the graph.
|
|
33
|
+
* @param {string} id - Unique entity identifier
|
|
34
|
+
* @param {string} type - Entity type (e.g. 'person', 'date', 'url')
|
|
35
|
+
* @param {Object} [properties={}] - Arbitrary key-value properties
|
|
36
|
+
* @returns {{id: string, type: string, properties: Object, labels: string[]}}
|
|
37
|
+
*/
|
|
38
|
+
addEntity(id: string, type: string, properties?: any): {
|
|
39
|
+
id: string;
|
|
40
|
+
type: string;
|
|
41
|
+
properties: any;
|
|
42
|
+
labels: string[];
|
|
43
|
+
};
|
|
44
|
+
/**
|
|
45
|
+
* Add a directed relationship between two entities.
|
|
46
|
+
* @param {string} fromId - Source entity ID
|
|
47
|
+
* @param {string} toId - Target entity ID
|
|
48
|
+
* @param {string} type - Relationship type (e.g. 'co-occurs', 'references')
|
|
49
|
+
* @param {Object} [properties={}] - Arbitrary key-value properties
|
|
50
|
+
* @returns {{id: string, from: string, to: string, type: string, properties: Object}}
|
|
51
|
+
* @throws {Error} If either entity does not exist
|
|
52
|
+
*/
|
|
53
|
+
addRelationship(fromId: string, toId: string, type: string, properties?: any): {
|
|
54
|
+
id: string;
|
|
55
|
+
from: string;
|
|
56
|
+
to: string;
|
|
57
|
+
type: string;
|
|
58
|
+
properties: any;
|
|
59
|
+
};
|
|
60
|
+
/**
|
|
61
|
+
* Retrieve an entity by ID.
|
|
62
|
+
* @param {string} id - Entity ID
|
|
63
|
+
* @returns {{id: string, type: string, properties: Object, labels: string[]}|null}
|
|
64
|
+
*/
|
|
65
|
+
getEntity(id: string): {
|
|
66
|
+
id: string;
|
|
67
|
+
type: string;
|
|
68
|
+
properties: any;
|
|
69
|
+
labels: string[];
|
|
70
|
+
} | null;
|
|
71
|
+
/**
|
|
72
|
+
* Get relationships for an entity, optionally filtered.
|
|
73
|
+
* @param {string} entityId - Entity ID
|
|
74
|
+
* @param {Object} [options={}] - Filter options
|
|
75
|
+
* @param {string} [options.type] - Filter by relationship type
|
|
76
|
+
* @param {'outgoing'|'incoming'|'both'} [options.direction='both'] - Direction filter
|
|
77
|
+
* @returns {Array<{id: string, from: string, to: string, type: string, properties: Object}>}
|
|
78
|
+
*/
|
|
79
|
+
getRelationships(entityId: string, options?: {
|
|
80
|
+
type?: string;
|
|
81
|
+
direction?: "outgoing" | "incoming" | "both";
|
|
82
|
+
}): Array<{
|
|
83
|
+
id: string;
|
|
84
|
+
from: string;
|
|
85
|
+
to: string;
|
|
86
|
+
type: string;
|
|
87
|
+
properties: any;
|
|
88
|
+
}>;
|
|
89
|
+
/**
|
|
90
|
+
* BFS traversal from startId up to a given depth.
|
|
91
|
+
* @param {string} startId - Starting entity ID
|
|
92
|
+
* @param {number} [depth=2] - Maximum traversal depth
|
|
93
|
+
* @returns {{entities: Array, relationships: Array, paths: Array<string[]>}}
|
|
94
|
+
*/
|
|
95
|
+
traverse(startId: string, depth?: number): {
|
|
96
|
+
entities: any[];
|
|
97
|
+
relationships: any[];
|
|
98
|
+
paths: Array<string[]>;
|
|
99
|
+
};
|
|
100
|
+
/**
|
|
101
|
+
* Query the graph by pattern matching.
|
|
102
|
+
* @param {Object} pattern - Query pattern
|
|
103
|
+
* @param {string} [pattern.entityType] - Filter entities by type
|
|
104
|
+
* @param {string} [pattern.relationshipType] - Filter relationships by type
|
|
105
|
+
* @param {Object} [pattern.properties] - Filter by property key-value pairs
|
|
106
|
+
* @returns {{entities: Array, relationships: Array}}
|
|
107
|
+
*/
|
|
108
|
+
query(pattern: {
|
|
109
|
+
entityType?: string;
|
|
110
|
+
relationshipType?: string;
|
|
111
|
+
properties?: any;
|
|
112
|
+
}): {
|
|
113
|
+
entities: any[];
|
|
114
|
+
relationships: any[];
|
|
115
|
+
};
|
|
116
|
+
/**
|
|
117
|
+
* Return basic graph statistics.
|
|
118
|
+
* @returns {{entityCount: number, relationshipCount: number}}
|
|
119
|
+
*/
|
|
120
|
+
getStats(): {
|
|
121
|
+
entityCount: number;
|
|
122
|
+
relationshipCount: number;
|
|
123
|
+
};
|
|
124
|
+
/**
|
|
125
|
+
* Clear all graph data.
|
|
126
|
+
*/
|
|
127
|
+
clear(): void;
|
|
128
|
+
}
|
|
129
|
+
import { EventEmitter } from "events";
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pipeline wrapper that applies all three guardrail layers (pre-retrieval,
|
|
3
|
+
* retrieval, and post-generation) around an existing RAG pipeline. In strict
|
|
4
|
+
* mode, any guard failure aborts the pipeline; otherwise issues are collected
|
|
5
|
+
* as warnings and execution continues.
|
|
6
|
+
*
|
|
7
|
+
* @extends EventEmitter
|
|
8
|
+
*/
|
|
9
|
+
export class GuardrailsPipeline extends EventEmitter<[never]> {
|
|
10
|
+
/**
|
|
11
|
+
* @param {object} pipeline - The underlying RAG pipeline (must have a .run() method)
|
|
12
|
+
* @param {object} [options] - Override default configuration
|
|
13
|
+
* @param {object|false} [options.preRetrieval={}] - PreRetrievalGuard options, or false to disable
|
|
14
|
+
* @param {object|false} [options.retrieval={}] - RetrievalGuard options, or false to disable
|
|
15
|
+
* @param {object|false} [options.postGeneration={}] - PostGenerationGuard options, or false to disable
|
|
16
|
+
* @param {boolean} [options.strict=false] - Whether to block on any guard failure
|
|
17
|
+
*/
|
|
18
|
+
constructor(pipeline: object, options?: {
|
|
19
|
+
preRetrieval?: object | false;
|
|
20
|
+
retrieval?: object | false;
|
|
21
|
+
postGeneration?: object | false;
|
|
22
|
+
strict?: boolean;
|
|
23
|
+
});
|
|
24
|
+
pipeline: any;
|
|
25
|
+
config: any;
|
|
26
|
+
preGuard: PreRetrievalGuard;
|
|
27
|
+
retrievalGuard: RetrievalGuard;
|
|
28
|
+
postGuard: PostGenerationGuard;
|
|
29
|
+
/**
|
|
30
|
+
* Run the full guarded pipeline.
|
|
31
|
+
*
|
|
32
|
+
* @param {object} input - Pipeline input
|
|
33
|
+
* @param {string} input.query - The user query
|
|
34
|
+
* @param {Float32Array} [input.queryVector] - Optional precomputed query vector
|
|
35
|
+
* @param {object} [input.options] - Additional pipeline options
|
|
36
|
+
* @param {object} [input.context] - Request context (e.g. userPermissions for ACL)
|
|
37
|
+
* @returns {Promise<object>} Pipeline result with guardrails metadata attached
|
|
38
|
+
*/
|
|
39
|
+
run(input: {
|
|
40
|
+
query: string;
|
|
41
|
+
queryVector?: Float32Array;
|
|
42
|
+
options?: object;
|
|
43
|
+
context?: object;
|
|
44
|
+
}): Promise<object>;
|
|
45
|
+
/**
|
|
46
|
+
* Citations and evaluation details copy sentences from the raw answer, so
|
|
47
|
+
* scrub every string in them with the same PII patterns as the answer.
|
|
48
|
+
*
|
|
49
|
+
* @param {*} value - Object, array or string to redact in place
|
|
50
|
+
* @returns {*} The redacted value
|
|
51
|
+
* @private
|
|
52
|
+
*/
|
|
53
|
+
private _redactDeep;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Default configuration for the GuardrailsPipeline.
|
|
57
|
+
* @type {object}
|
|
58
|
+
*/
|
|
59
|
+
export const DEFAULT_CONFIG: object;
|
|
60
|
+
import { EventEmitter } from "events";
|
|
61
|
+
import { PreRetrievalGuard } from "./pre-retrieval-guard";
|
|
62
|
+
import { RetrievalGuard } from "./retrieval-guard";
|
|
63
|
+
import { PostGenerationGuard } from "./post-generation-guard";
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Detect prompt-injection attempts in text.
|
|
3
|
+
*
|
|
4
|
+
* Built-in rules run on the folded text. Custom patterns run on the
|
|
5
|
+
* normalised text (case preserved) and on the folded text.
|
|
6
|
+
*
|
|
7
|
+
* @param {string} text
|
|
8
|
+
* @param {object} [opts]
|
|
9
|
+
* @param {Array<RegExp|string>} [opts.patterns=[]] - Extra patterns
|
|
10
|
+
* @param {boolean} [opts.useDefaults=true] - Include the built-in rules
|
|
11
|
+
* @returns {{ detected: boolean, matches: Array<{ id: string, pattern: string, match: string }>, normalized: string }}
|
|
12
|
+
*/
|
|
13
|
+
export function detectInjection(text: string, opts?: {
|
|
14
|
+
patterns?: Array<RegExp | string>;
|
|
15
|
+
useDefaults?: boolean;
|
|
16
|
+
}): {
|
|
17
|
+
detected: boolean;
|
|
18
|
+
matches: Array<{
|
|
19
|
+
id: string;
|
|
20
|
+
pattern: string;
|
|
21
|
+
match: string;
|
|
22
|
+
}>;
|
|
23
|
+
normalized: string;
|
|
24
|
+
};
|
|
25
|
+
/**
|
|
26
|
+
* Normalise text for matching, without leetspeak/homoglyph folding.
|
|
27
|
+
* Case is preserved so case-sensitive custom patterns still work.
|
|
28
|
+
* @param {string} text
|
|
29
|
+
* @returns {string}
|
|
30
|
+
*/
|
|
31
|
+
export function normalizeText(text: string): string;
|
|
32
|
+
/**
|
|
33
|
+
* Fully folded, lower-case form used by the built-in patterns.
|
|
34
|
+
* @param {string} text
|
|
35
|
+
* @returns {string}
|
|
36
|
+
*/
|
|
37
|
+
export function foldText(text: string): string;
|
|
38
|
+
/**
|
|
39
|
+
* Built-in injection patterns. They run against the folded, lower-case text,
|
|
40
|
+
* so they are written in lower case and must stay narrow enough not to flag
|
|
41
|
+
* ordinary questions (e.g. "How does Redis act as a cache?").
|
|
42
|
+
* @type {Array<{ id: string, pattern: RegExp }>}
|
|
43
|
+
*/
|
|
44
|
+
export const DEFAULT_RULES: Array<{
|
|
45
|
+
id: string;
|
|
46
|
+
pattern: RegExp;
|
|
47
|
+
}>;
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Post-generation guard that checks LLM output for PII leakage,
|
|
3
|
+
* groundedness against source documents, and length constraints.
|
|
4
|
+
* Sanitizes output by redacting detected PII.
|
|
5
|
+
*
|
|
6
|
+
* @extends EventEmitter
|
|
7
|
+
*/
|
|
8
|
+
export class PostGenerationGuard extends EventEmitter<[never]> {
|
|
9
|
+
/**
|
|
10
|
+
* @param {object} [options] - Override default configuration
|
|
11
|
+
* @param {boolean} [options.enablePIIDetection=true] - Whether to detect PII in output
|
|
12
|
+
* @param {boolean} [options.enableGroundednessCheck=true] - Whether to check groundedness
|
|
13
|
+
* @param {number} [options.groundednessThreshold=0.3] - Minimum groundedness score
|
|
14
|
+
* @param {number} [options.maxResponseLength=50000] - Maximum allowed response length
|
|
15
|
+
* @param {number} [options.minResponseLength=0] - Minimum response length
|
|
16
|
+
* @param {object} [options.piiPatterns] - Custom PII regex patterns (merged with defaults)
|
|
17
|
+
*/
|
|
18
|
+
constructor(options?: {
|
|
19
|
+
enablePIIDetection?: boolean;
|
|
20
|
+
enableGroundednessCheck?: boolean;
|
|
21
|
+
groundednessThreshold?: number;
|
|
22
|
+
maxResponseLength?: number;
|
|
23
|
+
minResponseLength?: number;
|
|
24
|
+
piiPatterns?: object;
|
|
25
|
+
});
|
|
26
|
+
config: any;
|
|
27
|
+
/**
|
|
28
|
+
* Check generated output for safety issues, PII, and groundedness.
|
|
29
|
+
*
|
|
30
|
+
* @param {string} output - The LLM-generated output text
|
|
31
|
+
* @param {Array<object>} [retrievedDocs=[]] - Source documents for groundedness checking
|
|
32
|
+
* @returns {{
|
|
33
|
+
* safe: boolean,
|
|
34
|
+
* issues: string[],
|
|
35
|
+
* sanitizedOutput: string,
|
|
36
|
+
* groundednessScore?: number
|
|
37
|
+
* }}
|
|
38
|
+
* @fires PostGenerationGuard#checked
|
|
39
|
+
*/
|
|
40
|
+
check(output: string, retrievedDocs?: Array<object>): {
|
|
41
|
+
safe: boolean;
|
|
42
|
+
issues: string[];
|
|
43
|
+
sanitizedOutput: string;
|
|
44
|
+
groundednessScore?: number;
|
|
45
|
+
};
|
|
46
|
+
/**
|
|
47
|
+
* Replace PII matches in arbitrary text with [REDACTED], using the same
|
|
48
|
+
* patterns as check(). Used to scrub text derived from the answer, such as
|
|
49
|
+
* citation sentences.
|
|
50
|
+
*
|
|
51
|
+
* @param {string} text
|
|
52
|
+
* @returns {string}
|
|
53
|
+
*/
|
|
54
|
+
redact(text: string): string;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Default configuration for the PostGenerationGuard.
|
|
58
|
+
* @type {object}
|
|
59
|
+
*/
|
|
60
|
+
export const DEFAULT_CONFIG: object;
|
|
61
|
+
import { EventEmitter } from "events";
|