@devilsdev/rag-core 3.3.0 → 3.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/README.md +1 -1
- package/dist/all.d.ts +58 -0
- package/dist/index.cjs +275 -15
- package/dist/index.d.ts +1 -1
- package/dist/index.mjs +1 -1
- package/dist/types/adapters/ai-sdk-middleware.d.ts +10 -0
- package/dist/types/adapters/mastra.d.ts +6 -2
- package/dist/types/agentic/agentic-pipeline.d.ts +1 -1
- package/dist/types/agentic/iterative-retriever.d.ts +1 -1
- package/dist/types/agentic/query-planner.d.ts +1 -1
- package/dist/types/agentic/self-critique.d.ts +1 -1
- package/dist/types/ai/federation/federated-learning-coordinator.d.ts +1 -1
- package/dist/types/ai/training/model-training-orchestrator.d.ts +1 -1
- package/dist/types/chunking/chunking-engine.d.ts +1 -1
- package/dist/types/citation/citation-tracker.d.ts +1 -1
- package/dist/types/connectors/anthropic-connector.d.ts +35 -1
- package/dist/types/connectors/base-connector.d.ts +1 -1
- package/dist/types/connectors/connector-utils.d.ts +20 -0
- package/dist/types/cost/cost-calculator.d.ts +1 -1
- package/dist/types/cost/cost-tracker.d.ts +1 -1
- package/dist/types/cost/token-budget.d.ts +1 -1
- package/dist/types/dashboard/dashboard-generator.d.ts +1 -1
- package/dist/types/dashboard/metrics-aggregator.d.ts +1 -1
- package/dist/types/debug/execution-tracer.d.ts +1 -1
- package/dist/types/debug/trace-inspector.d.ts +1 -1
- package/dist/types/dev/dev-server.d.ts +1 -1
- package/dist/types/dev/hot-reload.d.ts +1 -1
- package/dist/types/ecosystem/plugin-analytics-dashboard.d.ts +1 -1
- package/dist/types/ecosystem/plugin-certification.d.ts +1 -1
- package/dist/types/ecosystem/plugin-hub.d.ts +1 -1
- package/dist/types/enterprise/audit-logging.d.ts +1 -1
- package/dist/types/enterprise/data-governance.d.ts +1 -1
- package/dist/types/enterprise/multi-tenancy.d.ts +1 -1
- package/dist/types/enterprise/sso-integration.d.ts +1 -1
- package/dist/types/evaluate/pipeline-evaluator.d.ts +1 -1
- package/dist/types/graph/entity-extractor.d.ts +1 -1
- package/dist/types/graph/graph-retriever.d.ts +1 -1
- package/dist/types/graph/knowledge-graph.d.ts +1 -1
- package/dist/types/grounding/check-answer.d.ts +109 -1
- package/dist/types/grounding/llm-judge.d.ts +93 -0
- package/dist/types/grounding/provider-citations.d.ts +244 -0
- package/dist/types/guardrails/detectors.d.ts +88 -0
- package/dist/types/guardrails/evaluate-detectors.d.ts +61 -0
- package/dist/types/guardrails/guardrails-pipeline.d.ts +2 -9
- package/dist/types/guardrails/post-generation-guard.d.ts +33 -3
- package/dist/types/guardrails/pre-retrieval-guard.d.ts +29 -1
- package/dist/types/guardrails/retrieval-guard.d.ts +30 -1
- package/dist/types/mcp/mcp-server.d.ts +1 -1
- package/dist/types/observability/otel.d.ts +9 -3
- package/dist/types/observability/scores.d.ts +57 -0
- package/dist/types/reranker/cascade-reranker.d.ts +1 -1
- package/dist/types/reranker/embedding-reranker.d.ts +1 -1
- package/dist/types/reranker/scoring-reranker.d.ts +1 -1
- package/dist/types/retrieval/bm25-search.d.ts +1 -1
- package/dist/types/retrieval/hybrid-retriever.d.ts +1 -1
- package/dist/types/security/jwt-validator.d.ts +1 -1
- package/dist/types/security/plugin-sandbox.d.ts +1 -1
- package/dist/types/streaming/sse-adapter.d.ts +1 -1
- package/dist/types/streaming/stream-router.d.ts +1 -1
- package/dist/types/streaming/streaming-embedder.d.ts +1 -1
- package/dist/types/streaming/websocket-adapter.d.ts +1 -1
- package/dist/types/templates/scaffold.d.ts +1 -1
- package/dist/types/testing/contract-tests.d.ts +8 -4
- package/dist/types/utils/batch-processor.d.ts +1 -1
- package/dist/types/utils/connection-pool.d.ts +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @param {object} result - A pipeline run result (or a stream's done
|
|
3
|
+
* chunk) with `evaluation` and/or `citations`, or a checkAnswer() result
|
|
4
|
+
* @param {object} [options]
|
|
5
|
+
* @param {boolean} [options.explanations=false] - Include explanations,
|
|
6
|
+
* which quote the answer
|
|
7
|
+
* @returns {Array<{name: string, value: number, target: 'retrieval'|'generation', label?: string, explanation?: string}>}
|
|
8
|
+
*/
|
|
9
|
+
export function evaluationScores(result: object, { explanations }?: {
|
|
10
|
+
explanations?: boolean;
|
|
11
|
+
}): Array<{
|
|
12
|
+
name: string;
|
|
13
|
+
value: number;
|
|
14
|
+
target: "retrieval" | "generation";
|
|
15
|
+
label?: string;
|
|
16
|
+
explanation?: string;
|
|
17
|
+
}>;
|
|
18
|
+
/**
|
|
19
|
+
* The scores of a run result or answer check as Langfuse scores: the
|
|
20
|
+
* objects `langfuse.score.create()` takes (from `@langfuse/client`), and,
|
|
21
|
+
* without a trace id, the evaluations a Langfuse experiment evaluator
|
|
22
|
+
* returns. Langfuse is not a dependency.
|
|
23
|
+
*
|
|
24
|
+
* With `telemetry` on, a run result carries its OpenTelemetry trace and span
|
|
25
|
+
* ids in `result.telemetry`; Langfuse uses the same ids when it receives the
|
|
26
|
+
* spans (LangfuseSpanProcessor), so each score is attached to the trace and
|
|
27
|
+
* to the span it judges: the retrieval for contextPrecision and
|
|
28
|
+
* contextRecall, the generation for the rest. A score whose stage had no
|
|
29
|
+
* span (a cache hit) gets the trace only: Langfuse's default span filter
|
|
30
|
+
* keeps the stage spans (they have gen_ai.* attributes) but not the run
|
|
31
|
+
* span, so an observation id for it could point at nothing.
|
|
32
|
+
*
|
|
33
|
+
* @param {object} result - A pipeline run result, a stream's done chunk, or a checkAnswer() result
|
|
34
|
+
* @param {object} [options]
|
|
35
|
+
* @param {string} [options.traceId] - Overrides `result.telemetry.traceId`
|
|
36
|
+
* @param {string} [options.observationId] - Attach every score to this observation
|
|
37
|
+
* @param {string} [options.sessionId]
|
|
38
|
+
* @param {boolean} [options.comments=false] - Add explanations as comments; they quote the answer
|
|
39
|
+
* @returns {Array<{name: string, value: number, dataType: 'NUMERIC', traceId?: string, observationId?: string, sessionId?: string, comment?: string, metadata?: {label: string}}>}
|
|
40
|
+
*/
|
|
41
|
+
export function toLangfuseScores(result: object, options?: {
|
|
42
|
+
traceId?: string;
|
|
43
|
+
observationId?: string;
|
|
44
|
+
sessionId?: string;
|
|
45
|
+
comments?: boolean;
|
|
46
|
+
}): Array<{
|
|
47
|
+
name: string;
|
|
48
|
+
value: number;
|
|
49
|
+
dataType: "NUMERIC";
|
|
50
|
+
traceId?: string;
|
|
51
|
+
observationId?: string;
|
|
52
|
+
sessionId?: string;
|
|
53
|
+
comment?: string;
|
|
54
|
+
metadata?: {
|
|
55
|
+
label: string;
|
|
56
|
+
};
|
|
57
|
+
}>;
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
*
|
|
6
6
|
* @extends EventEmitter
|
|
7
7
|
*/
|
|
8
|
-
export class CascadeReranker extends EventEmitter
|
|
8
|
+
export class CascadeReranker extends EventEmitter {
|
|
9
9
|
/**
|
|
10
10
|
* @param {object[]} [rerankers=[]] - Array of objects with .rerank() method
|
|
11
11
|
* @param {object} [options]
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
*
|
|
9
9
|
* @extends EventEmitter
|
|
10
10
|
*/
|
|
11
|
-
export class EmbeddingReranker extends EventEmitter
|
|
11
|
+
export class EmbeddingReranker extends EventEmitter {
|
|
12
12
|
/**
|
|
13
13
|
* @param {object} embedder - Must expose .embedQuery(text) or .embed(text)
|
|
14
14
|
* @param {object} [options]
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* Keyword search with BM25 ranking. Index documents with index(), then
|
|
3
3
|
* search(query) returns them scored by term frequency and rarity.
|
|
4
4
|
*/
|
|
5
|
-
export class BM25Search extends EventEmitter
|
|
5
|
+
export class BM25Search extends EventEmitter {
|
|
6
6
|
constructor(options?: {});
|
|
7
7
|
config: {
|
|
8
8
|
k1: number;
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* Runs several retrievers in parallel (for example vector and BM25) and
|
|
3
3
|
* fuses their results with weighted reciprocal rank fusion.
|
|
4
4
|
*/
|
|
5
|
-
export class HybridRetriever extends EventEmitter
|
|
5
|
+
export class HybridRetriever extends EventEmitter {
|
|
6
6
|
/**
|
|
7
7
|
* @param {Array<{retriever: object, weight: number, name: string}>} retrievers
|
|
8
8
|
* @param {object} options
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
* adapter.on('token', (t) => console.log('sent', t));
|
|
12
12
|
* await adapter.stream(asyncTokenGenerator, res);
|
|
13
13
|
*/
|
|
14
|
-
export class SSEAdapter extends EventEmitter
|
|
14
|
+
export class SSEAdapter extends EventEmitter {
|
|
15
15
|
/**
|
|
16
16
|
* @param {Object} [options] - Configuration overrides
|
|
17
17
|
* @param {string} [options.eventName='token'] - SSE event name for token frames
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
* const handler = router.createHandler(pipeline);
|
|
14
14
|
* app.post('/api/query', handler);
|
|
15
15
|
*/
|
|
16
|
-
export class StreamRouter extends EventEmitter
|
|
16
|
+
export class StreamRouter extends EventEmitter {
|
|
17
17
|
/**
|
|
18
18
|
* @param {Object} [options] - Configuration overrides
|
|
19
19
|
* @param {string} [options.defaultTransport='sse'] - Fallback transport type
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
* se.on('done', (stats) => console.log('finished', stats));
|
|
17
17
|
* const all = await se.embedAll(documents);
|
|
18
18
|
*/
|
|
19
|
-
export class StreamingEmbedder extends EventEmitter
|
|
19
|
+
export class StreamingEmbedder extends EventEmitter {
|
|
20
20
|
/**
|
|
21
21
|
* @param {Object} embedder - Embedder instance with `.embed()` or `.embedQuery()`
|
|
22
22
|
* @param {Object} [options] - Override any key from {@link DEFAULT_CONFIG}
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
* adapter.on('done', () => console.log('stream complete'));
|
|
13
13
|
* await adapter.stream(asyncTokenGenerator, ws);
|
|
14
14
|
*/
|
|
15
|
-
export class WebSocketAdapter extends EventEmitter
|
|
15
|
+
export class WebSocketAdapter extends EventEmitter {
|
|
16
16
|
/**
|
|
17
17
|
* @param {Object} [options] - Configuration overrides
|
|
18
18
|
* @param {string} [options.messageType='token'] - Type field for token messages
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
* const result = scaffolder.create('document-qa', '/path/to/my-project');
|
|
10
10
|
* console.log(result.files); // list of created files
|
|
11
11
|
*/
|
|
12
|
-
export class ProjectScaffolder extends EventEmitter
|
|
12
|
+
export class ProjectScaffolder extends EventEmitter {
|
|
13
13
|
/**
|
|
14
14
|
* @param {Object} [options={}] - Scaffolder configuration
|
|
15
15
|
* @param {boolean} [options.installDependencies=false] - Whether to auto-run npm install
|
|
@@ -11,20 +11,22 @@
|
|
|
11
11
|
* import { describe, it } from "vitest"; // or "node:test"
|
|
12
12
|
* runContractTests("llm", () => new MyLLM(), { describe, it });
|
|
13
13
|
*
|
|
14
|
-
* @param {'loader'|'embedder'|'retriever'|'reranker'|'llm'} type - Plugin type
|
|
14
|
+
* @param {'loader'|'embedder'|'retriever'|'reranker'|'llm'|'detector'} type - Plugin type
|
|
15
15
|
* @param {() => (object|Promise<object>)} factory - Returns a new, empty plugin for each check
|
|
16
16
|
* @param {object} [options]
|
|
17
17
|
* @param {string} [options.name] - Name of the test group (default: "<type> contract")
|
|
18
18
|
* @param {boolean} [options.registry=false] - Also require the `metadata` pluginRegistry.register() needs
|
|
19
19
|
* @param {(retriever: object, documents: object[]) => (void|Promise<void>)} [options.setup] - Retrievers: loads the test documents (default: `retriever.store(documents)`), for retrievers without store()
|
|
20
|
+
* @param {string} [options.positive] - Detectors: text the detector must flag, instead of the default sample for its kind
|
|
20
21
|
* @param {Function} [options.describe] - Your framework's describe (default: the global one)
|
|
21
22
|
* @param {Function} [options.it] - Your framework's it/test (default: the global it or test)
|
|
22
23
|
* @returns {void}
|
|
23
24
|
*/
|
|
24
|
-
export function runContractTests(type: "loader" | "embedder" | "retriever" | "reranker" | "llm", factory: () => (object | Promise<object>), options?: {
|
|
25
|
+
export function runContractTests(type: "loader" | "embedder" | "retriever" | "reranker" | "llm" | "detector", factory: () => (object | Promise<object>), options?: {
|
|
25
26
|
name?: string;
|
|
26
27
|
registry?: boolean;
|
|
27
28
|
setup?: (retriever: object, documents: object[]) => (void | Promise<void>);
|
|
29
|
+
positive?: string;
|
|
28
30
|
describe?: Function;
|
|
29
31
|
it?: Function;
|
|
30
32
|
}): void;
|
|
@@ -35,16 +37,18 @@ export function runContractTests(type: "loader" | "embedder" | "retriever" | "re
|
|
|
35
37
|
* const report = await checkContract("embedder", () => new MyEmbedder());
|
|
36
38
|
* if (!report.passed) console.log(report.results.filter((r) => !r.passed));
|
|
37
39
|
*
|
|
38
|
-
* @param {'loader'|'embedder'|'retriever'|'reranker'|'llm'} type - Plugin type
|
|
40
|
+
* @param {'loader'|'embedder'|'retriever'|'reranker'|'llm'|'detector'} type - Plugin type
|
|
39
41
|
* @param {() => (object|Promise<object>)} factory - Returns a new, empty plugin for each check
|
|
40
42
|
* @param {object} [options]
|
|
41
43
|
* @param {boolean} [options.registry=false] - Also require the `metadata` pluginRegistry.register() needs
|
|
42
44
|
* @param {(retriever: object, documents: object[]) => (void|Promise<void>)} [options.setup] - Retrievers: loads the test documents (default: `retriever.store(documents)`), for retrievers without store()
|
|
45
|
+
* @param {string} [options.positive] - Detectors: text the detector must flag, instead of the default sample for its kind
|
|
43
46
|
* @returns {Promise<{ type: string, passed: boolean, results: Array<{ name: string, passed: boolean, skipped: boolean, error?: string }> }>}
|
|
44
47
|
*/
|
|
45
|
-
export function checkContract(type: "loader" | "embedder" | "retriever" | "reranker" | "llm", factory: () => (object | Promise<object>), options?: {
|
|
48
|
+
export function checkContract(type: "loader" | "embedder" | "retriever" | "reranker" | "llm" | "detector", factory: () => (object | Promise<object>), options?: {
|
|
46
49
|
registry?: boolean;
|
|
47
50
|
setup?: (retriever: object, documents: object[]) => (void | Promise<void>);
|
|
51
|
+
positive?: string;
|
|
48
52
|
}): Promise<{
|
|
49
53
|
type: string;
|
|
50
54
|
passed: boolean;
|