Skip to content
12 changes: 7 additions & 5 deletions src/agents/judge.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
OperationType,
)
from src.storage.base import BaseVectorStore, SearchResult
from src.config import settings


# ---------------------------------------------------------------------------
Expand Down Expand Up @@ -87,13 +88,13 @@ def _format_similar_block(
return "\n".join(lines)


SUMMARY_JUDGE_SIMILARITY_THRESHOLD = 0.4


def _has_summary_judge_candidates(
matches_per_item: Dict[str, List[SearchResult]],
threshold: float = SUMMARY_JUDGE_SIMILARITY_THRESHOLD,
threshold: Optional[float] = None,
) -> bool:
if threshold is None:
threshold = settings.summary_judge_similarity_threshold
for matches in matches_per_item.values():
for match in matches:
if match.score >= threshold:
Expand All @@ -112,11 +113,12 @@ def _filter_matches_by_threshold(


def _deterministic_summary_add(items_strings: List[str], confidence: float = 0.8) -> JudgeResult:
threshold = settings.summary_judge_similarity_threshold
operations = [
Operation(
type=OperationType.ADD,
content=item,
reason="No similar summary at or above 0.4 — defaulting to ADD.",
reason=f"No similar summary at or above {threshold} — defaulting to ADD.",
)
for item in items_strings
if str(item).strip()
Expand Down Expand Up @@ -196,7 +198,7 @@ async def arun(self, state: Dict[str, Any]) -> JudgeResult:
if domain == JudgeDomain.SUMMARY:
matches_per_item = _filter_matches_by_threshold(
matches_per_item,
SUMMARY_JUDGE_SIMILARITY_THRESHOLD,
settings.summary_judge_similarity_threshold,
)

# 3. Build the prompt
Expand Down
12 changes: 12 additions & 0 deletions src/config/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,18 @@ class Settings(BaseSettings):
default=0.4,
description="LLM temperature for generation"
)
summary_judge_similarity_threshold: float = Field(
default=0.4,
ge=0.0,
le=1.0,
description="Threshold score for the Judge to match summary memories"
)
temporal_search_similarity_threshold: float = Field(
default=0.3,
ge=-1.0,
le=1.0,
description="Minimum cosine similarity threshold score for Neo4j temporal search"
)
Comment thread
ved015 marked this conversation as resolved.
Comment thread
greptile-apps[bot] marked this conversation as resolved.
llm_timeout_seconds: float = Field(
default=45.0,
description="Per-agent LLM call timeout in seconds",
Expand Down
6 changes: 5 additions & 1 deletion src/graph/neo4j_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
from neo4j import GraphDatabase

from src.graph.schema import GraphSchema
from src.config import settings

logger = logging.getLogger("xmem.graph.neo4j")

Expand Down Expand Up @@ -250,7 +251,7 @@ def search_events_by_embedding(
user_id: str,
query_text: str,
top_k: int = 1,
similarity_threshold: float = 0.3,
similarity_threshold: Optional[float] = None,
) -> List[Dict[str, Any]]:
"""Semantic search over event embeddings stored on HAS_EVENT relationships.

Expand All @@ -263,6 +264,9 @@ def search_events_by_embedding(
``similarity_score`` is raw cosine in [-1, 1] (matches the previous
dot-product semantics, which assumed unit-normalised embeddings).
"""
if similarity_threshold is None:
similarity_threshold = settings.temporal_search_similarity_threshold
Comment thread
greptile-apps[bot] marked this conversation as resolved.

if not self._embedding_fn:
logger.warning("No embedding function — cannot search by embedding.")
return []
Expand Down
Loading