[schemas] recency-boosted match_thoughts RPC#231
Open
txcfi-scott wants to merge 1 commit intoNateBJones-Projects:mainfrom
Open
[schemas] recency-boosted match_thoughts RPC#231txcfi-scott wants to merge 1 commit intoNateBJones-Projects:mainfrom
txcfi-scott wants to merge 1 commit intoNateBJones-Projects:mainfrom
Conversation
Installs match_thoughts_recency alongside the core match_thoughts RPC.
Blends cosine similarity with an exponential recency decay:
recency_factor = exp(-age_days / half_life_days)
final_score = similarity * (1 - recency_weight)
+ recency_factor * recency_weight
Defaults (recency_weight = 0) reproduce the behavior of match_thoughts
exactly, so installation is side-effect-free for existing callers.
Threshold is applied on raw cosine similarity before the blend.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What it does
Adds a new RPC,
match_thoughts_recency, alongside the corematch_thoughtsfunction from the getting-started guide. It accepts the same arguments plus two new optional parameters —recency_weightandhalf_life_days— and returns the same columns. Ranking is a blend of cosine similarity and an exponentially-decaying recency factor.The original
match_thoughtsis not replaced. Callers opt into the new variant by name.Why it matters
Pure cosine similarity returns ancient thoughts ranked high whenever they happen to be vector-nearest. For a long-lived evergreen personal brain that is fine — old high-quality notes should still surface. But for an active daily-context or task-tracking brain, a gentle recency preference produces visibly better results. Baking that preference into the core function would be disruptive; making it a separate RPC with an opt-in weight lets each caller tune it per query.
The formula
recency_weightdefaults to0.0→ pure similarity, identical ranking tomatch_thoughts.half_life_daysdefaults to90.0→ a thought 90 days old contributes half of a brand-new thought's recency factor.[0, 1]onrecency_weightare clamped; non-positivehalf_life_daysfalls back to 90.How it stays safe
match_thoughtsRPC is untouched.CREATE OR REPLACE FUNCTION, so the file is safe to re-run.match_thoughtsbehavior exactly; installing this schema has zero effect on existing callers.DROP FUNCTION IF EXISTS match_thoughts_recency(vector(1536), float, int, jsonb, float, float);removes it cleanly.Example usage
Pure similarity (identical to
match_thoughts):Gentle recency nudge (20% weight, 90-day half-life):
Strong recency preference ("what did I capture this week about X?"):
What it requires
thoughtstable +match_thoughtsfrom the getting-started guide).No additional services. No LLM calls. No embedding regeneration.
Tested
schema.sqltwice against a fresh and a populated Supabase Open Brain. Both runs complete idempotently with no errors.match_thoughts_recencywith default arguments and confirmed results matchmatch_thoughtsrow-for-row (same rank order, same similarity values).recency_weightfrom0.0→1.0in0.1increments and confirmed the rank order shifts monotonically from pure-similarity toward pure-recency.match_threshold := 0.7andrecency_weight := 1.0, brand-new thoughts whose raw similarity is below 0.7 are correctly excluded.recency_weightoutside[0, 1]is clamped and non-positivehalf_life_daysfalls back to 90.Files touched
Only
schemas/recency-boosted-match-thoughts/— stays within the contribution scope check.Attribution
Adapted from a recency-weighted ranking variant used in a personal Open Brain deployment where the mix of evergreen notes and daily task captures made pure cosine ranking feel stale. Released here so any Open Brain user can opt in without modifying the core search function.