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(storage): sanitize persisted search tags on index writes (#5862)
Xinmin Zeng2d43f20ca6c9
diff --git a/docs/en/api/06-retrieval.md b/docs/en/api/06-retrieval.mdindex 4b9d402f0..ed6e2a3ce 100644--- a/docs/en/api/06-retrieval.md+++ b/docs/en/api/06-retrieval.md@@ -181,6 +181,8 @@ curl -X POST http://localhost:1933/api/v1/search/find \Tags must use strict `k=v` strings. When multiple tags are provided, `find()` requires all of them; the example above only returns contexts whose explicit retrieval tags contain both `env=prod` and `team=search`.+Legacy invalid stored tags are discarded when a full index record is written or an explicit tag field is updated. Reads filter invalid tags without changing storage. To repair a known affected file or directory without re-embedding or replacing its valid tags, call `POST /api/v1/content/set_tags` with `{"uri": "<affected-uri>", "tags": [], "mode": "append"}`. For directories, add `"recursive": true` only when descendants should also be repaired. Bare values such as `default` are removed, not assigned an inferred key.+**Python SDK**```pythondiff --git a/docs/zh/api/06-retrieval.md b/docs/zh/api/06-retrieval.mdindex 96d9320ad..55f4b9ad9 100644--- a/docs/zh/api/06-retrieval.md+++ b/docs/zh/api/06-retrieval.md@@ -181,6 +181,8 @@ curl -X POST http://localhost:1933/api/v1/search/find \Tags 必须使用严格的 `k=v` 字符串。传入多个 tags 时,`find()` 会要求全部命中;上面的例子只返回显式检索标签同时包含 `env=prod` 和 `team=search` 的上下文。+完整索引记录写回或显式标签字段更新时,会丢弃存储中的遗留非法标签。读取只过滤非法标签,不修改存储。如需修复已知受影响的文件或目录,同时保留合法标签且不重新生成向量,可调用 `POST /api/v1/content/set_tags`,请求体为 `{"uri": "<affected-uri>", "tags": [], "mode": "append"}`。仅在需要同时修复目录后代时添加 `"recursive": true`。`default` 等裸值会被移除,不会通过猜测键名进行转换。+**Python SDK**```pythondiff --git a/openviking/storage/viking_vector_index_backend.py b/openviking/storage/viking_vector_index_backend.pyindex 33452dba0..067d61d1a 100644--- a/openviking/storage/viking_vector_index_backend.py+++ b/openviking/storage/viking_vector_index_backend.py@@ -42,7 +42,11 @@ from openviking.storage.vectordb.collection.collection import Collectionfrom openviking.storage.vectordb.collection.result import UpdateResultfrom openviking.storage.vectordb.utils.logging_init import init_cpp_loggingfrom openviking.storage.vectordb_adapters import create_collection_adapter-from openviking.utils.tags import merge_search_tags, preserve_memory_type_tag+from openviking.utils.tags import (+ merge_search_tags,+ normalize_search_tags,+ preserve_memory_type_tag,+)from openviking.utils.time_decay import parse_duration_msfrom openviking.utils.time_utils import get_current_timestampfrom openviking_cli.exceptions import InvalidArgumentError@@ -380,6 +384,11 @@ class _SingleAccountBackend:payload = {k: v for k, v in data.items() if v is not None}filtered = self._filter_known_fields(payload)result = {k: v for k, v in filtered.items() if v is not None}+ # Full-record writes must not carry legacy invalid tags through a merge.+ if "search_tags" in result:+ result["search_tags"] = normalize_search_tags(+ result["search_tags"], discard_invalid=True+ )# Ensure text fields required by the schema are present (even if empty).# VikingDB requires all schema-defined fields in upsert data.@@ -416,6 +425,10 @@ class _SingleAccountBackend:payload = self._filter_known_fields({key: value for key, value in data.items() if value is not None})+ if "search_tags" in payload:+ payload["search_tags"] = normalize_search_tags(+ payload["search_tags"], discard_invalid=True+ )if self._adapter.USE_CONTENT_FIELD:content = payload.get("content")if isinstance(content, (str, bytes)):diff --git a/tests/api_test/filesystem/test_fs_cp.py b/tests/api_test/filesystem/test_fs_cp.pyindex 0373b35f8..b99ec2a17 100644--- a/tests/api_test/filesystem/test_fs_cp.py+++ b/tests/api_test/filesystem/test_fs_cp.py@@ -95,6 +95,11 @@ class TestFsCp:without_recursive = api_client.fs_cp(source, target)assert without_recursive.status_code == 400, without_recursive.text+ # Request-scoped write completion can precede ancestor refreshes.+ # Copy needs a lease on the whole source tree, so settle those first.+ settled = api_client.system_wait(timeout=30)+ assert settled.status_code == 200, settled.text+copied = api_client.fs_cp(source, target, recursive=True)assert copied.status_code == 200, copied.textassert api_client.fs_read(f"{target}/nested/child.md").status_code == 200