Skip to content

fix: allow DocMetadata to accept extra keyword arguments from stored payloads#1404

Open
octo-patch wants to merge 1 commit intoagentscope-ai:mainfrom
octo-patch:fix/issue-1374-docmetadata-extra-kwargs
Open

fix: allow DocMetadata to accept extra keyword arguments from stored payloads#1404
octo-patch wants to merge 1 commit intoagentscope-ai:mainfrom
octo-patch:fix/issue-1374-docmetadata-extra-kwargs

Conversation

@octo-patch
Copy link
Copy Markdown

Fixes #1374

Problem

When users add custom fields (e.g. filename) to document metadata before storing documents in Qdrant, retrieving those documents fails with:

TypeError: DocMetadata.__init__() got an unexpected keyword argument 'filename'

This happens because DocMetadata(**point.payload) is called in _qdrant_store.py during retrieval, but DocMetadata only accepts its four defined fields and rejects any extra keyword arguments.

Solution

Change DocMetadata to use @dataclass(init=False) and define a custom __init__ that accepts **kwargs. Any extra fields are stored as instance attributes via setattr, preserving user-defined metadata and making it accessible after retrieval.

Testing

Manually verified: after setting a custom filename attribute on DocMetadata and storing a document, calling knowledge.retrieve() no longer raises a TypeError and the filename attribute is accessible on the returned document's metadata.

…payloads (fixes agentscope-ai#1374)

When users add custom fields (e.g. 'filename') to document metadata and
store them in Qdrant, retrieving the documents fails with:
  TypeError: DocMetadata.__init__() got an unexpected keyword argument 'filename'

Use @DataClass(init=False) with a custom __init__ that accepts **kwargs
and sets extra fields as attributes, preserving user-defined metadata.
@cla-assistant
Copy link
Copy Markdown

cla-assistant bot commented Apr 3, 2026

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]:执行knowledge.retrieve搜索方法,报错got an unexpected keyword argument 'filename'

1 participant