OpenSearch: delete_by_metadata_field never deletes anything, so edited or deleted annotations stay in the annotation index

Aperta
#47,014 0 commenti 1 reazione 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

@Aadharbindal ci sta già lavorando.

Dal 24/11/2026.

  • #47016 di @Aadharbindal — aperta

Valutazione

Difficoltà
3/5
Tempo stimato
Mezza giornata
Idoneità per principianti
25/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
python
Ambito
search

Direzione di ricerca

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.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

🐞 bug
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:

  1. Enable annotation reply on a chat app and add an annotation.
  2. Edit the annotation's question, or delete the annotation.
  3. 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:

  1. delete_by_metadata_field passes the result of get_ids_by_metadata_field to delete_by_ids. Those are OpenSearch _ids (uuid4().hex, set in add_texts), but delete_by_ids treats its argument as metadata doc_ids and looks each one up again with a metadata.doc_id term query. No document has an OpenSearch _id as its doc_id, so nothing is found and nothing is deleted. This affects every key, including document_id.
  2. get_ids_by_metadata_field uses {"term": {"metadata.<key>": value}}. create_collection only maps doc_id and document_id as keyword. app_id and annotation_id get the dynamic mapping (analyzed text plus a .keyword subfield), and a term query for a whole UUID never matches the analyzed tokens of a text field.
  3. 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.

Lingua principale
Python
Stelle
162k
Fork
25.6k
Merge medio
15h 9m
PR unite (30g)
606

Preparare l'ambiente

Apri in Codespaces

Avvia il container di sviluppo del progetto nel browser, con il tuo account GitHub.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di langgenius/dify

Tutte le issue di langgenius/dify

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.