#2433·MemOS

SentenceChunker.chunk discards Chunk objects (token_count/sentences) by rebinding to str

Author: simpleqtCreated Sep 28, 2026Updated Sep 28, 2026
Labelstypes:bugarea:coreai:failedstatus:in-progress

Bug Description

SentenceChunker.chunk in src/memos/chunkers/sentence_chunker.py builds a proper Chunk object and then immediately overwrites it with the restored-URL string:

python
chunk = Chunk(text=c.text, token_count=c.token_count, sentences=c.sentences)
chunk = self.restore_urls(chunk.text, url_map)   # rebinds `chunk` to a bare str
chunks.append(chunk)

So the method always returns list[str] despite declaring list[str] | list[Chunk]: token_count and sentences are silently discarded, and callers that use the documented Chunk API (.text / .token_count / .sentences) get an AttributeError. The existing test masks this by accepting both return types.

Expected Behavior

The method should return actual Chunk objects with the URL-restored text plus the preserved token_count and sentences.

Environment

MemOS main, python 3.14.

Additional Context

Fix + red/green-verified test ready; PR to follow referencing this issue.