Evaluating Cognitive Recall: Building an LLM-as-a-Judge Test Strategy for AI Memory

LLM Judge Validation

In traditional retrieval-augmented generation (RAG) and vector search databases, quality assurance is evaluated through statistical metrics like Mean Reciprocal Rank (MRR), Recall@K, or Normalized Discounted Cumulative Gain (nDCG). While these metrics tell you which documents were retrieved, they fail to evaluate the semantic integrity and contextual utility of the recalled information.

For Spector, our open-source cognitive memory framework, we had to go further. Spector operates on a four-tier human-inspired memory hierarchy:

  • Episodic Memory: High-frequency streaming observations.
  • Semantic Memory: Abstracted, consolidated facts.
  • Temporal Chain: Chronological linking of events.
  • Hebbian Co-activation: Associative memory graphs.

When a query traverses these layers, evaluating "correctness" is a multidimensional problem. This is why we architected a automated LLM-as-a-Judge testing pipeline.


1. Why Standard Assertions Fail Cognitive Recall

Consider a user query: "Did the client approve the Q3 cloud budget?" An older, deleted budget draft might be highly similar mathematically (cosine similarity > 0.89) to the final approved budget. A traditional unit test checking vector distance would mark this as a "win".

However, recalling the outdated draft is a hallucination/drift error. A simple string match or vector distance check cannot identify that the retrieved document is factually incorrect relative to the temporal context.


2. The LLM-as-a-Judge Architecture

Our test framework runs an evaluation loop that pairs retrieved memory context with a specialized LLM evaluator acting as a Judge. The pipeline operates as follows:

graph TD A[Test Case Query] --> B[Spector Recall Pipeline] B --> C[Recalled Memory Context] D[Ground Truth Anchor] --> E[LLM Judge Prompt Builder] C --> E A --> E E --> F[LLM Judge API] F --> G{Scoring Engine} G -- Score >= Threshold --> H[Test PASS] G -- Score < Threshold --> I[Test FAIL & Log Telemetry]

3. Key Metrics Scored by the Judge

We programmatically prompt our judge models to evaluate three primary axes, returning a structured JSON response:

  1. Semantic Alignment (Score: 1-5): Measures how well the recalled memory addresses the core intent of the query, ignoring irrelevant syntactic matches.
  2. Temporal Correctness (Score: 1-5): Verifies if the recalled memory represents the active, non-superseded state of information based on temporal anchors.
  3. Factuality (Score: 0 or 1): A binary check verifying if the recalled text contains contradictions compared to the ground truth.

Example Evaluator Prompt Structure:

You are an expert QA Evaluator. Analyze the recalled memory context against the ground truth for the given query.

Query: [User Query]
Recalled Context: [Spector Output]
Ground Truth: [Factual Benchmark]

Evaluate the performance on the following schema:
{
  "semantic_alignment": 1-5,
  "temporal_correctness": 1-5,
  "factual_integrity": 0-1,
  "rationale": "Detailed engineering breakdown of why this score was assigned."
}
Respond with raw JSON only.

4. Continuous Integration and Gating

By wrapping our LLM Judge API requests in standard JUnit assertions, we block pull requests that cause semantic regression. This lets us confidently refactor optimization logic in our retrieval stage (like our SIMD-accelerated index lookups) without risking the quality of recall.

With Spector, we are proving that autonomous testing is key to building production-grade cognitive AI.