Skip to content

feat(store): inject implicit graph-linking metadata in search results via topic_key siblings #243

@Snakeblack

Description

@Snakeblack

Pre-flight Checks

  • I have searched existing issues and this is not a duplicate
  • I understand this issue needs status:approved before a PR can be opened

Problem Description / Descripción del Problema

English: When mem_search returns results, each observation is isolated — the agent has no awareness of related observations that share the same topic_key. For example, if an agent finds 'JWT Middleware' (topic: auth/jwt), it doesn't know about 'Token Rotation Bug' or 'Session Fix' that share the same topic. This forces additional manual searches to build relational context.

Español: Cuando mem_search retorna resultados, cada observación está aislada — el agente no tiene awareness de observaciones relacionadas que comparten el mismo topic_key. Esto fuerza búsquedas manuales adicionales para construir contexto relacional.

Proposed Solution / Solución Propuesta

English: Post-process search results in two layers:

  1. Store layer: New RelatedByTopicKeys() function that queries siblings by topic_key using the existing idx_obs_topic composite index (efficient, no schema migration)
  2. MCP layer: Inject related metadata as enriched text in handleSearch response:
    Related (topic 'auth/jwt'): ID 4 (JWT Middleware), ID 12 (Token Rotation Bug)

Limits: max 5 siblings per topic_key. Excludes soft-deleted observations. Filters by project + scope. No query executed when results have no topic_keys.

Español: Post-procesamiento en dos capas: (1) nueva función RelatedByTopicKeys() en store usando el índice compuesto idx_obs_topic existente, y (2) inyección de metadata relacional como texto enriquecido en handleSearch. Máximo 5 hermanos por topic_key, filtra por project+scope, excluye soft-deleted.

Affected Area

Store (new query function), MCP Server (search response enrichment)

Additional Context

  • Leverages existing idx_obs_topic(topic_key, project, scope, updated_at DESC) index
  • No schema migration needed
  • New RelatedObservation struct: {ID int64, Title string}
  • Separation of concerns: store returns pure data, handler serializes to text

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions