Skip to content

armgit / mem0

Public Imported from GitHub
0

The Memory Layer for AI Agents - Drop-in memory infrastructure for AI agents and apps. Context that persists. Built for production.

⚡️ Speed up `is_readable by` 101% in `embedchain/utils/misc.py` (#1258)

Saurabh Misra9a116830039e
diff --git a/embedchain/utils/misc.py b/embedchain/utils/misc.py
index cb7ff090e..1c2a12a1d 100644
--- a/embedchain/utils/misc.py
+++ b/embedchain/utils/misc.py
@@ -109,11 +109,11 @@ def is_readable(s):
:param s: string
:return: True if the string is more than 95% printable.
"""
- try:
- printable_ratio = sum(c in string.printable for c in s) / len(s)
- except ZeroDivisionError:
- logging.warning("Empty string processed as unreadable")
- printable_ratio = 0
+ len_s = len(s)
+ if len_s == 0:
+ return False
+ printable_chars = set(string.printable)
+ printable_ratio = sum(c in printable_chars for c in s) / len_s
return printable_ratio > 0.95 # 95% of characters are printable