feat: vector similarity-based behavioral pattern detection#375
Merged
Conversation
Adds pattern echo detection to the distillation pipeline. After each distillation segment is created, compares its embedding against all previous segments for the same project. When a segment is similar to 2+ prior segments from different sessions (cosine >= 0.78), uses the curator LLM to extract the common behavioral pattern and create a preference knowledge entry. Detected patterns in eval: error handling conventions, ORM avoidance, const-by-default, post-implementation checklists. Also adds session recording/replay and --scenarios flag to eval harness for ~90% cheaper subsequent eval runs.
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.
Summary
Adds pattern echo detection to the distillation pipeline. When a new distillation segment has high embedding similarity to segments from previous sessions, it signals repeated user behavior. The system extracts the common pattern via LLM and creates a preference knowledge entry.
How it works
vectorSearchAllDistillations()ltm.create()dedup guard prevents duplicate entriesDetected patterns in eval
Limitations
Pattern echoes detect topically similar behaviors (same phrasing across sessions). They miss abstract behavioral patterns where the surface text varies — e.g., "always asks for tests after implementation" when the tests are for REST endpoints in one session and React components in another. These require higher-level temporal/sequential reasoning.
Files
packages/core/src/pattern-echo.ts(NEW) — detection logic, ~170 linespackages/core/src/prompt.ts—PATTERN_ECHO_SYSTEMprompt +patternEchoUser()packages/core/src/distillation.ts— hook intodistillSegment(), await when urgent