You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
fix: preserve identifier types in PolarDB lightweight recall - #2551
PolarDB lightweight vector-search projections can return a numeric user ID as an already-decoded string. Decoding it again with json.loads turns it into an integer, causing TextualMemoryItem validation to fail and potentially leaving knowledge-base retrieval empty after successful ingestion.
Preserve identifier strings (including leading zeros), normalize native integer identifiers to strings, and keep JSON-quoted strings and nulls compatible. Non-identifier arrays, objects, booleans and numeric values retain their existing decoding. The identifier field set is a module-level frozenset, avoiding per-field allocations during recall. No dependency, schema or route changes.
Type of change
Bug fix (non-breaking change which fixes an issue)
How Has This Been Tested?
Unit Test: poetry run pytest tests/graph_dbs/ -q → 77 passed, 3 skipped.
Test Script Or Test Steps: make test → 1005 passed, 9 skipped; make format and changed-file pre-commit passed.
Pipeline verification: all 16 Python tests CI jobs passed on final head b1a7d5fee60c06923933550c9c9c0755c54e383c (Linux, Windows, macOS 14/15; Python 3.10–3.13). Live cloud API testing is not applicable before deployment.
Regression cases exercise a mocked database row through real lightweight vector search and real recall-item construction, covering digit strings, native integers, JSON-quoted strings, leading zeros and nulls. Before the fix, the numeric string/integer cases fail with Pydantic metadata.user_id string-type errors (2 failed, 26 passed); after the fix, all relevant tests pass. All fixtures are synthetic and external services are mocked.
Checklist
I have performed a self-review of my own code | 我已自行检查了自己的代码
I have commented my code in hard-to-understand areas | 我已在难以理解的地方对代码进行了注释
I have added tests that prove my fix is effective or that my feature works | 我已添加测试以证明我的修复有效或功能正常
Documentation issue/PR: not applicable; no public API changes.
The test environment encountered an issue that requires manual attention.
Details: Required Python dependency is unavailable. Automated validation remains blocked.
[tests/graph_dbs/test_search_return_fields.py] test_return_fields_included_in_results: ../../repo/tests/graph_dbs/test_search_return_fields.py:33: in neo4j_db
with patch("neo4j.GraphDatabase") as mock_gd:
/usr/lib/python3.10/unittest/mock.py:1431: in enter
self.target = self.getter()
/usr/lib/python3.10/unittest/mock.py:1618: in
getter = lambda: _importer(target)
/usr/lib/python3.10/unittest/mock.py:1257: in _importer
thing = import(import_path)
E ModuleNotFoundError: No module named 'neo4j'
[tests/graph_dbs/test_search_return_fields.py] test_backward_compatible_without_return_fields: ../../repo/tests/graph_dbs/test_search_return_fields.py:33: in neo4j_db
with patch("neo4j.GraphDatabase") as mock_gd:
/usr/lib/python3.10/unittest/mock.py:1431: in enter
self.target = self.getter()
/usr/lib/python3.10/unittest/mock.py:1618: in
getter = lambda: _importer(target)
/usr/lib/python3.10/unittest/mock.py:1257: in _importer
thing = import(import_path)
E ModuleNotFoundError: No module named 'neo4j'
[tests/graph_dbs/test_search_return_fields.py] test_cypher_return_clause_includes_fields: ../../repo/tests/graph_dbs/test_search_return_fields.py:33: in neo4j_db
with patch("neo4j.GraphDatabase") as mock_gd:
/usr/lib/python3.10/unittest/mock.py:1431: in enter
self.target = self.getter()
/usr/lib/python3.10/unittest/mock.py:1618: in
getter = lambda: _importer(target)
/usr/lib/python3.10/unittest/mock.py:1257: in _importer
thing = import(import_path)
E ModuleNotFoundError: No module named 'neo4j'
[tests/graph_dbs/test_search_return_fields.py] test_cypher_return_clause_default: ../../repo/tests/graph_dbs/test_search_return_fields.py:33: in neo4j_db
with patch("neo4j.GraphDatabase") as mock_gd:
/usr/lib/python3.10/unittest/mock.py:1431: in enter
self.target = self.getter()
/usr/lib/python3.10/unittest/mock.py:1618: in
getter = lambda: _importer(target)
/usr/lib/python3.10/unittest/mock.py:1257: in _importer
thing = import(import_path)
E ModuleNotFoundError: No module named 'neo4j'
[tests/graph_dbs/test_search_return_fields.py] test_return_fields_skips_id_field: ../../repo/tests/graph_dbs/test_search_return_fields.py:33: in neo4j_db
with patch("neo4j.GraphDatabase") as mock_gd:
/usr/lib/python3.10/unittest/mock.py:1431: in enter
self.target = self.getter()
/usr/lib/python3.10/unittest/mock.py:1618: in
getter = lambda: _importer(target)
/usr/lib/python3.10/unittest/mock.py:1257: in _importer
thing = import(import_path)
E ModuleNotFoundError: No module named 'neo4j' [advisory, non-gating] AI-generated tests on branch test/auto-gen-76289f0ed9dd0b83-20261029192601: 151/153 passed, 2 failed — these do NOT affect the PR verdict; review the branch manually. Branch:codex/fix-polardb-lightweight-identifiers
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Fixes #2550.
PolarDB lightweight vector-search projections can return a numeric user ID as an already-decoded string. Decoding it again with
json.loadsturns it into an integer, causingTextualMemoryItemvalidation to fail and potentially leaving knowledge-base retrieval empty after successful ingestion.Preserve identifier strings (including leading zeros), normalize native integer identifiers to strings, and keep JSON-quoted strings and nulls compatible. Non-identifier arrays, objects, booleans and numeric values retain their existing decoding. The identifier field set is a module-level frozenset, avoiding per-field allocations during recall. No dependency, schema or route changes.
Type of change
How Has This Been Tested?
poetry run pytest tests/graph_dbs/ -q→ 77 passed, 3 skipped.make test→ 1005 passed, 9 skipped;make formatand changed-file pre-commit passed.b1a7d5fee60c06923933550c9c9c0755c54e383c(Linux, Windows, macOS 14/15; Python 3.10–3.13). Live cloud API testing is not applicable before deployment.Regression cases exercise a mocked database row through real lightweight vector search and real recall-item construction, covering digit strings, native integers, JSON-quoted strings, leading zeros and nulls. Before the fix, the numeric string/integer cases fail with Pydantic
metadata.user_idstring-type errors (2 failed, 26 passed); after the fix, all relevant tests pass. All fixtures are synthetic and external services are mocked.Checklist
Reviewer Checklist