OpenSearch: delete_by_metadata_field never deletes anything, so edited or deleted annotations stay in the annotation index
Maintainers usually reply within 1 day
Assessment
- Difficulty
- 3/5
- Estimated time
- Half a day
- Newbie friendliness
- 25/100
Research direction
Start in api/providers/vdb/vdb-opensearch/src/dify_vdb_opensearch/opensearch_vector.py, where delete_by_metadata_field, get_ids_by_metadata_field and delete_by_ids are defined, and check create_collection's field mapping for app_id and annotation_id. Trace the callers in update_annotation_to_index_task, delete_annotation_index_task and enable_annotation_reply_task. Done means deleting by annotation_id or app_id removes the matching documents, and unit tests cover it. A linked pull request already exists, so coordinate with it before starting.
Written by the indexing model from the issue text.
Description
Self Checks
- I have read the Contributing Guide and Language Policy.
- This is only for bug report, if you would like to ask a question, please head to Discussions.
- I have searched for existing issues search for existing issues, including closed ones.
- I confirm that I am using English to submit this report, otherwise it will be closed.
- 【中文用户 & Non English User】请使用英语提交,否则会被关闭 :)
- Please do not modify this template :) and fill in all the required fields.
Dify version
main (8985a46)
Cloud or Self Hosted
Self Hosted (Source)
Steps to reproduce
With VECTOR_STORE=opensearch:
- Enable annotation reply on a chat app and add an annotation.
- Edit the annotation's question, or delete the annotation.
- Ask the old question again.
The annotation tasks remove the old vector with vector.delete_by_metadata_field("annotation_id", annotation_id) (update_annotation_to_index_task, delete_annotation_index_task) and vector.delete_by_metadata_field("app_id", app_id) (enable_annotation_reply_task).
✔️ Expected Behavior
The old annotation vector is removed, so the edited or deleted annotation no longer answers the old question.
❌ Actual Behavior
Nothing is deleted. The old vector stays in the OpenSearch index, so annotation reply keeps answering with the old or deleted annotation, and re-enabling annotation reply adds duplicates. For annotation_id and app_id this happens silently; for keyword fields the only trace is a Document with metadata doc_id ... not found for deletion warning per hit.
In api/providers/vdb/vdb-opensearch/src/dify_vdb_opensearch/opensearch_vector.py there are three problems:
delete_by_metadata_fieldpasses the result ofget_ids_by_metadata_fieldtodelete_by_ids. Those are OpenSearch_ids (uuid4().hex, set inadd_texts), butdelete_by_idstreats its argument as metadatadoc_ids and looks each one up again with ametadata.doc_idterm query. No document has an OpenSearch_idas itsdoc_id, so nothing is found and nothing is deleted. This affects every key, includingdocument_id.get_ids_by_metadata_fielduses{"term": {"metadata.<key>": value}}.create_collectiononly mapsdoc_idanddocument_idas keyword.app_idandannotation_idget the dynamic mapping (analyzed text plus a.keywordsubfield), and a term query for a whole UUID never matches the analyzed tokens of a text field.- The search has no
size, so it returns at most 10 hits.
The Elasticsearch backend has a similar problem with a different cause (match instead of term), reported in #46995. This one is separate: it is the OpenSearch backend, and the _id/doc_id mix-up in (1) is specific to it.
I have a fix with unit tests and will open a PR.
- Dominant language
- Python
- Stars
- 162k
- Forks
- 25.6k
- Avg merge
- 15h 9m
- Merged PRs (30d)
- 606
Getting set up
Starts the project's dev container in your browser, under your own GitHub account.
- No Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from langgenius/dify
-
OpenSearch: text_exists() queries OpenSearch _id instead of metadata.doc_id, so it always returns False for indexed chunksPossibly taken @SanemIzci claimed this 1 day ago. Open🐞 bug
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
langgenius/dify#47109 · 1 comment · 1 reaction ·
Maintainers usually reply within 1 day
-
Log only execution identifiers when a workflow worker starts a runPossibly taken @kinglegendzzh claimed this 1 day ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
langgenius/dify#47094 · 2 reactions ·
Maintainers usually reply within 1 day
-
Node.js SDK declares a response body for 204 conversation deletionPossibly taken @Wang-Zephyr claimed this 5 days ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
langgenius/dify#46883 · 1 comment · 1 reaction ·
Maintainers usually reply within 1 day
-
Provider IDs with a trailing newline are silently accepted and propagatedPossibly taken @Batianxieshen1 claimed this 5 days ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
langgenius/dify#46875 · 1 comment · 1 reaction ·
Maintainers usually reply within 1 day
-
Agent Python SDK polling rejects function-tool results that SSE acceptsPossibly taken @EndlessRoad-max claimed this 5 days ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
langgenius/dify#46868 · 1 reaction ·
Maintainers usually reply within 1 day
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 79/100
micronaut-projects/micronaut-core#14585 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
langgenius/graphon#443 ·
Maintainers usually reply within 2 days
-
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
Maintainers usually reply within 1 day
-
[BUG]: Management endpoints /v1/memory/stats and /v1/memory/counts bypass API key authenticationOpen
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
docling-project/docling-serve#788 ·
Maintainers usually reply within 1 day
-
Mend: dependency security vulnerability untriaged
Difficulty 1/5 Under an hour Newbie friendliness 78/100
opensearch-project/cross-cluster-replication#1805 ·
Maintainers usually reply within 1 day