.maestro/playbooks/Wizard-2026-02-22/2026-02-22-LoCoMo-Eval/LOCOMO-EVAL-03.md
This phase builds the question-answering pipeline that searches claude-mem for relevant context and uses Opus 4.6 to generate answers. For each LoCoMo QA question, the pipeline retrieves observations from the ingested conversation, formats them as context with category-specific prompting, and calls Opus 4.6 for an extractive answer. All calls are instrumented with latency and token tracking for production-readiness comparison against Mem0's published metrics (p95 latency 1.44s, ~1,764 tokens/query). A prototype run on one conversation's questions validates the pipeline end-to-end.
Build search retrieval module: (completed 2026-02-26 — created evals/locomo/src/qa/searcher.ts with searchForContext, formatSearchResultsAsContext, buildContextWindow; reuses WorkerClient from ingestion layer; observation-boundary-aware truncation)
evals/locomo/src/qa/searcher.tsevals/locomo/src/ingestion/worker-client.ts for search API accesssearchForContext(question: string, project: string, limit: number) — searches claude-mem observations using the worker client's search method, scoped to the conversation's project. Returns { results, search_latency_ms } where search_latency_ms is measured from the worker client's instrumented search methodformatSearchResultsAsContext(searchResults) — concatenates observation titles, facts, and narratives from search results into a single context string, with clear section separators between observationsbuildContextWindow(formattedContext: string, maxChars: number) — truncates context to fit within a character budget (default: 12000 chars, roughly 3000 tokens), truncating at the last complete observation boundary rather than mid-sentence Build QA prompt templates and answer generator: (completed 2026-02-26 — installed @anthropic-ai/[email protected]; created prompts.ts with QA_SYSTEM_PROMPT and buildUserPrompt with 5 category hints; created answerer.ts with answerQuestion using claude-opus-4-6, temperature=0, max_tokens=256, latency+token instrumentation)
@anthropic-ai/sdk is already in the root package.json — if not, install it with bun add @anthropic-ai/sdkevals/locomo/src/qa/prompts.tsbuildUserPrompt(question: string, context: string, category: string) — format the user message with the context block followed by the question, including a category-specific instruction hint:
evals/locomo/src/qa/answerer.tsanswerQuestion(question: string, context: string, category: string) — calls Anthropic API with model claude-opus-4-6:
answer_latency_ms from API call start to response receivedinput_tokens and output_tokens from the API response usage field{ predicted_answer: string, input_tokens: number, output_tokens: number, answer_latency_ms: number } Create and run QA prototype on one conversation: (completed 2026-02-26 — created evals/locomo/scripts/run-qa-one.ts with OpenRouter fallback auth; ran on conv-26 with 20 questions (10 temporal, 8 single-hop, 2 multi-hop); mean search latency 1165ms, mean answer latency 2032ms, ~455 tokens/question; results saved to qa-prototype-results.json)
evals/locomo/scripts/run-qa-one.tsgetQuestionsForConversation which excludes adversarial by default)"{category} | Q: {question_truncated} | Pred: {answer} | Truth: {ground_truth} | search: {search_latency_ms}ms | answer: {answer_latency_ms}ms"evals/locomo/results/qa-prototype-results.json as an array of objects with: question, category, predicted_answer, ground_truth, search_results_count, search_latency_ms, answer_latency_ms, answer_input_tokens, answer_output_tokensbun evals/locomo/scripts/run-qa-one.ts Write and run QA pipeline tests: (completed 2026-02-26 — created evals/locomo/tests/qa-pipeline.test.ts with 23 tests: formatSearchResultsAsContext (5 tests: multi-obs separators, empty array, raw text fallback, partial fields, 3-obs separators), buildContextWindow (6 tests: under-budget passthrough, boundary truncation, tight budget, zero budget, empty context, default maxChars), buildUserPrompt (7 tests: all 5 category hints, context+question inclusion, unknown category fallback), answerQuestion with mocked Anthropic client (5 tests: correct model/system/max_tokens, text extraction+trim, empty content→unanswerable, token/latency metrics, multi-block join); all 80 tests across 7 files pass)
evals/locomo/tests/qa-pipeline.test.tsformatSearchResultsAsContext correctly formats multiple observations with separatorsbuildContextWindow truncates at observation boundaries (not mid-text)buildContextWindow returns full context when under budgetbuildUserPrompt includes the correct category hint for each of the 5 categoriesbuildUserPrompt includes both the context block and the questionanswerQuestion without real API calls — verify it sends the correct model, system prompt, and max_tokensbun test evals/locomo/tests/qa-pipeline.test.ts