vesper-memory 0.3.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/.env.example +28 -0
- package/CHANGELOG.md +137 -0
- package/LICENSE +21 -0
- package/README.md +665 -0
- package/config/sqlite-schema.sql +413 -0
- package/dist/benchmark/index.d.ts +18 -0
- package/dist/benchmark/index.d.ts.map +1 -0
- package/dist/benchmark/index.js +19 -0
- package/dist/benchmark/index.js.map +1 -0
- package/dist/benchmark/metrics-collector.d.ts +90 -0
- package/dist/benchmark/metrics-collector.d.ts.map +1 -0
- package/dist/benchmark/metrics-collector.js +196 -0
- package/dist/benchmark/metrics-collector.js.map +1 -0
- package/dist/benchmark/report-generator.d.ts +35 -0
- package/dist/benchmark/report-generator.d.ts.map +1 -0
- package/dist/benchmark/report-generator.js +221 -0
- package/dist/benchmark/report-generator.js.map +1 -0
- package/dist/benchmark/runner.d.ts +30 -0
- package/dist/benchmark/runner.d.ts.map +1 -0
- package/dist/benchmark/runner.js +308 -0
- package/dist/benchmark/runner.js.map +1 -0
- package/dist/benchmark/scenarios/context-recall.d.ts +65 -0
- package/dist/benchmark/scenarios/context-recall.d.ts.map +1 -0
- package/dist/benchmark/scenarios/context-recall.js +180 -0
- package/dist/benchmark/scenarios/context-recall.js.map +1 -0
- package/dist/benchmark/scenarios/index.d.ts +34 -0
- package/dist/benchmark/scenarios/index.d.ts.map +1 -0
- package/dist/benchmark/scenarios/index.js +230 -0
- package/dist/benchmark/scenarios/index.js.map +1 -0
- package/dist/benchmark/statistics.d.ts +125 -0
- package/dist/benchmark/statistics.d.ts.map +1 -0
- package/dist/benchmark/statistics.js +520 -0
- package/dist/benchmark/statistics.js.map +1 -0
- package/dist/benchmark/types.d.ts +458 -0
- package/dist/benchmark/types.d.ts.map +1 -0
- package/dist/benchmark/types.js +297 -0
- package/dist/benchmark/types.js.map +1 -0
- package/dist/cli 2.js +583 -0
- package/dist/cli.d 2.ts +8 -0
- package/dist/cli.d.ts +8 -0
- package/dist/cli.d.ts 2.map +1 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +583 -0
- package/dist/cli.js 2.map +1 -0
- package/dist/cli.js.map +1 -0
- package/dist/config/rate-limits.d.ts +76 -0
- package/dist/config/rate-limits.d.ts.map +1 -0
- package/dist/config/rate-limits.js +161 -0
- package/dist/config/rate-limits.js.map +1 -0
- package/dist/config 2/rate-limits.d.ts +76 -0
- package/dist/config 2/rate-limits.d.ts.map +1 -0
- package/dist/config 2/rate-limits.js +161 -0
- package/dist/config 2/rate-limits.js.map +1 -0
- package/dist/consolidation/pipeline.d.ts +52 -0
- package/dist/consolidation/pipeline.d.ts.map +1 -0
- package/dist/consolidation/pipeline.js +193 -0
- package/dist/consolidation/pipeline.js.map +1 -0
- package/dist/consolidation 2/pipeline.d.ts +52 -0
- package/dist/consolidation 2/pipeline.d.ts.map +1 -0
- package/dist/consolidation 2/pipeline.js +193 -0
- package/dist/consolidation 2/pipeline.js.map +1 -0
- package/dist/embeddings/client.d.ts +95 -0
- package/dist/embeddings/client.d.ts.map +1 -0
- package/dist/embeddings/client.js +162 -0
- package/dist/embeddings/client.js.map +1 -0
- package/dist/embeddings 2/client.d.ts +94 -0
- package/dist/embeddings 2/client.d.ts.map +1 -0
- package/dist/embeddings 2/client.js +144 -0
- package/dist/embeddings 2/client.js.map +1 -0
- package/dist/memory-layers/semantic-memory.d.ts +76 -0
- package/dist/memory-layers/semantic-memory.d.ts.map +1 -0
- package/dist/memory-layers/semantic-memory.js +231 -0
- package/dist/memory-layers/semantic-memory.js.map +1 -0
- package/dist/memory-layers/skill-library.d.ts +25 -0
- package/dist/memory-layers/skill-library.d.ts.map +1 -0
- package/dist/memory-layers/skill-library.js +54 -0
- package/dist/memory-layers/skill-library.js.map +1 -0
- package/dist/memory-layers/working-memory.d.ts +57 -0
- package/dist/memory-layers/working-memory.d.ts.map +1 -0
- package/dist/memory-layers/working-memory.js +153 -0
- package/dist/memory-layers/working-memory.js.map +1 -0
- package/dist/memory-layers 2/semantic-memory.d.ts +33 -0
- package/dist/memory-layers 2/semantic-memory.d.ts.map +1 -0
- package/dist/memory-layers 2/semantic-memory.js +114 -0
- package/dist/memory-layers 2/semantic-memory.js.map +1 -0
- package/dist/memory-layers 2/skill-library.d.ts +25 -0
- package/dist/memory-layers 2/skill-library.d.ts.map +1 -0
- package/dist/memory-layers 2/skill-library.js +54 -0
- package/dist/memory-layers 2/skill-library.js.map +1 -0
- package/dist/memory-layers 2/working-memory.d.ts +57 -0
- package/dist/memory-layers 2/working-memory.d.ts.map +1 -0
- package/dist/memory-layers 2/working-memory.js +153 -0
- package/dist/memory-layers 2/working-memory.js.map +1 -0
- package/dist/middleware/auth.d.ts +287 -0
- package/dist/middleware/auth.d.ts.map +1 -0
- package/dist/middleware/auth.js +610 -0
- package/dist/middleware/auth.js.map +1 -0
- package/dist/middleware 2/auth.d.ts +287 -0
- package/dist/middleware 2/auth.d.ts.map +1 -0
- package/dist/middleware 2/auth.js +610 -0
- package/dist/middleware 2/auth.js.map +1 -0
- package/dist/monitoring/health.d.ts +241 -0
- package/dist/monitoring/health.d.ts.map +1 -0
- package/dist/monitoring/health.js +649 -0
- package/dist/monitoring/health.js.map +1 -0
- package/dist/monitoring/metrics.d.ts +153 -0
- package/dist/monitoring/metrics.d.ts.map +1 -0
- package/dist/monitoring/metrics.js +349 -0
- package/dist/monitoring/metrics.js.map +1 -0
- package/dist/monitoring 2/health.d.ts +241 -0
- package/dist/monitoring 2/health.d.ts.map +1 -0
- package/dist/monitoring 2/health.js +649 -0
- package/dist/monitoring 2/health.js.map +1 -0
- package/dist/monitoring 2/metrics.d.ts +153 -0
- package/dist/monitoring 2/metrics.d.ts.map +1 -0
- package/dist/monitoring 2/metrics.js +349 -0
- package/dist/monitoring 2/metrics.js.map +1 -0
- package/dist/retrieval/hybrid-search.d.ts +186 -0
- package/dist/retrieval/hybrid-search.d.ts.map +1 -0
- package/dist/retrieval/hybrid-search.js +330 -0
- package/dist/retrieval/hybrid-search.js.map +1 -0
- package/dist/retrieval 2/hybrid-search.d.ts +186 -0
- package/dist/retrieval 2/hybrid-search.d.ts.map +1 -0
- package/dist/retrieval 2/hybrid-search.js +327 -0
- package/dist/retrieval 2/hybrid-search.js.map +1 -0
- package/dist/router/smart-router.d.ts +157 -0
- package/dist/router/smart-router.d.ts.map +1 -0
- package/dist/router/smart-router.js +524 -0
- package/dist/router/smart-router.js.map +1 -0
- package/dist/router 2/smart-router.d.ts +111 -0
- package/dist/router 2/smart-router.d.ts.map +1 -0
- package/dist/router 2/smart-router.js +383 -0
- package/dist/router 2/smart-router.js.map +1 -0
- package/dist/security/rate-limit-middleware.d.ts +119 -0
- package/dist/security/rate-limit-middleware.d.ts.map +1 -0
- package/dist/security/rate-limit-middleware.js +193 -0
- package/dist/security/rate-limit-middleware.js.map +1 -0
- package/dist/security 2/rate-limit-middleware.d.ts +119 -0
- package/dist/security 2/rate-limit-middleware.d.ts.map +1 -0
- package/dist/security 2/rate-limit-middleware.js +193 -0
- package/dist/security 2/rate-limit-middleware.js.map +1 -0
- package/dist/server 2.js +861 -0
- package/dist/server-wrapper 2.js +170 -0
- package/dist/server-wrapper.d 2.ts +12 -0
- package/dist/server-wrapper.d.ts +12 -0
- package/dist/server-wrapper.d.ts 2.map +1 -0
- package/dist/server-wrapper.d.ts.map +1 -0
- package/dist/server-wrapper.js +170 -0
- package/dist/server-wrapper.js 2.map +1 -0
- package/dist/server-wrapper.js.map +1 -0
- package/dist/server.d 2.ts +14 -0
- package/dist/server.d.ts +14 -0
- package/dist/server.d.ts 2.map +1 -0
- package/dist/server.d.ts.map +1 -0
- package/dist/server.js +656 -0
- package/dist/server.js 2.map +1 -0
- package/dist/server.js.map +1 -0
- package/dist/synthesis/conflict-detector.d.ts +43 -0
- package/dist/synthesis/conflict-detector.d.ts.map +1 -0
- package/dist/synthesis/conflict-detector.js +125 -0
- package/dist/synthesis/conflict-detector.js.map +1 -0
- package/dist/synthesis 2/conflict-detector.d.ts +43 -0
- package/dist/synthesis 2/conflict-detector.d.ts.map +1 -0
- package/dist/synthesis 2/conflict-detector.js +125 -0
- package/dist/synthesis 2/conflict-detector.js.map +1 -0
- package/dist/utils/monitoring.d.ts +25 -0
- package/dist/utils/monitoring.d.ts.map +1 -0
- package/dist/utils/monitoring.js +41 -0
- package/dist/utils/monitoring.js.map +1 -0
- package/dist/utils/rate-limiter.d.ts +97 -0
- package/dist/utils/rate-limiter.d.ts.map +1 -0
- package/dist/utils/rate-limiter.js +166 -0
- package/dist/utils/rate-limiter.js.map +1 -0
- package/dist/utils/validation.d.ts +139 -0
- package/dist/utils/validation.d.ts.map +1 -0
- package/dist/utils/validation.js +195 -0
- package/dist/utils/validation.js.map +1 -0
- package/dist/utils 2/monitoring.d.ts +25 -0
- package/dist/utils 2/monitoring.d.ts.map +1 -0
- package/dist/utils 2/monitoring.js +41 -0
- package/dist/utils 2/monitoring.js.map +1 -0
- package/dist/utils 2/rate-limiter.d.ts +97 -0
- package/dist/utils 2/rate-limiter.d.ts.map +1 -0
- package/dist/utils 2/rate-limiter.js +166 -0
- package/dist/utils 2/rate-limiter.js.map +1 -0
- package/dist/utils 2/validation.d.ts +139 -0
- package/dist/utils 2/validation.d.ts.map +1 -0
- package/dist/utils 2/validation.js +195 -0
- package/dist/utils 2/validation.js.map +1 -0
- package/docker-compose.yml +65 -0
- package/embedding-service/Dockerfile +29 -0
- package/embedding-service/README.md +68 -0
- package/embedding-service/requirements.txt +6 -0
- package/embedding-service/server.py +110 -0
- package/package.json +92 -0
- package/scripts/FRESH_INSTALL.md +280 -0
- package/scripts/README.md +101 -0
- package/scripts/ensure-infrastructure.sh +38 -0
- package/scripts/fresh-install-auto.sh +96 -0
- package/scripts/fresh-install.sh +167 -0
- package/scripts/health-check.sh +72 -0
- package/scripts/init-qdrant.ts +201 -0
- package/scripts/postinstall.js +94 -0
- package/scripts/run-accuracy-benchmark.ts +1237 -0
- package/scripts/run-real-benchmark.ts +581 -0
- package/scripts/test-mcp-server.sh +38 -0
|
@@ -0,0 +1,230 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Scenario Module Index
|
|
3
|
+
*
|
|
4
|
+
* Exports all scenario implementations and factory functions.
|
|
5
|
+
*/
|
|
6
|
+
export { createContextRecallScenario, CONTEXT_RECALL_TEST_DATA } from "./context-recall.js";
|
|
7
|
+
import { createContextRecallScenario } from "./context-recall.js";
|
|
8
|
+
/**
|
|
9
|
+
* Create a scenario by type
|
|
10
|
+
*
|
|
11
|
+
* @param type - The scenario type to create
|
|
12
|
+
* @param client - MCP client for memory operations
|
|
13
|
+
* @returns Scenario instance
|
|
14
|
+
* @throws Error if scenario type is not supported
|
|
15
|
+
*/
|
|
16
|
+
export function createScenario(type, client) {
|
|
17
|
+
switch (type) {
|
|
18
|
+
case "context-recall":
|
|
19
|
+
return createContextRecallScenario(client);
|
|
20
|
+
case "cross-session":
|
|
21
|
+
return createCrossSessionScenario(client);
|
|
22
|
+
case "skill-retrieval":
|
|
23
|
+
return createSkillRetrievalScenario(client);
|
|
24
|
+
case "token-efficiency":
|
|
25
|
+
return createTokenEfficiencyScenario(client);
|
|
26
|
+
case "semantic-accuracy":
|
|
27
|
+
return createSemanticAccuracyScenario(client);
|
|
28
|
+
default:
|
|
29
|
+
throw new Error(`Unsupported scenario type: ${type}`);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
// =============================================================================
|
|
33
|
+
// Cross-Session Scenario (Simplified Implementation)
|
|
34
|
+
// =============================================================================
|
|
35
|
+
function createCrossSessionScenario(client) {
|
|
36
|
+
const testData = [
|
|
37
|
+
{
|
|
38
|
+
session1Fact: "In our previous session, we discussed implementing caching with Redis",
|
|
39
|
+
session2Question: "What did we discuss about caching?",
|
|
40
|
+
expectedKeywords: ["Redis", "caching"],
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
session1Fact: "Yesterday, the user decided to use PostgreSQL for the database",
|
|
44
|
+
session2Question: "What database did we decide to use?",
|
|
45
|
+
expectedKeywords: ["PostgreSQL", "database"],
|
|
46
|
+
},
|
|
47
|
+
{
|
|
48
|
+
session1Fact: "Last week, we fixed a critical bug in the authentication system",
|
|
49
|
+
session2Question: "What bug did we fix recently?",
|
|
50
|
+
expectedKeywords: ["bug", "authentication"],
|
|
51
|
+
},
|
|
52
|
+
];
|
|
53
|
+
return createBaseScenario("cross-session", client, testData);
|
|
54
|
+
}
|
|
55
|
+
// =============================================================================
|
|
56
|
+
// Skill Retrieval Scenario (Simplified Implementation)
|
|
57
|
+
// =============================================================================
|
|
58
|
+
function createSkillRetrievalScenario(client) {
|
|
59
|
+
const testData = [
|
|
60
|
+
{
|
|
61
|
+
session1Fact: "Skill: Deploy to production by running 'npm run build && npm run deploy'",
|
|
62
|
+
session2Question: "How do I deploy to production?",
|
|
63
|
+
expectedKeywords: ["npm", "build", "deploy"],
|
|
64
|
+
},
|
|
65
|
+
{
|
|
66
|
+
session1Fact: "Skill: Create a new component using 'npm run generate:component ComponentName'",
|
|
67
|
+
session2Question: "How do I create a new component?",
|
|
68
|
+
expectedKeywords: ["generate", "component"],
|
|
69
|
+
},
|
|
70
|
+
{
|
|
71
|
+
session1Fact: "Skill: Run tests with coverage using 'npm test -- --coverage'",
|
|
72
|
+
session2Question: "How do I run tests with coverage?",
|
|
73
|
+
expectedKeywords: ["test", "coverage"],
|
|
74
|
+
},
|
|
75
|
+
];
|
|
76
|
+
return createBaseScenario("skill-retrieval", client, testData);
|
|
77
|
+
}
|
|
78
|
+
// =============================================================================
|
|
79
|
+
// Token Efficiency Scenario (Simplified Implementation)
|
|
80
|
+
// =============================================================================
|
|
81
|
+
function createTokenEfficiencyScenario(client) {
|
|
82
|
+
const testData = [
|
|
83
|
+
{
|
|
84
|
+
session1Fact: "Project context: Building a memory system for AI with Redis, Qdrant, and SQLite",
|
|
85
|
+
session2Question: "What is the project context?",
|
|
86
|
+
expectedKeywords: ["memory", "Redis", "Qdrant", "SQLite"],
|
|
87
|
+
},
|
|
88
|
+
{
|
|
89
|
+
session1Fact: "User preferences: TypeScript, functional programming, 80% test coverage",
|
|
90
|
+
session2Question: "What are the user's coding preferences?",
|
|
91
|
+
expectedKeywords: ["TypeScript", "functional", "test", "coverage"],
|
|
92
|
+
},
|
|
93
|
+
];
|
|
94
|
+
return createBaseScenario("token-efficiency", client, testData);
|
|
95
|
+
}
|
|
96
|
+
// =============================================================================
|
|
97
|
+
// Semantic Accuracy Scenario (Simplified Implementation)
|
|
98
|
+
// =============================================================================
|
|
99
|
+
function createSemanticAccuracyScenario(client) {
|
|
100
|
+
const testData = [
|
|
101
|
+
{
|
|
102
|
+
session1Fact: "The capital city of France is Paris, known for the Eiffel Tower",
|
|
103
|
+
session2Question: "What is the capital of France?",
|
|
104
|
+
expectedKeywords: ["Paris", "capital"],
|
|
105
|
+
},
|
|
106
|
+
{
|
|
107
|
+
session1Fact: "Machine learning is a subset of artificial intelligence focused on learning from data",
|
|
108
|
+
session2Question: "What is machine learning?",
|
|
109
|
+
expectedKeywords: ["learning", "data", "artificial intelligence"],
|
|
110
|
+
},
|
|
111
|
+
{
|
|
112
|
+
session1Fact: "REST APIs use HTTP methods like GET, POST, PUT, DELETE for communication",
|
|
113
|
+
session2Question: "How do REST APIs work?",
|
|
114
|
+
expectedKeywords: ["HTTP", "GET", "POST"],
|
|
115
|
+
},
|
|
116
|
+
];
|
|
117
|
+
return createBaseScenario("semantic-accuracy", client, testData);
|
|
118
|
+
}
|
|
119
|
+
function createBaseScenario(type, client, testData) {
|
|
120
|
+
const errors = [];
|
|
121
|
+
return {
|
|
122
|
+
getType() {
|
|
123
|
+
return type;
|
|
124
|
+
},
|
|
125
|
+
getDescription() {
|
|
126
|
+
const descriptions = {
|
|
127
|
+
"context-recall": "Tests ability to recall facts from conversations",
|
|
128
|
+
"cross-session": "Tests persistence of context across sessions",
|
|
129
|
+
"skill-retrieval": "Tests retrieval of procedural knowledge",
|
|
130
|
+
"token-efficiency": "Measures token usage reduction",
|
|
131
|
+
"semantic-accuracy": "Tests semantic search accuracy",
|
|
132
|
+
};
|
|
133
|
+
return descriptions[type];
|
|
134
|
+
},
|
|
135
|
+
async setup() {
|
|
136
|
+
errors.length = 0;
|
|
137
|
+
for (const testCase of testData) {
|
|
138
|
+
try {
|
|
139
|
+
await client.storeMemory(testCase.session1Fact, "semantic", {
|
|
140
|
+
scenario: type,
|
|
141
|
+
timestamp: Date.now(),
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
catch (err) {
|
|
145
|
+
const errorMsg = err instanceof Error ? err.message : String(err);
|
|
146
|
+
errors.push(`Setup error: ${errorMsg}`);
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
},
|
|
150
|
+
async run(phase) {
|
|
151
|
+
const { measureLatency, evaluateResponseQuality, aggregateMetrics } = await import("../metrics-collector.js");
|
|
152
|
+
const metrics = [];
|
|
153
|
+
const rawResponses = [];
|
|
154
|
+
for (const testCase of testData) {
|
|
155
|
+
if (phase === "vesper-enabled") {
|
|
156
|
+
try {
|
|
157
|
+
const { result, latencyMs } = await measureLatency(async () => {
|
|
158
|
+
return await client.retrieveMemory(testCase.session2Question, {
|
|
159
|
+
max_results: 3,
|
|
160
|
+
});
|
|
161
|
+
});
|
|
162
|
+
const memoryHit = result.success && result.results.length > 0;
|
|
163
|
+
const responseContent = memoryHit
|
|
164
|
+
? result.results[0].content
|
|
165
|
+
: "No relevant memory found";
|
|
166
|
+
const retrievalAccuracy = memoryHit
|
|
167
|
+
? evaluateResponseQuality(responseContent, testCase.expectedKeywords, {
|
|
168
|
+
mode: "keywords",
|
|
169
|
+
})
|
|
170
|
+
: 0;
|
|
171
|
+
metrics.push({
|
|
172
|
+
timestamp: Date.now(),
|
|
173
|
+
latencyMs,
|
|
174
|
+
memoryHit,
|
|
175
|
+
retrievalAccuracy,
|
|
176
|
+
});
|
|
177
|
+
rawResponses.push(responseContent);
|
|
178
|
+
}
|
|
179
|
+
catch (err) {
|
|
180
|
+
const errorMsg = err instanceof Error ? err.message : String(err);
|
|
181
|
+
errors.push(`Run error: ${errorMsg}`);
|
|
182
|
+
metrics.push({
|
|
183
|
+
timestamp: Date.now(),
|
|
184
|
+
latencyMs: 0,
|
|
185
|
+
memoryHit: false,
|
|
186
|
+
retrievalAccuracy: 0,
|
|
187
|
+
});
|
|
188
|
+
rawResponses.push(`Error: ${errorMsg}`);
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
else {
|
|
192
|
+
const startTime = performance.now();
|
|
193
|
+
await new Promise((resolve) => setTimeout(resolve, 1));
|
|
194
|
+
const latencyMs = performance.now() - startTime;
|
|
195
|
+
metrics.push({
|
|
196
|
+
timestamp: Date.now(),
|
|
197
|
+
latencyMs,
|
|
198
|
+
memoryHit: false,
|
|
199
|
+
retrievalAccuracy: 0,
|
|
200
|
+
});
|
|
201
|
+
rawResponses.push("Memory disabled - cannot recall");
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
let aggregates;
|
|
205
|
+
try {
|
|
206
|
+
aggregates = aggregateMetrics(metrics);
|
|
207
|
+
}
|
|
208
|
+
catch {
|
|
209
|
+
aggregates = {
|
|
210
|
+
latencyP50: 0,
|
|
211
|
+
latencyP95: 0,
|
|
212
|
+
latencyP99: 0,
|
|
213
|
+
memoryHitRate: 0,
|
|
214
|
+
};
|
|
215
|
+
}
|
|
216
|
+
return {
|
|
217
|
+
scenarioType: type,
|
|
218
|
+
phase,
|
|
219
|
+
metrics,
|
|
220
|
+
aggregates,
|
|
221
|
+
rawResponses,
|
|
222
|
+
errors: errors.length > 0 ? [...errors] : undefined,
|
|
223
|
+
};
|
|
224
|
+
},
|
|
225
|
+
async teardown() {
|
|
226
|
+
errors.length = 0;
|
|
227
|
+
},
|
|
228
|
+
};
|
|
229
|
+
}
|
|
230
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/benchmark/scenarios/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAE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C;YACJ,CAAC;YAED,OAAO;gBACL,YAAY,EAAE,IAAI;gBAClB,KAAK;gBACL,OAAO;gBACP,UAAU;gBACV,YAAY;gBACZ,MAAM,EAAE,MAAM,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC,SAAS;aACpD,CAAC;QACJ,CAAC;QAED,KAAK,CAAC,QAAQ;YACZ,MAAM,CAAC,MAAM,GAAG,CAAC,CAAC;QACpB,CAAC;KACF,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Statistical Functions for Scientific Benchmarks
|
|
3
|
+
*
|
|
4
|
+
* Pure functions for calculating:
|
|
5
|
+
* - Descriptive statistics (mean, median, percentile)
|
|
6
|
+
* - Dispersion measures (variance, standard deviation)
|
|
7
|
+
* - Confidence intervals
|
|
8
|
+
* - Hypothesis testing (Welch's t-test)
|
|
9
|
+
* - Effect size (Cohen's d)
|
|
10
|
+
*
|
|
11
|
+
* All functions are designed to be accurate, efficient, and safe.
|
|
12
|
+
*/
|
|
13
|
+
/**
|
|
14
|
+
* Custom error class for statistics-related errors
|
|
15
|
+
*/
|
|
16
|
+
export declare class StatisticsError extends Error {
|
|
17
|
+
constructor(message: string);
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Calculate arithmetic mean of an array
|
|
21
|
+
*
|
|
22
|
+
* @param values - Array of numbers
|
|
23
|
+
* @returns The arithmetic mean
|
|
24
|
+
* @throws StatisticsError if array is empty or contains non-finite values
|
|
25
|
+
*/
|
|
26
|
+
export declare function mean(values: number[]): number;
|
|
27
|
+
/**
|
|
28
|
+
* Calculate median of an array
|
|
29
|
+
*
|
|
30
|
+
* @param values - Array of numbers
|
|
31
|
+
* @returns The median value
|
|
32
|
+
* @throws StatisticsError if array is empty
|
|
33
|
+
*/
|
|
34
|
+
export declare function median(values: number[]): number;
|
|
35
|
+
/**
|
|
36
|
+
* Calculate percentile using linear interpolation
|
|
37
|
+
*
|
|
38
|
+
* @param values - Array of numbers
|
|
39
|
+
* @param p - Percentile to calculate (0-100)
|
|
40
|
+
* @returns The percentile value
|
|
41
|
+
* @throws StatisticsError if array is empty or percentile is out of range
|
|
42
|
+
*/
|
|
43
|
+
export declare function percentile(values: number[], p: number): number;
|
|
44
|
+
/**
|
|
45
|
+
* Calculate variance of an array
|
|
46
|
+
*
|
|
47
|
+
* @param values - Array of numbers
|
|
48
|
+
* @param sample - If true, calculate sample variance (n-1 denominator); default is population variance
|
|
49
|
+
* @returns The variance
|
|
50
|
+
* @throws StatisticsError if array is empty or too small for sample variance
|
|
51
|
+
*/
|
|
52
|
+
export declare function variance(values: number[], sample?: boolean): number;
|
|
53
|
+
/**
|
|
54
|
+
* Calculate standard deviation of an array
|
|
55
|
+
*
|
|
56
|
+
* @param values - Array of numbers
|
|
57
|
+
* @param sample - If true, calculate sample standard deviation
|
|
58
|
+
* @returns The standard deviation
|
|
59
|
+
* @throws StatisticsError if array is empty or too small for sample SD
|
|
60
|
+
*/
|
|
61
|
+
export declare function standardDeviation(values: number[], sample?: boolean): number;
|
|
62
|
+
/**
|
|
63
|
+
* Result of confidence interval calculation
|
|
64
|
+
*/
|
|
65
|
+
export interface ConfidenceIntervalResult {
|
|
66
|
+
mean: number;
|
|
67
|
+
lower: number;
|
|
68
|
+
upper: number;
|
|
69
|
+
confidenceLevel: number;
|
|
70
|
+
marginOfError: number;
|
|
71
|
+
standardError: number;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Calculate confidence interval using t-distribution
|
|
75
|
+
*
|
|
76
|
+
* @param values - Array of sample values
|
|
77
|
+
* @param confidenceLevel - Confidence level (0 < level < 1), e.g., 0.95 for 95% CI
|
|
78
|
+
* @returns ConfidenceIntervalResult with mean, lower, upper bounds
|
|
79
|
+
* @throws StatisticsError if array has less than 2 elements or invalid confidence level
|
|
80
|
+
*/
|
|
81
|
+
export declare function confidenceInterval(values: number[], confidenceLevel: number): ConfidenceIntervalResult;
|
|
82
|
+
/**
|
|
83
|
+
* Result of Welch's t-test
|
|
84
|
+
*/
|
|
85
|
+
export interface WelchTTestResult {
|
|
86
|
+
tStatistic: number;
|
|
87
|
+
pValue: number;
|
|
88
|
+
degreesOfFreedom: number;
|
|
89
|
+
significant: boolean;
|
|
90
|
+
alpha: number;
|
|
91
|
+
meanDifference: number;
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Perform Welch's t-test for two independent samples
|
|
95
|
+
*
|
|
96
|
+
* Welch's t-test is more robust than Student's t-test when
|
|
97
|
+
* variances are unequal between groups.
|
|
98
|
+
*
|
|
99
|
+
* @param groupA - First sample
|
|
100
|
+
* @param groupB - Second sample
|
|
101
|
+
* @param alpha - Significance level (default 0.05)
|
|
102
|
+
* @returns WelchTTestResult with test statistics and significance
|
|
103
|
+
* @throws StatisticsError if either group has less than 2 elements
|
|
104
|
+
*/
|
|
105
|
+
export declare function welchTTest(groupA: number[], groupB: number[], alpha?: number): WelchTTestResult;
|
|
106
|
+
/**
|
|
107
|
+
* Calculate Cohen's d effect size
|
|
108
|
+
*
|
|
109
|
+
* Cohen's d measures the standardized difference between two means.
|
|
110
|
+
* Guidelines: |d| < 0.2 negligible, 0.2-0.5 small, 0.5-0.8 medium, > 0.8 large
|
|
111
|
+
*
|
|
112
|
+
* @param groupA - First sample
|
|
113
|
+
* @param groupB - Second sample
|
|
114
|
+
* @returns Cohen's d (positive if A > B, negative if A < B)
|
|
115
|
+
* @throws StatisticsError if either group has less than 2 elements
|
|
116
|
+
*/
|
|
117
|
+
export declare function cohensD(groupA: number[], groupB: number[]): number;
|
|
118
|
+
/**
|
|
119
|
+
* Interpret Cohen's d effect size
|
|
120
|
+
*
|
|
121
|
+
* @param d - Cohen's d value
|
|
122
|
+
* @returns String interpretation
|
|
123
|
+
*/
|
|
124
|
+
export declare function interpretEffectSize(d: number): string;
|
|
125
|
+
//# sourceMappingURL=statistics.d.ts.map
|
|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