Skip to content

Commit

Permalink
bugfix: modify root node's global metadata (#392)
Browse files Browse the repository at this point in the history
  • Loading branch information
ouonline authored Dec 17, 2024
1 parent e0dd386 commit 1ba38a4
Show file tree
Hide file tree
Showing 8 changed files with 18 additions and 6 deletions.
2 changes: 1 addition & 1 deletion lazyllm/tools/rag/chroma_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ def _make_chroma_metadata(self, node: DocNode) -> Dict[str, Any]:
"metadata": obj2str(node._metadata),
}

if not node.parent:
if node.is_root_node:
metadata["global_metadata"] = obj2str(node.global_metadata)

return metadata
Expand Down
4 changes: 4 additions & 0 deletions lazyllm/tools/rag/doc_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,10 @@ def root_node(self) -> Optional["DocNode"]:
root = root.parent
return root or self

@property
def is_root_node(self) -> bool:
return (not self.parent)

@property
def global_metadata(self) -> Dict[str, Any]:
return self.root_node._global_metadata
Expand Down
2 changes: 1 addition & 1 deletion lazyllm/tools/rag/milvus_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ def _deserialize_node_partial(self, result: Dict) -> DocNode:
if k.startswith(self._embedding_key_prefix):
doc.embedding[k[len(self._embedding_key_prefix):]] = v
elif k.startswith(self._global_metadata_key_prefix):
if doc.parent:
if doc.is_root_node:
doc._global_metadata[k[len(self._global_metadata_key_prefix):]] = v

return doc
2 changes: 1 addition & 1 deletion requirements.full.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ psutil
pypdf
pytest
numpy==1.26.4
pymilvus
pymilvus>=2.4.7, <2.5.0
async-timeout
httpx<0.28.0
redis>=5.0.4
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,6 @@ psutil
pypdf
pytest
numpy==1.26.4
pymilvus
pymilvus>=2.4.7, <2.5.0
async-timeout
httpx<0.28.0
2 changes: 1 addition & 1 deletion scripts/check_requirements.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def parse_requirement(line):
return None, None

def compare_versions(version_spec, req_version):
if version_spec.startswith('^') and req_version == '*':
if version_spec.startswith('^'):
return True
return version_spec == req_version

Expand Down
8 changes: 8 additions & 0 deletions tests/basic_tests/test_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,9 @@ def setUp(self):
}
self.global_metadata_desc = {
'comment': GlobalMetadataDesc(data_type=GlobalMetadataDesc.DTYPE_VARCHAR, max_size=65535, default_value=' '),
'signature': GlobalMetadataDesc(data_type=GlobalMetadataDesc.DTYPE_VARCHAR, max_size=256, default_value=' '),
'tags': GlobalMetadataDesc(data_type=GlobalMetadataDesc.DTYPE_ARRAY,
element_type=GlobalMetadataDesc.DTYPE_INT32, max_size=128, default_value=[]),
}

self.node_groups = [LAZY_ROOT_NAME, "group1", "group2"]
Expand Down Expand Up @@ -278,6 +281,7 @@ def test_query_with_filter_non_exist(self):

def test_reload(self):
self.store.update_nodes([self.node1, self.node2, self.node3])
# reload from storage
del self.store
self.store = MilvusStore(group_embed_keys=self.group_embed_keys, embed=self.mock_embed,
embed_dims=self.embed_dims, global_metadata_desc=self.global_metadata_desc,
Expand All @@ -291,6 +295,10 @@ def test_reload(self):
for orig_node in orig_nodes:
if node._uid == orig_node._uid:
self.assertEqual(node.text, orig_node.text)
# builtin fields are not in orig node, so we can not use
# node.global_metadata == orig_node.global_metadata
for k, v in orig_node.global_metadata.items():
self.assertEqual(node.global_metadata[k], v)
break

# XXX `array_contains_any` is not supported in local(aka lite) mode. skip this ut
Expand Down
2 changes: 1 addition & 1 deletion tests/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ docx2txt
olefile
pytest-rerunfailures
pytest-order
pymilvus
pymilvus>=2.4.7, <2.5.0

0 comments on commit 1ba38a4

Please sign in to comment.