Skip to content

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

fix(vectordb): encode string IDs before hashing (#3995)

t0saki4bf438a65581
diff --git a/.github/workflows/_test_lite.yml b/.github/workflows/_test_lite.yml
index ef46de8b2..9b6d639ec 100644
--- a/.github/workflows/_test_lite.yml
+++ b/.github/workflows/_test_lite.yml
@@ -86,4 +86,5 @@ jobs:
uv run pytest -q -o addopts='' \
tests/vectordb/test_cuvs_config.py \
tests/vectordb/test_cuvs_index.py \
- tests/vectordb/test_cuvs_collection.py
+ tests/vectordb/test_cuvs_collection.py \
+ tests/vectordb/test_str_to_uint64.py
diff --git a/openviking/storage/vectordb/utils/str_to_uint64.py b/openviking/storage/vectordb/utils/str_to_uint64.py
index e25ec2134..2828874b3 100644
--- a/openviking/storage/vectordb/utils/str_to_uint64.py
+++ b/openviking/storage/vectordb/utils/str_to_uint64.py
@@ -7,4 +7,4 @@ def str_to_uint64(input_string: str) -> int:
"""
Generate a 64-bit unsigned integer hash from a string using xxHash.
"""
- return xxhash.xxh64(input_string).intdigest()
+ return xxhash.xxh64(input_string.encode("utf-8")).intdigest()
diff --git a/tests/vectordb/test_str_to_uint64.py b/tests/vectordb/test_str_to_uint64.py
new file mode 100644
index 000000000..87174b7b0
--- /dev/null
+++ b/tests/vectordb/test_str_to_uint64.py
@@ -0,0 +1,62 @@
+# Copyright (c) 2026 Beijing Volcano Engine Technology Co., Ltd.
+# SPDX-License-Identifier: AGPL-3.0
+
+import openviking.storage.vectordb.utils.str_to_uint64 as subject
+from openviking.storage.vectordb.collection.local_collection import (
+ get_or_create_local_collection,
+)
+
+
+def test_str_to_uint64_preserves_stable_utf8_hashes():
+ assert subject.str_to_uint64("abc") == 4952883123889572249
+ assert subject.str_to_uint64("部署") == 4215394785105220848
+
+
+def test_str_to_uint64_passes_utf8_bytes_to_xxhash(monkeypatch):
+ seen = []
+
+ class _Digest:
+ @staticmethod
+ def intdigest():
+ return 42
+
+ def _xxh64(value):
+ seen.append(value)
+ return _Digest()
+
+ monkeypatch.setattr(subject.xxhash, "xxh64", _xxh64)
+
+ assert subject.str_to_uint64("部署") == 42
+ assert seen == ["部署".encode("utf-8")]
+
+
+def test_local_collection_round_trips_string_primary_keys():
+ collection = get_or_create_local_collection(
+ meta_data={
+ "CollectionName": "string_pk_compat",
+ "Fields": [
+ {"FieldName": "id", "FieldType": "string", "IsPrimaryKey": True},
+ {"FieldName": "uri", "FieldType": "path"},
+ {"FieldName": "vector", "FieldType": "vector", "Dim": 4},
+ ],
+ }
+ )
+
+ inserted = collection.upsert_data(
+ [
+ {
+ "id": "部署-1",
+ "uri": "viking://resources/string-pk",
+ "vector": [1.0, 0.0, 0.0, 0.0],
+ }
+ ]
+ )
+ fetched = collection.fetch_data(["部署-1"])
+ collection.delete_data(["部署-1"])
+ missing = collection.fetch_data(["部署-1"])
+
+ assert inserted.ids == ["部署-1"]
+ assert [(item.id, item.fields["uri"]) for item in fetched.items] == [
+ ("部署-1", "viking://resources/string-pk")
+ ]
+ assert missing.ids_not_exist == ["部署-1"]