Skip to content

fix: /recall entity/category post-filter is inefficient #663

Description

@ajianaz

Summary

/recall entity/category filters (main.rs:732-759) are post-filters in Rust AFTER semantic search. This means:

  1. Fetches up to limit*10 results (max 200)
  2. Rust iterates all results checking metadata
  3. Non-matching results discarded

A memory matching entity filter perfectly might be excluded if not in top 200 by similarity.

Proposed Fix

Push entity/category filter into SQL query layer before scoring.

Acceptance Criteria

Functional

  • Entity/category filter applied at SQL level, not Rust post-filter
  • No 10x fetch amplification
  • Correct results for low-similarity but matching memories

Verification (CMO can run without reading code)

  • curl POST /recall {"query":"launch","entity":"drawover"} → returns drawover memories even if embedding similarity is low
  • curl POST /recall {"query":"launch","entity":"nonexistent"} → returns empty results (no entity match)
  • Compare POST /recall {"query":"generic","entity":"drawover"} results before and after fix → same or more accurate results
  • Recall time with entity filter < 50ms (vs current ~200ms with 10x amplification)

Edge cases

  • Entity filter on memory with no entity metadata → memory excluded (correct behavior)
  • Multiple memories same entity → all returned (not just top-1)

Tests

  • Unit: entity filter at SQL level returns correct subset
  • Benchmark: entity-filtered recall < 50ms

Priority

Low — correctness issue for edge cases.

Dependencies

Partially addressed by #655 (metadata storage) and #656 (DB indexes).

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingpriority:lowFix when convenientscope:apiHTTP server / API layer

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions