Foresight.Reflect.MentalModelRanking (Foresight v0.1.0)

Copy Markdown View Source

Lexical relevance ranking + limit for the reflect search_mental_models tool .

Mental models are stored as plain documents with no embeddings, so semantic ranking + staleness (is_stale) is the deferred work. Until then the tool must at least honour its query and cap results instead of dumping ALL active mental models into the agent's context. This ranks active MMs by query token overlap over title+original_text and takes the top limit; a blank query preserves input order (already external_id-ordered), and ties are stable.

Summary

Functions

Rank mental_models by lexical relevance to query, returning the top limit.

Functions

rank(mental_models, query, limit)

@spec rank([map()], String.t() | nil, non_neg_integer()) :: [map()]

Rank mental_models by lexical relevance to query, returning the top limit.

Each item may be any struct/map exposing :title and :original_text (atom or string keys). A blank/nil query preserves input order; equal-relevance ties keep input order (stable sort).