chore(context): refactor for consistency, optimize formatting, and simplify logic

- Cleaned up unnecessary comments in `__all__` definitions for better readability.
- Adjusted indentation and formatting across modules for improved clarity (e.g., long lines, logical grouping).
- Simplified conditional expressions and inline comments for context scoring and ranking.
- Replaced some hard-coded values with type-safe annotations (e.g., `ClassVar`).
- Removed unused imports and ensured consistent usage across test files.
- Updated `test_score_not_cached_on_context` to clarify caching behavior.
- Improved truncation strategy logic and marker handling.
This commit is contained in:
2026-01-04 15:23:14 +01:00
parent 9e54f16e56
commit 2bea057fb1
26 changed files with 226 additions and 273 deletions

View File

@@ -116,12 +116,16 @@ class ContextCache:
# This avoids JSON serializing potentially large content strings
context_data = []
for ctx in contexts:
context_data.append({
"type": ctx.get_type().value,
"content_hash": self._hash_content(ctx.content), # Hash instead of full content
"source": ctx.source,
"priority": ctx.priority, # Already an int
})
context_data.append(
{
"type": ctx.get_type().value,
"content_hash": self._hash_content(
ctx.content
), # Hash instead of full content
"source": ctx.source,
"priority": ctx.priority, # Already an int
}
)
data = {
"contexts": context_data,
@@ -412,7 +416,7 @@ class ContextCache:
# Get Redis info
info = await self._redis.info("memory") # type: ignore
stats["redis_memory_used"] = info.get("used_memory_human", "unknown")
except Exception:
pass
except Exception as e:
logger.debug(f"Failed to get Redis stats: {e}")
return stats