Fix memory empty issue (#15411)

Fix memory empty issue
This commit is contained in:
Wang Qi
2026-06-01 10:25:56 +08:00
committed by GitHub
parent e13431cdc0
commit 4972af4367

View File

@@ -13,6 +13,7 @@
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
# #
import os
import sys import sys
from typing import List from typing import List
@@ -20,8 +21,12 @@ from common import settings
from common.constants import MemoryType from common.constants import MemoryType
from common.doc_store.doc_store_base import OrderByExpr, MatchExpr from common.doc_store.doc_store_base import OrderByExpr, MatchExpr
def _es_index_prefix() -> str:
return os.environ.get("ES_INDEX_PREFIX", "").strip()
def index_name(uid: str): return f"memory_{uid}" def index_name(uid: str):
prefix = _es_index_prefix()
return f"memory_{prefix}_{uid}" if prefix else f"memory_{uid}"
class MessageService: class MessageService:
@@ -179,7 +184,13 @@ class MessageService:
@staticmethod @staticmethod
def calculate_message_size(message: dict): def calculate_message_size(message: dict):
return sys.getsizeof(message["content"]) + sys.getsizeof(message["content_embed"][0]) * len(message["content_embed"]) content_embed = message.get("content_embed")
embed_size = (
sys.getsizeof(content_embed[0]) * len(content_embed)
if content_embed is not None and len(content_embed) > 0
else 0
)
return sys.getsizeof(message.get("content", "")) + embed_size
@classmethod @classmethod
def calculate_memory_size(cls, memory_ids: List[str], uid_list: List[str]): def calculate_memory_size(cls, memory_ids: List[str], uid_list: List[str]):