This repository was archived by the owner on Jun 3, 2026. It is now read-only.
Repository navigation
feat: make similarity thresholds configurable for judge and temporal search #213
Merged
ved015
merged 9 commits into
XortexAI:main
from
Pratyush426:feat/configurable-similarity-thresholds
Jun 1, 2026
Merged
Changes from 1 commit
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
5bab290
feat: make similarity thresholds configurable for judge and temporal …
Pratyush426 be6c71d
feat: enforce boundary constraints and dynamic settings evaluation fo…
Pratyush426 d092481
test: refactor threshold tests to use pytest monkeypatch fixture
Pratyush426 33388cd
docs: clarify asymmetric similarity threshold validation bounds
Pratyush426 402f05d
refactor: move settings import to module level in neo4j_client.py
Pratyush426 71c4607
refactor: remove added comments from code
Pratyush426 6ba1d9f
remove test file
ved015 a3839d3
test: bypass LLM API-key verification in settings boundary tests
Pratyush426 671705c
remove test file
ved015 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,76 @@ | ||
| import sys | ||
| import types | ||
|
|
||
| # Mock the neo4j package to allow execution without global environment installation | ||
| neo4j_mock = types.ModuleType("neo4j") | ||
| neo4j_mock.GraphDatabase = object | ||
| sys.modules.setdefault("neo4j", neo4j_mock) | ||
|
|
||
| import pytest | ||
| from src.config import settings | ||
| from src.agents.judge import _has_summary_judge_candidates, _deterministic_summary_add | ||
| from src.storage.base import SearchResult | ||
| from src.graph.neo4j_client import Neo4jClient | ||
|
|
||
|
|
||
| def test_summary_judge_respects_custom_settings(): | ||
| original_threshold = settings.summary_judge_similarity_threshold | ||
| try: | ||
| # Match with a score of 0.35 | ||
| matches = { | ||
| "test item": [ | ||
| SearchResult(id="1", content="similar text", score=0.35, metadata={}) | ||
| ] | ||
| } | ||
|
|
||
| # Default is 0.4, so score of 0.35 should NOT match | ||
| settings.summary_judge_similarity_threshold = 0.4 | ||
| assert not _has_summary_judge_candidates(matches) | ||
|
|
||
| # If we configure it to 0.3, a score of 0.35 SHOULD match | ||
| settings.summary_judge_similarity_threshold = 0.3 | ||
| assert _has_summary_judge_candidates(matches) | ||
|
|
||
| # Test deterministic addition reason string includes threshold | ||
| settings.summary_judge_similarity_threshold = 0.55 | ||
| result = _deterministic_summary_add(["new summary"]) | ||
| assert len(result.operations) == 1 | ||
| assert "0.55" in result.operations[0].reason | ||
|
|
||
| finally: | ||
| # Restore settings | ||
| settings.summary_judge_similarity_threshold = original_threshold | ||
|
ved015 marked this conversation as resolved.
Resolved
greptile-apps[bot] marked this conversation as resolved.
Resolved
|
||
|
|
||
|
|
||
| def test_neo4j_client_respects_custom_settings(monkeypatch): | ||
| original_threshold = settings.temporal_search_similarity_threshold | ||
| try: | ||
| settings.temporal_search_similarity_threshold = 0.45 | ||
|
|
||
| # Instantiate Neo4jClient without real connections | ||
| client = Neo4jClient(uri="bolt://localhost:7687", username="neo4j", password="password") | ||
|
|
||
| # Mock embedding function | ||
| client._embedding_fn = lambda text: [0.1, 0.2] | ||
|
|
||
| # Mock session & driver behaviour so query does not hit a real Neo4j server | ||
| class MockSession: | ||
| def __enter__(self): | ||
| return self | ||
|
|
||
| def __exit__(self, exc_type, exc_val, exc_tb): | ||
| pass | ||
|
|
||
| def run(self, query, **params): | ||
| # Verify that the similarity_threshold parameter passed to the query | ||
| # is indeed custom loaded from settings.temporal_search_similarity_threshold | ||
| assert params["similarity_threshold"] == 0.45 | ||
| return [] | ||
|
|
||
| monkeypatch.setattr(client, "_session", lambda: MockSession()) | ||
|
|
||
| # Trigger search without specifying similarity_threshold explicitly | ||
| client.search_events_by_embedding(user_id="user-1", query_text="yesterday I did VOS") | ||
|
|
||
| finally: | ||
| settings.temporal_search_similarity_threshold = original_threshold | ||
|
ved015 marked this conversation as resolved.
Resolved
|
||
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.