Skip to content

Fix period-based content splitting in external paper search cache key #213

@tnkshuuhei

Description

@tnkshuuhei

Problem

buildStableKey() and parseContent() in lib/external-paper-search.ts split content on the first period (.) to separate title from description:

function buildStableKey(fromContent: string, toContent: string): string {
  const fromTitle = fromContent.split(".")[0].trim();
  const toTitle = toContent.split(".")[0].trim();
  return `${fromTitle}${toTitle}`.trim();
}

Card titles containing periods (e.g., "Dr. Smith's Intervention", "e.g. community health programs", "U.S. education policy") are truncated incorrectly:

  • "Dr. Smith's Intervention" → "Dr"
  • "e.g. community health" → "e"

This affects:

  1. Cache keys: Truncated keys may collide or miss, though worst case is a cache miss (not incorrect results)
  2. LLM query extraction input: parseContent() feeds truncated titles to Gemini 2.5 Flash, potentially degrading search query quality

Proposed Solution

  • Use a more robust separator (e.g., the first sentence-ending period followed by a space and uppercase letter)
  • Or pass title and description as separate fields from the caller instead of concatenating with period separator
  • Or hash the full content for cache keys

Relevant Files

  • lib/external-paper-search.ts:60-75buildStableKey() and parseContent()
  • mastra/workflows/logic-model-with-evidence.ts:326-331 — Caller that concatenates title. description

Context

Identified during review of PR #194.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions