mirror of
https://github.com/mtayfur/openwebui-memory-system.git
synced 2026-01-22 06:51:01 +01:00
style(memory_system): add emoji to log messages and improve docstrings for clarity
Emojis are added to log messages for better visual distinction and quick scanning in logs, and several docstrings are introduced or improved to clarify method purposes, enhancing code readability and maintainability. Unused parameters are removed for cleaner function signatures.
This commit is contained in:
@@ -469,7 +469,7 @@ class SkipDetector:
|
|||||||
}
|
}
|
||||||
|
|
||||||
logger.info(
|
logger.info(
|
||||||
f"SkipDetector initialized with {len(self.NON_PERSONAL_CATEGORY_DESCRIPTIONS)} non-personal categories and {len(self.PERSONAL_CATEGORY_DESCRIPTIONS)} personal categories"
|
f"✅ SkipDetector initialized with {len(self.NON_PERSONAL_CATEGORY_DESCRIPTIONS)} non-personal and {len(self.PERSONAL_CATEGORY_DESCRIPTIONS)} personal categories"
|
||||||
)
|
)
|
||||||
|
|
||||||
def validate_message_size(self, message: str, max_message_chars: int) -> Optional[str]:
|
def validate_message_size(self, message: str, max_message_chars: int) -> Optional[str]:
|
||||||
@@ -650,6 +650,7 @@ class LLMRerankingService:
|
|||||||
self.memory_system = memory_system
|
self.memory_system = memory_system
|
||||||
|
|
||||||
def _should_use_llm_reranking(self, memories: List[Dict]) -> Tuple[bool, str]:
|
def _should_use_llm_reranking(self, memories: List[Dict]) -> Tuple[bool, str]:
|
||||||
|
"""Determine if LLM reranking should be used based on candidate count."""
|
||||||
if self.memory_system.valves.llm_reranking_trigger_multiplier <= 0:
|
if self.memory_system.valves.llm_reranking_trigger_multiplier <= 0:
|
||||||
return False, "LLM reranking disabled"
|
return False, "LLM reranking disabled"
|
||||||
|
|
||||||
@@ -670,7 +671,6 @@ class LLMRerankingService:
|
|||||||
user_message: str,
|
user_message: str,
|
||||||
candidate_memories: List[Dict],
|
candidate_memories: List[Dict],
|
||||||
max_count: int,
|
max_count: int,
|
||||||
emitter: Optional[Callable] = None,
|
|
||||||
) -> List[Dict]:
|
) -> List[Dict]:
|
||||||
"""Use LLM to select most relevant memories."""
|
"""Use LLM to select most relevant memories."""
|
||||||
memory_lines = self.memory_system._format_memories_for_llm(candidate_memories)
|
memory_lines = self.memory_system._format_memories_for_llm(candidate_memories)
|
||||||
@@ -709,6 +709,7 @@ CANDIDATE MEMORIES:
|
|||||||
candidate_memories: List[Dict],
|
candidate_memories: List[Dict],
|
||||||
emitter: Optional[Callable] = None,
|
emitter: Optional[Callable] = None,
|
||||||
) -> Tuple[List[Dict], Dict[str, Any]]:
|
) -> Tuple[List[Dict], Dict[str, Any]]:
|
||||||
|
"""Rerank candidate memories using LLM or return top semantic matches."""
|
||||||
start_time = time.time()
|
start_time = time.time()
|
||||||
max_injection = self.memory_system.valves.max_memories_returned
|
max_injection = self.memory_system.valves.max_memories_returned
|
||||||
|
|
||||||
@@ -731,7 +732,7 @@ CANDIDATE MEMORIES:
|
|||||||
)
|
)
|
||||||
logger.info(f"🧠 Using LLM reranking: {decision_reason}")
|
logger.info(f"🧠 Using LLM reranking: {decision_reason}")
|
||||||
|
|
||||||
selected_memories = await self._llm_select_memories(user_message, llm_candidates, max_injection, emitter)
|
selected_memories = await self._llm_select_memories(user_message, llm_candidates, max_injection)
|
||||||
|
|
||||||
if not selected_memories:
|
if not selected_memories:
|
||||||
logger.info("📭 No relevant memories after LLM analysis")
|
logger.info("📭 No relevant memories after LLM analysis")
|
||||||
@@ -1290,10 +1291,10 @@ class Filter:
|
|||||||
embedding = np.squeeze(embedding)
|
embedding = np.squeeze(embedding)
|
||||||
|
|
||||||
if embedding.ndim != 1:
|
if embedding.ndim != 1:
|
||||||
raise ValueError(f"Embedding must be 1D after squeeze, got shape {embedding.shape}")
|
raise ValueError(f"📐 Embedding must be 1D after squeeze, got shape {embedding.shape}")
|
||||||
|
|
||||||
if self._embedding_dimension and embedding.shape[0] != self._embedding_dimension:
|
if self._embedding_dimension and embedding.shape[0] != self._embedding_dimension:
|
||||||
raise ValueError(f"Embedding must have {self._embedding_dimension} dimensions, got {embedding.shape[0]}")
|
raise ValueError(f"📐 Embedding dimension mismatch: expected {self._embedding_dimension}, got {embedding.shape[0]}")
|
||||||
|
|
||||||
norm = np.linalg.norm(embedding)
|
norm = np.linalg.norm(embedding)
|
||||||
return embedding / norm if norm > 0 else embedding
|
return embedding / norm if norm > 0 else embedding
|
||||||
@@ -1391,9 +1392,10 @@ class Filter:
|
|||||||
suffix = "..." if len(scores) > max_scores_to_show else ""
|
suffix = "..." if len(scores) > max_scores_to_show else ""
|
||||||
|
|
||||||
logger.info(f"{context_label}: {len(memories)} memories | Top: {top_score:.3f} | Median: {median_score:.3f} | Lowest: {lowest_score:.3f}")
|
logger.info(f"{context_label}: {len(memories)} memories | Top: {top_score:.3f} | Median: {median_score:.3f} | Lowest: {lowest_score:.3f}")
|
||||||
logger.info(f"Scores: [{scores_str}{suffix}]")
|
logger.info(f"📈 Scores: [{scores_str}{suffix}]")
|
||||||
|
|
||||||
def _build_operation_details(self, created_count: int, updated_count: int, deleted_count: int) -> List[str]:
|
def _build_operation_details(self, created_count: int, updated_count: int, deleted_count: int) -> List[str]:
|
||||||
|
"""Build formatted operation detail strings for status messages."""
|
||||||
operations = [
|
operations = [
|
||||||
(created_count, "📝 Created"),
|
(created_count, "📝 Created"),
|
||||||
(updated_count, "✏️ Updated"),
|
(updated_count, "✏️ Updated"),
|
||||||
@@ -1409,6 +1411,7 @@ class Filter:
|
|||||||
return f"{cache_type}_{user_id}"
|
return f"{cache_type}_{user_id}"
|
||||||
|
|
||||||
def format_current_datetime(self) -> str:
|
def format_current_datetime(self) -> str:
|
||||||
|
"""Return current UTC datetime in human-readable format."""
|
||||||
return datetime.now(timezone.utc).strftime("%A %B %d %Y at %H:%M:%S UTC")
|
return datetime.now(timezone.utc).strftime("%A %B %d %Y at %H:%M:%S UTC")
|
||||||
|
|
||||||
def _format_memories_for_llm(self, memories: List[Dict[str, Any]]) -> List[str]:
|
def _format_memories_for_llm(self, memories: List[Dict[str, Any]]) -> List[str]:
|
||||||
@@ -1426,7 +1429,7 @@ class Filter:
|
|||||||
formatted_date = parsed_date.strftime("%b %d %Y")
|
formatted_date = parsed_date.strftime("%b %d %Y")
|
||||||
line += f" [noted at {formatted_date}]"
|
line += f" [noted at {formatted_date}]"
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.warning(f"Failed to format date {record_date}: {str(e)}")
|
logger.warning(f"📅 Failed to format date {record_date}: {str(e)}")
|
||||||
line += f" [noted at {record_date}]"
|
line += f" [noted at {record_date}]"
|
||||||
memory_lines.append(line)
|
memory_lines.append(line)
|
||||||
return memory_lines
|
return memory_lines
|
||||||
|
|||||||
Reference in New Issue
Block a user