feat: make similarity thresholds configurable for judge and temporal search#213
Conversation
There was a problem hiding this comment.
Code Review
This pull request makes similarity thresholds configurable by introducing summary_judge_similarity_threshold and temporal_search_similarity_threshold settings, updating the judge agent and Neo4j client to use them, and adding corresponding unit tests. Feedback suggests avoiding module-level evaluation of the judge threshold to prevent stale values, adding validation constraints (ge/le) to the Pydantic fields, and refactoring tests to use pytest's monkeypatch fixture instead of manual try...finally blocks.
|
| Filename | Overview |
|---|---|
| src/config/settings.py | Adds two new validated threshold fields; intentional asymmetry in lower bounds (0.0 vs -1.0) is appropriate given their distinct semantic domains. |
| src/agents/judge.py | Removes the module-level frozen constant and consistently reads the live settings value in all three call sites (_has_summary_judge_candidates, _filter_matches_by_threshold, _deterministic_summary_add). |
| src/graph/neo4j_client.py | Converts similarity_threshold to Optional[float] with settings fallback; import correctly placed at module level. |
Flowchart
%%{init: {'theme': 'neutral'}}%%
flowchart TD
S[Settings singleton] -->|summary_judge_similarity_threshold| HA[_has_summary_judge_candidates]
S -->|summary_judge_similarity_threshold| FM[_filter_matches_by_threshold]
S -->|summary_judge_similarity_threshold| DA[_deterministic_summary_add]
S -->|temporal_search_similarity_threshold| NE[Neo4jClient.search_events_by_embedding]
HA -->|no candidates| DA
HA -->|candidates exist| FM
FM --> LLM[LLM judge call]
DA --> RET1[Return deterministic ADD]
LLM --> RET2[Return JudgeResult]
NE --> RET3[Return matching events]
Reviews (7): Last reviewed commit: "remove test file" | Re-trigger Greptile
|
hi @Pratyush426 thank you for the contribution will review it but please resolve all the conversation and leave comment on them it makes us easy to track for future PR's |
|
@Pratyush426 please revert the last commit its not needed i will be taaking care of the failing CI myself and please remove the comments from your changes rest looks fine |
|
Once you are done with this please ping me i will do a final review and merge |
2c41817 to
71c4607
Compare
|
@Pratyush426 please stop adding new commits i have to run the workflow again and again now please dont push anything i will do a final review and take care myself |
|
Apologies for the multiple pushes. I will not push anything else to the branch. The codebase and test suite are completely clean and ready for your final review whenever you are ready. Thank you. |
|
@Pratyush426 thank you for your contribution keep on raising such fruitful PR's |
|
Thanks for merging this. I really enjoyed working on the codebase and collaborating on the review process. I saw that you are hiring Founding Software Engineer Interns (via your recent LinkedIn post) and I have submitted my application. Given my familiarity with the XMem codebase and my interest in memory architectures, I would love to be considered. linkedin post: https://www.linkedin.com/posts/hiring-softwareengineering-internship-share-7466563297442643968-n8gZ/?utm_source=share&utm_medium=member_desktop&rcm=ACoAAEep3lUBYeU3eSvDkxRCTzCExOlteRECksw |
|
Sure thank you for your interest please fill the form we will have a look |

Context
Currently, the cosine similarity thresholds used for summary memory updates in
JudgeAgent(0.4) and temporal event search inNeo4jClient(0.3) are statically hardcoded. This prevents adjustability of the memory retrieval layer sensitivity when adopting custom or dynamic embedding configurations (e.g., 384-dimensional FastEmbed, 768-dimensional Gemini, or 1536-dimensional OpenAI embeddings), which naturally produce different similarity distributions.Changes
summary_judge_similarity_threshold(default0.4) andtemporal_search_similarity_threshold(default0.3) settings usingpydantic-settingsinsrc/config/settings.py.SUMMARY_JUDGE_SIMILARITY_THRESHOLD,_has_summary_judge_candidates, and_deterministic_summary_addinsrc/agents/judge.pyto read dynamically from settings, ensuring generated reasons output custom values.search_events_by_embeddinginsrc/graph/neo4j_client.pyto fallback tosettings.temporal_search_similarity_thresholdwhen no override parameter is specified.tests/test_configurable_thresholds.pyusing isolated, mocked connection wrappers.Testing Proof
python -m pytest tests/test_deterministic_memory_layer.py(5 passed)python -m pytest tests/test_configurable_thresholds.py(2 passed)