-
Notifications
You must be signed in to change notification settings - Fork 71
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support edit metadata #414
base: main
Are you sure you want to change the base?
Conversation
meta_dict = json.loads(doc.meta) if doc.meta else {} | ||
for k, v in kv_pair.items(): | ||
if k not in meta_dict: | ||
meta_dict[k] = v |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
此处不合理,假设我有两个标签a和b先后add,第一次add的时候会赋值成a,然后第二次add时就报错了
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
我建议metadata加的时候要简单指定一下是不是list(取一个适合业务的名字,比如vector_values=True)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
出于简化设计和易于使用的考量。改为了这样的设计:
前提约束:metadata 内容是扁平的,即 {key: val} val 中不会出现嵌套的dict。
增加metadata时, kv_pair类型约束为: Dict[str, Union[bool, int, float, str, list]]
- 若k为新增:使用v直接赋值
- k已存在,若meta[k] 为list:将v中元素追加至meta[k]中
- k已存在,meta[k] 非list:将meta[k]变为list,并追加v中所有元素
@app.post("/delete_metadata_keys") | ||
def delete_metadata_keys(self, del_metadata_request: DeleteMetadataRequest): | ||
doc_ids = del_metadata_request.doc_ids | ||
keys = del_metadata_request.keys |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
如果我想meta_dict[k].remove(v),该怎么办
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
已更新delete_metadata_item 接口,解决此需求
lazyllm/tools/rag/doc_manager.py
Outdated
keys: Optional[List[str]] = Field(None) | ||
doc_ids: List[str] | ||
# value type should be None/list/str | ||
kv_pair: Optional[Dict[str, Union[None, bool, int, float, str, list]]] = Field(None) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
也同时保留原来keys的逻辑吧,并且判断一下keys和kv_pair有且只能有一个
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里稍微做了一下调整。 添加了keys 关键字,并且keys和kv_pair 可以 都存在/都不存在/存在一个。
功能效果如下:
- 都不存在,把所有用户设置的metadata key删除
- 只存在 keys,以key删除
- 只存在kv_pair, 以key+value 删除
- keys与kv_pair都存在。合并删除,即满足条件的key和kv_pair都会删除
No description provided.