MCPcopy
hub / github.com/promptfoo/promptfoo / InMemoryEvaluationStore

Class InMemoryEvaluationStore

src/evaluator/inMemoryStore.ts:34–161  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

32}
33
34export class InMemoryEvaluationStore
35 implements EvaluationStore<InMemoryEvaluation, EvaluateResult>
36{
37 private readonly failedResultsByIndex: Map<string, EvaluateResult>;
38 private readonly finalResultsByIndex: Map<string, EvaluateResult>;
39
40 constructor(readonly evaluation: InMemoryEvaluation) {
41 this.failedResultsByIndex = toResultMap(evaluation.failedResults);
42 this.finalResultsByIndex = toResultMap(evaluation.finalResults);
43 if (this.failedResultsByIndex.size > 0) {
44 evaluation.resultPersistenceFailed = true;
45 }
46 this.syncFailedResults();
47 this.syncFinalResults();
48 }
49
50 get id(): string {
51 return this.evaluation.id;
52 }
53
54 get config(): Partial<UnifiedConfig> {
55 return this.evaluation.config;
56 }
57
58 get persisted(): boolean {
59 return this.evaluation.persisted;
60 }
61
62 get prompts(): CompletedPrompt[] {
63 return this.evaluation.prompts;
64 }
65
66 get results(): EvaluateResult[] {
67 return this.evaluation.results;
68 }
69
70 get resultPersistenceFailed(): boolean {
71 return this.evaluation.resultPersistenceFailed;
72 }
73
74 async appendResult(result: EvaluateResult): Promise<void> {
75 this.evaluation.results.push(result);
76 }
77
78 async appendPrompts(prompts: CompletedPrompt[]): Promise<void> {
79 this.evaluation.prompts = prompts;
80 }
81
82 hasResultPersistenceFailure(result: Pick<EvaluateResult, 'promptIdx' | 'testIdx'>): boolean {
83 return this.failedResultsByIndex.has(getResultIndexKey(result));
84 }
85
86 async readCompletedIndexPairs(options?: { excludeErrors?: boolean }): Promise<Set<string>> {
87 const completedPairs = new Set<string>();
88 for (const result of this.evaluation.results) {
89 if (options?.excludeErrors && result.failureReason === ERROR_FAILURE_REASON) {
90 continue;
91 }

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…