Skip to content
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

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open

Conversation

SuperEver
Copy link
Contributor

No description provided.

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
Copy link
Contributor

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时就报错了

Copy link
Contributor

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)

Copy link
Contributor Author

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]]

  1. 若k为新增:使用v直接赋值
  2. k已存在,若meta[k] 为list:将v中元素追加至meta[k]中
  3. 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
Copy link
Contributor

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),该怎么办

Copy link
Contributor Author

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 Show resolved Hide resolved
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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

也同时保留原来keys的逻辑吧,并且判断一下keys和kv_pair有且只能有一个

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里稍微做了一下调整。 添加了keys 关键字,并且keys和kv_pair 可以 都存在/都不存在/存在一个。
功能效果如下:

  1. 都不存在,把所有用户设置的metadata key删除
  2. 只存在 keys,以key删除
  3. 只存在kv_pair, 以key+value 删除
  4. keys与kv_pair都存在。合并删除,即满足条件的key和kv_pair都会删除

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.

2 participants