Skip to content

Commit e0ddfea

Browse files
committed
🐛 Memory error cause by embedding model name with /
1 parent 08a0aba commit e0ddfea

File tree

5 files changed

+44
-2
lines changed

5 files changed

+44
-2
lines changed

backend/utils/memory_utils.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,14 @@ def build_memory_config(tenant_id: str) -> Dict[str, Any]:
2929
raise ValueError("ES_HOST must include scheme, host and port, e.g. http://host:9200")
3030
es_host = f"{parsed.scheme}://{parsed.hostname}"
3131
es_port = parsed.port
32+
# Normalize repo/name to avoid problematic characters in index names
33+
safe_repo = embed_raw["model_repo"].lower().replace(
34+
"/", "_") if embed_raw["model_repo"] else ""
35+
safe_name = embed_raw["model_name"].lower().replace("/", "_")
3236
index_name = (
33-
f"mem0_{embed_raw['model_repo'].lower()}_{embed_raw['model_name'].lower()}_{embed_raw['max_tokens']}"
37+
f"mem0_{safe_repo}_{safe_name}_{embed_raw['max_tokens']}"
3438
if embed_raw["model_repo"]
35-
else f"mem0_{embed_raw['model_name'].lower()}_{embed_raw['max_tokens']}"
39+
else f"mem0_{safe_name}_{embed_raw['max_tokens']}"
3640
)
3741

3842
# 3. Assemble final configuration

frontend/app/[locale]/knowledges/components/document/DocumentChunk.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -781,6 +781,10 @@ const DocumentChunk: React.FC<DocumentChunkProps> = ({
781781
onChange={handlePaginationChange}
782782
disabled={loading}
783783
showQuickJumper
784+
locale={{
785+
jump_to: t("document.chunk.pagination.jumpTo"),
786+
page: t("document.chunk.pagination.page"),
787+
}}
784788
showTotal={(pageTotal, range) =>
785789
t("document.chunk.pagination.range", {
786790
defaultValue: "{{start}}-{{end}} of {{total}}",

frontend/public/locales/en/common.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -583,6 +583,8 @@
583583
"document.chunk.search.document": "Docs",
584584
"document.chunk.search.chunk": "Chunk",
585585
"document.chunk.pagination.range": "{{start}}-{{end}} of {{total}}",
586+
"document.chunk.pagination.jumpTo": "Go to",
587+
"document.chunk.pagination.page": "Page",
586588

587589
"model.dialog.title": "Add Model",
588590
"model.dialog.label.type": "Model Type",

frontend/public/locales/zh/common.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -584,6 +584,8 @@
584584
"document.chunk.search.document": "文档",
585585
"document.chunk.search.chunk": "分片",
586586
"document.chunk.pagination.range": "{{start}}-{{end}} / 共 {{total}}",
587+
"document.chunk.pagination.jumpTo": "跳转到",
588+
"document.chunk.pagination.page": "",
587589

588590
"model.dialog.title": "添加模型",
589591
"model.dialog.label.type": "模型类型",

test/backend/utils/test_memory_utils.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,36 @@ def test_build_memory_config_with_custom_port(self):
318318
self.assertEqual(result["vector_store"]["config"]
319319
["collection_name"], "mem0_openai_test-embed_1536")
320320

321+
def test_build_memory_config_sanitizes_slashes_in_repo_and_name(self):
322+
"""Slash characters in repo/name are replaced with underscores in collection name"""
323+
mock_tenant_config_manager = MagicMock()
324+
mock_tenant_config_manager.get_model_config.side_effect = [
325+
{"model_name": "gpt-4", "model_repo": "azure/openai", "base_url": "https://api.example.com/v1", "api_key": "llm-key"},
326+
{"model_name": "text-embed/ada-002", "model_repo": "azure/openai", "base_url": "https://api.example.com/v1", "api_key": "embed-key", "max_tokens": 1536}
327+
]
328+
329+
mock_const = MagicMock()
330+
mock_const.ES_HOST = "http://localhost:9200"
331+
mock_const.ES_API_KEY = "test-es-key"
332+
mock_const.ES_USERNAME = "elastic"
333+
mock_const.ES_PASSWORD = "test-password"
334+
335+
model_mapping = {"llm": "llm", "embedding": "embedding"}
336+
mock_get_model_name = MagicMock()
337+
mock_get_model_name.side_effect = ["azure/openai/gpt-4", "azure/openai/text-embed/ada-002"]
338+
339+
with patch('backend.utils.memory_utils.tenant_config_manager', mock_tenant_config_manager), \
340+
patch('backend.utils.memory_utils._c', mock_const), \
341+
patch('backend.utils.memory_utils.get_model_name_from_config', mock_get_model_name), \
342+
patch('backend.utils.memory_utils.MODEL_CONFIG_MAPPING', model_mapping):
343+
344+
result = self.build_memory_config("tenant-with-slash")
345+
346+
self.assertEqual(
347+
result["vector_store"]["config"]["collection_name"],
348+
"mem0_azure_openai_text-embed_ada-002_1536",
349+
)
350+
321351
def test_build_memory_config_with_empty_model_repo(self):
322352
"""Empty model_repo yields collection name without repo segment"""
323353
mock_tenant_config_manager = MagicMock()

0 commit comments

Comments
 (0)