Self-evolving Context Database for AI Agents. Unify Agent Memory, Knowledge RAG and Skills.
Python agent-contextagent-memoryagent-pluginsagentic-ragcontext-databasedsh-pluginknowledge-basememorymemory-managementself-evolvingvector-database
fix(language): ignore bare import paths during detection (#4543)
chenyu7b0482576cc1
diff --git a/openviking/session/memory/utils/language.py b/openviking/session/memory/utils/language.pyindex 7b57c668a..edc325bcc 100644--- a/openviking/session/memory/utils/language.py+++ b/openviking/session/memory/utils/language.py@@ -21,7 +21,12 @@ _JAPANESE_KANA_MIN_CHARS = 3_STRONG_DOMINANT_MIN_CHARS = 10_STRONG_DOMINANT_RATIO = 0.95_PRIMARY_LANGUAGES = {"zh-CN", "en"}-_URI_LANGUAGE_NOISE_RE = re.compile(r"\b(?:viking|https?)://[^\s<>\]\)\"']+")+# Bare import paths are machine tokens too: repeated .com domains otherwise+# count as the Portuguese stopword "com" in code skeletons.+_URI_LANGUAGE_NOISE_RE = re.compile(+ r"\b(?:(?:viking|https?)://|(?:[a-zA-Z0-9-]+\.)+[a-zA-Z]{2,}/)"+ r"[^\s<>\]\)\"'`]+"+)_LATIN_STOPWORDS = {"en": set(@@ -373,7 +378,7 @@ def resolve_output_language_from_text(def strip_language_detection_noise(text: str) -> str:- """Remove URI-like machine tokens that should not affect output language."""+ """Remove URIs and bare domain paths that should not affect output language."""return _URI_LANGUAGE_NOISE_RE.sub(" ", text or "")diff --git a/tests/storage/test_semantic_processor_language.py b/tests/storage/test_semantic_processor_language.pyindex 7861f48a0..2dd284cf4 100644--- a/tests/storage/test_semantic_processor_language.py+++ b/tests/storage/test_semantic_processor_language.py@@ -185,6 +185,47 @@ class TestLanguageFlow:class TestOverviewGenerationFlow:"""目录概述生成流程测试。"""+ @pytest.mark.asyncio+ @pytest.mark.parametrize(+ "description,override,expected_language",+ [+ ("", "", "en"),+ ("这是用于查询任务状态和统计运行时间的客户端代码。", "", "zh-CN"),+ (+ "Este documento descreve as preferências do usuário e o projeto para completar.",+ "",+ "pt",+ ),+ ("", "zh-CN", "zh-CN"),+ ],+ )+ async def test_import_paths_do_not_set_overview_language(+ self, description, override, expected_language+ ):+ from openviking.storage.queuefs.semantic_processor import SemanticProcessor++ imports = [f'"github.com/example/module{index}"' for index in range(6)]+ skeleton = "package client\nimport (\n" + "\n".join(imports) + "\n)\nfunc NewClient()"+ config = MagicMock()+ config.output_language_override = override+ config.semantic.max_overview_prompt_chars = 60_000+ config.semantic.overview_batch_size = 50+ config.vlm.get_completion_async = AsyncMock(return_value="# client\nClient overview.")++ with patch(+ "openviking.storage.queuefs.semantic_processor.get_openviking_config",+ return_value=config,+ ):+ await SemanticProcessor()._generate_overview(+ "viking://resources/example/client",+ [{"name": "client.go", "summary": description + "\n" + skeleton}],+ [],+ )++ prompt = config.vlm.get_completion_async.call_args.args[0]+ assert f"Output Language: {expected_language}" in prompt+ assert all(path in prompt for path in imports)+@pytest.mark.parametrize("lang,file_summaries",[@@ -265,6 +306,7 @@ class TestOverviewGenerationFlow:assert "**Quick Navigation** (H2)" not in promptassert "**Detailed Description** (H2)" not in prompt+class LanguageAwareMockVLM:"""语言感知的 MockVLM,根据 prompt 中的 Output Language 返回对应语言的响应。"""