Skip to content

Self-evolving Context Database for AI Agents. Unify Agent Memory, Knowledge RAG and Skills.

fix(tags): remove charset and length restrictions (#4761)

agent230abf054d31
diff --git a/docs/en/api/06-retrieval.md b/docs/en/api/06-retrieval.md
index f39aed1bf..bd0b01ebf 100644
--- a/docs/en/api/06-retrieval.md
+++ b/docs/en/api/06-retrieval.md
@@ -58,7 +58,7 @@ The `find()` method performs pure vector similarity search for simple query scen
| image_url | str | No | None | Image query as a `data:image/...;base64,...`, `http(s)://`, or `viking://` URI. Requires a multimodal embedding model |
| target_uri | str \| List[str] | No | "" | Limit search to specific URI prefix |
| context_type | str \| List[str] | No | None | Limit results to one or more `ContextType` values: `memory`, `resource`, or `skill` |
-| tags | List[str] | No | None | Explicit retrieval tags in strict `k=v` form (lowercase letters/digits/`_`/`-`/`.`, starting with a letter or digit, key<=64, value<=128). Multiple tags are combined with AND; a result must contain every requested tag |
+| tags | List[str] | No | None | Explicit retrieval tags in strict `k=v` form. Multiple tags are combined with AND; a result must contain every requested tag |
| node_limit | int | No | None | Maximum number of results |
| score_threshold | float | No | None | Minimum relevance score threshold |
| filter | Dict | No | None | Metadata filter |
@@ -176,7 +176,7 @@ curl -X POST http://localhost:1933/api/v1/search/find \
}'
```
-Tags must use strict `k=v` strings: both key and value are non-empty, contain exactly one `=`, are made only of lowercase letters, digits, `_`, `-`, `.` and start with a letter or digit (the server trims whitespace and lowercases). The key is capped at 64 and the value at 128 characters. 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`.
+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`.
**Python SDK**
@@ -396,7 +396,7 @@ The `search()` method adds session context understanding and intent analysis cap
| session | Session | No | None | Session for context-aware search (SDK) |
| session_id | str | No | None | Session ID for context-aware search (HTTP) |
| context_type | str \| List[str] | No | None | Limit results to one or more `ContextType` values: `memory`, `resource`, or `skill` |
-| tags | List[str] | No | None | Explicit retrieval tags in strict `k=v` form (lowercase letters/digits/`_`/`-`/`.`, starting with a letter or digit, key<=64, value<=128). Multiple tags are combined with AND; a result must contain every requested tag |
+| tags | List[str] | No | None | Explicit retrieval tags in strict `k=v` form. Multiple tags are combined with AND; a result must contain every requested tag |
| node_limit | int | No | None | Maximum number of results |
| score_threshold | float | No | None | Minimum relevance score threshold |
| filter | Dict | No | None | Metadata filter |
diff --git a/docs/en/api/12-content.md b/docs/en/api/12-content.md
index df49478ca..c2ea88e34 100644
--- a/docs/en/api/12-content.md
+++ b/docs/en/api/12-content.md
@@ -491,7 +491,7 @@ Content-Disposition: attachment; filename*=UTF-8''logo.png
### set_tags()
-Set explicit `k=v` tags used by retrieval filters. Both key and value are non-empty, contain exactly one `=`, are made only of lowercase letters, digits, `_`, `-`, `.` and start with a letter or digit (the server trims whitespace and lowercases); the key is capped at 64 and the value at 128 characters, and invalid tags are rejected. `replace` replaces existing tags, while `append` adds tags. When the target is a directory, `recursive=true` applies the update to files below it.
+Set explicit `k=v` tags used by retrieval filters. `replace` replaces existing tags, while `append` adds tags. When the target is a directory, `recursive=true` applies the update to files below it.
**Python SDK**
diff --git a/docs/zh/api/06-retrieval.md b/docs/zh/api/06-retrieval.md
index 59c1c1274..169aa01b9 100644
--- a/docs/zh/api/06-retrieval.md
+++ b/docs/zh/api/06-retrieval.md
@@ -58,7 +58,7 @@ OpenViking 提供多种检索方法,包括简单的向量相似度搜索、带
| image_url | str | 否 | None | 图片查询,支持 `data:image/...;base64,...`、`http(s)://` 或 `viking://` URI;需要 multimodal embedding 模型 |
| target_uri | str \| List[str] | 否 | "" | 限制搜索范围到指定的 URI 前缀 |
| context_type | str \| List[str] | 否 | None | 限定一个或多个 `ContextType` 取值:`memory`、`resource` 或 `skill` |
-| tags | List[str] | 否 | None | 显式检索标签,必须是严格的 `k=v` 格式(小写字母/数字/`_`/`-`/`.`,以字母或数字开头,key≤64、value≤128)。多个 tags 之间是 AND 关系,结果必须同时包含所有请求的标签 |
+| tags | List[str] | 否 | None | 显式检索标签,必须是严格的 `k=v` 格式。多个 tags 之间是 AND 关系,结果必须同时包含所有请求的标签 |
| limit | int | 否 | 10 | 最大返回结果数 |
| node_limit | int | 否 | None | 可选 HTTP 别名;如果提供,会覆盖 limit |
| score_threshold | float | 否 | None | 最低相关性分数阈值 |
@@ -177,7 +177,7 @@ curl -X POST http://localhost:1933/api/v1/search/find \
}'
```
-Tags 必须使用严格的 `k=v` 字符串:key 和 value 都非空,只能有一个 `=`,仅由小写字母、数字、`_`、`-`、`.` 组成且以字母或数字开头(服务端会去空白并转小写),key 最长 64、value 最长 128 字符。传入多个 tags 时,`find()` 会要求全部命中;上面的例子只返回显式检索标签同时包含 `env=prod` 和 `team=search` 的上下文。
+Tags 必须使用严格的 `k=v` 字符串。传入多个 tags 时,`find()` 会要求全部命中;上面的例子只返回显式检索标签同时包含 `env=prod` 和 `team=search` 的上下文。
**Python SDK**
@@ -397,7 +397,7 @@ openviking find "红色海报风格" --image ./poster.png --uri "viking://resour
| session | Session | 否 | None | 用于上下文感知搜索的会话(SDK)|
| session_id | str | 否 | None | 用于上下文感知搜索的会话 ID(HTTP)|
| context_type | str \| List[str] | 否 | None | 限定一个或多个 `ContextType` 取值:`memory`、`resource` 或 `skill` |
-| tags | List[str] | 否 | None | 显式检索标签,必须是严格的 `k=v` 格式(小写字母/数字/`_`/`-`/`.`,以字母或数字开头,key≤64、value≤128)。多个 tags 之间是 AND 关系,结果必须同时包含所有请求的标签 |
+| tags | List[str] | 否 | None | 显式检索标签,必须是严格的 `k=v` 格式。多个 tags 之间是 AND 关系,结果必须同时包含所有请求的标签 |
| limit | int | 否 | 10 | 最大返回结果数 |
| node_limit | int | 否 | None | 可选 HTTP 别名;如果提供,会覆盖 limit |
| score_threshold | float | 否 | None | 最低相关性分数阈值 |
diff --git a/docs/zh/api/12-content.md b/docs/zh/api/12-content.md
index 6f877ddf3..fe2febb93 100644
--- a/docs/zh/api/12-content.md
+++ b/docs/zh/api/12-content.md
@@ -491,7 +491,7 @@ Content-Disposition: attachment; filename*=UTF-8''logo.png
### set_tags()
-设置用于检索过滤的显式 `k=v` 标签。key 和 value 都非空、只能有一个 `=`,仅由小写字母、数字、`_`、`-`、`.` 组成且以字母或数字开头(服务端会去空白并转小写),key 最长 64、value 最长 128 字符;不合规的标签会被拒绝。`replace` 替换已有标签,`append` 追加标签;对目录设置 `recursive=true` 时会更新目录下的文件。
+设置用于检索过滤的显式 `k=v` 标签。`replace` 替换已有标签,`append` 追加标签;对目录设置 `recursive=true` 时会更新目录下的文件。
**Python SDK**
diff --git a/openviking/utils/tags.py b/openviking/utils/tags.py
index a6faa5e08..c9c581ae6 100644
--- a/openviking/utils/tags.py
+++ b/openviking/utils/tags.py
@@ -5,7 +5,6 @@
from __future__ import annotations
import logging
-import re
from collections import OrderedDict
from typing import Any, Iterable
@@ -13,25 +12,12 @@ from openviking_cli.exceptions import InvalidArgumentError
logger = logging.getLogger(__name__)
-# Explicit search tags are meant to be small, enumerable business dimensions
-# (env, team, source, ...). Constrain both sides of ``k=v`` so tags stay stable
-# identifiers rather than free-form text: bounded length and a predictable
-# character set after lower-casing (no internal spaces, no ``=``).
-MAX_TAG_KEY_LENGTH = 64
-MAX_TAG_VALUE_LENGTH = 128
-MAX_TAG_LENGTH = MAX_TAG_KEY_LENGTH + 1 + MAX_TAG_VALUE_LENGTH
-_TAG_TOKEN_RE = re.compile(r"^[a-z0-9][a-z0-9_.-]*$")
-
def normalize_search_tag(tag: str) -> str:
"""Validate and normalize a single k=v search tag."""
value = str(tag).strip().lower()
if not value:
raise InvalidArgumentError("search tag must be a non-empty k=v string")
- if len(value) > MAX_TAG_LENGTH:
- raise InvalidArgumentError(
- f"invalid search tag '{tag}': exceeds max length {MAX_TAG_LENGTH}"
- )
if value.count("=") != 1:
raise InvalidArgumentError(f"invalid search tag '{tag}': expected strict k=v format")
@@ -40,19 +26,6 @@ def normalize_search_tag(tag: str) -> str:
raise InvalidArgumentError(
f"invalid search tag '{tag}': key and value must both be non-empty"
)
- if len(key) > MAX_TAG_KEY_LENGTH:
- raise InvalidArgumentError(
- f"invalid search tag '{tag}': key exceeds max length {MAX_TAG_KEY_LENGTH}"
- )
- if len(raw_value) > MAX_TAG_VALUE_LENGTH:
- raise InvalidArgumentError(
- f"invalid search tag '{tag}': value exceeds max length {MAX_TAG_VALUE_LENGTH}"
- )
- if not _TAG_TOKEN_RE.match(key) or not _TAG_TOKEN_RE.match(raw_value):
- raise InvalidArgumentError(
- f"invalid search tag '{tag}': key and value may only contain lowercase "
- "letters, digits, '_', '-', '.', and must start with a letter or digit"
- )
return f"{key}={raw_value}"
diff --git a/tests/service/test_agent_evolution_service.py b/tests/service/test_agent_evolution_service.py
index 5cc4b04c0..fd4495473 100644
--- a/tests/service/test_agent_evolution_service.py
+++ b/tests/service/test_agent_evolution_service.py
@@ -22,8 +22,9 @@ def _ctx() -> RequestContext:
@pytest.mark.asyncio
-async def test_list_trajectories_by_experience_uses_exact_scalar_filter_and_pagination():
- experience_uri = "viking://user/alice/memories/experiences/exchange.md"
[email protected]("filename", ["exchange.md", "vikingdb_fe_repo_workflows.md"])
+async def test_list_trajectories_by_experience_uses_exact_scalar_filter_and_pagination(filename):
+ experience_uri = f"viking://user/alice/memories/experiences/{filename}"
viking_fs = Mock()
viking_fs.stat = AsyncMock(return_value={"isDir": False})
vikingdb = Mock()
@@ -189,8 +190,9 @@ async def test_list_trajectories_by_experience_accepts_1000_and_paginates_all_re
@pytest.mark.asyncio
-async def test_get_experience_outcome_distribution_counts_two_tags_on_same_list_field():
- experience_uri = "viking://user/alice/memories/experiences/exchange.md"
[email protected]("filename", ["exchange.md", "vikingdb_fe_repo_workflows.md"])
+async def test_get_experience_outcome_distribution_counts_two_tags_on_same_list_field(filename):
+ experience_uri = f"viking://user/alice/memories/experiences/{filename}"
viking_fs = Mock()
viking_fs.stat = AsyncMock(return_value={"isDir": False})
vikingdb = Mock()
diff --git a/tests/unit/session/memory/test_experience_lineage.py b/tests/unit/session/memory/test_experience_lineage.py
index 876bb93dd..f5317438a 100644
--- a/tests/unit/session/memory/test_experience_lineage.py
+++ b/tests/unit/session/memory/test_experience_lineage.py
@@ -15,6 +15,7 @@ from openviking.session.memory.experience_lineage import (
from openviking.session.train.components.trajectory_analyzer import (
_trajectory_search_tags_by_uri,
)
+from openviking.utils.tags import build_search_tags_filter, merge_search_tags, normalize_search_tags
from openviking_cli.session.user_id import UserIdentifier
@@ -180,13 +181,27 @@ def test_collect_read_experience_uris_ignores_removed_dedicated_tool():
assert collect_read_experience_uris(messages, ctx=_ctx()) == []
-def test_experience_source_tag_uses_experience_uri_as_key():
- uri = "viking://user/alice/memories/experiences/无订单号换货处理.md"
-
+ "uri",
+ [
+ "viking://user/alice/memories/experiences/cfg_streaming.md",
+ "viking://user/alice/memories/experiences/无订单号换货处理.md",
+ "viking://user/alice/memories/experiences/vikingdb_fe_repo_workflows.md",
+ "viking://user/alice/memories/experiences/" + "nested/" * 40 + "workflow.md",
+ ],
+)
+def test_experience_source_tag_uses_experience_uri_as_key(uri):
tag = experience_source_tag(uri)
assert tag == f"{uri}=1"
assert tag.count("=") == 1
+ assert normalize_search_tags([tag], discard_invalid=True) == [tag]
+ assert merge_search_tags([tag], ["env=stg"]) == [tag, "env=stg"]
+ assert build_search_tags_filter([tag]) == {
+ "op": "must",
+ "field": "search_tags",
+ "conds": [tag],
+ }
def test_experience_source_tag_preserves_case_and_escapes_equals_without_collisions():
@@ -201,6 +216,7 @@ def test_experience_source_tag_preserves_case_and_escapes_equals_without_collisi
assert uppercase_tag != lowercase_tag
assert uppercase_tag.count("=") == 1
assert lowercase_tag.count("=") == 1
+ assert merge_search_tags([uppercase_tag], [lowercase_tag]) == [uppercase_tag, lowercase_tag]
def test_source_experiences_create_transient_tags_for_every_generated_trajectory():
diff --git a/tests/unit/test_search_tags_filter.py b/tests/unit/test_search_tags_filter.py
index a7b584746..a7021e119 100644
--- a/tests/unit/test_search_tags_filter.py
+++ b/tests/unit/test_search_tags_filter.py
@@ -8,8 +8,6 @@ import pytest
from openviking.server.routers.search import _resolve_search_filter
from openviking.utils import tags as tags_module
from openviking.utils.tags import (
- MAX_TAG_KEY_LENGTH,
- MAX_TAG_VALUE_LENGTH,
build_search_tags_filter,
merge_search_tags,
normalize_search_tag,
@@ -48,33 +46,31 @@ def test_search_tag_allows_dot_dash_underscore():
"tag",
[
"team=search platform", # internal space
- "team=with/slash", # unsupported char
+ "team=with/slash",
"team=值", # non-ascii
- "-team=search", # must start with letter/digit
+ "-team=search",
"team=-search",
- "te=am=search", # more than one '='
+ "team=search,platform",
+ "team,owner=search",
+ "viking://user/alice/memories/experiences/workflow.md=1",
+ "viking://user/%41lice/memories/experiences/%45xchange%3d%46low.md=1",
],
)
-def test_search_tag_rejects_disallowed_characters(tag):
- with pytest.raises(InvalidArgumentError):
- normalize_search_tag(tag)
-
-
-def test_search_tag_rejects_over_length_key():
- over_key = "k" * (MAX_TAG_KEY_LENGTH + 1)
- with pytest.raises(InvalidArgumentError):
- normalize_search_tag(f"{over_key}=v")
+def test_search_tag_accepts_special_characters(tag):
+ assert normalize_search_tag(tag) == tag
+ assert normalize_search_tags([tag], discard_invalid=True) == [tag]
-def test_search_tag_rejects_over_length_value():
- over_value = "v" * (MAX_TAG_VALUE_LENGTH + 1)
[email protected]("tag", ["", "team", "=search", "team=", "te=am=search"])
+def test_search_tag_still_requires_non_empty_kv_format(tag):
with pytest.raises(InvalidArgumentError):
- normalize_search_tag(f"team={over_value}")
+ normalize_search_tag(tag)
-def test_search_tag_accepts_boundary_lengths():
- key = "k" * MAX_TAG_KEY_LENGTH
- value = "v" * MAX_TAG_VALUE_LENGTH
[email protected]("key_length,value_length", [(64, 128), (65, 1), (4, 129), (256, 512)])
+def test_search_tag_accepts_long_keys_and_values(key_length, value_length):
+ key = "k" * key_length
+ value = "v" * value_length
assert normalize_search_tag(f"{key}={value}") == f"{key}={value}"