Plugin backwards invocation for knowledge base operations (documents, metadata, pipeline runs)

Open
#46,637 1 comment 1 reaction 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
5/5
Estimated time
Over a week
Newbie friendliness
30/100
Issue type
Feature
Clarity
Mostly clear
Activity status
Active
Tech stack
python
Domain
api, backend, databases

Research direction

Start by reading the plugin SDK backwards invocation code and manifest permission handling, then trace the knowledge pipeline and dataset service APIs mentioned in the issue. Map how tenant scope, document metadata, indexing status, chunk retrieval, and in-place pipeline runs are exposed today. Done means a permission-gated plugin namespace supports the listed operations within the installed tenant; the issue does not identify specific files or tests.

Written by the indexing model from the issue text.

Description

👻 feat:rag 💪 enhancement Knowledge Pipeline
Self Checks
  • I have read the Contributing Guide and Language Policy.
  • 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.
  • Please do not modify this template :) and fill in all the required fields.
1. Is this request related to a challenge you're experiencing? Tell me about your story.

We keep two pipeline knowledge bases in sync with an external system: records are added, edited and removed there, and Dify should follow (one-way) within a few minutes. The setup is entirely on the Dify side:

  • an online_document datasource plugin that lists the external records as pages and returns their content,
  • a tool plugin that compares the pages with the documents already in the knowledge base, runs the published pipeline for new or changed pages, and deletes documents whose record changed or disappeared,
  • a workflow with a Schedule trigger that calls the tool every 5 minutes.

It works, but the tool cannot do any of this through the plugin SDK. Backwards invocation covers models, tools, apps, workflow nodes, storage and files, but nothing for knowledge bases. So a plugin running inside Dify has to call Dify's own Service API over HTTP:

  • every tool instance needs the Dify API base URL as seen from the plugin daemon (http://api:5001 in docker compose, something else in other deployments), plus a knowledge base API key. That key is workspace-wide and has to be stored as a tool parameter. Neither should be needed for a plugin to work with the workspace it is installed in.
  • going through a workflow HTTP Request node instead does not help: it goes through the SSRF proxy, which blocks private addresses unless SSRF_PROXY_ALLOW_PRIVATE_IPS is changed.

What we would like is backwards invocation for common knowledge base operations, scoped to the plugin's tenant and gated by a manifest permission like the existing tool / model / app ones. For example, a self.session.knowledge namespace offering:

  1. list documents of a dataset, with indexing status and metadata (paginated),
  2. delete a document,
  3. create metadata fields and set document metadata,
  4. run the published knowledge pipeline for a list of datasource items, and re-run it for an existing document in place (original_document_id),
  5. get the indexing status of a batch,
  6. retrieve chunks (this would also cover langgenius/dify-plugin-sdks#129).
2. Additional context or comments

Related limitations we ran into while building this, which shaped the request above:

  • No in-place update through the Service API. POST /v1/datasets/{id}/pipeline/run does not accept original_document_id, so every run creates a new document. The console endpoint POST /console/api/rag/pipelines/{id}/workflows/published/run accepts it and replaces the document in place. Over the Service API, an update means: create a new document, wait for indexing, then delete the old one. To match documents to records again, we track both in custom metadata (record_id, content hash).
  • No re-sync for pipeline online_document documents. document_indexing_sync_task only handles legacy notion_import documents and is triggered manually. Documents imported through a datasource plugin (including the official Notion datasource) are never refreshed, so every integration needs its own sync tool.
  • A datasource and a tool cannot ship in one package (datasource and tool, model, endpoint, trigger, or agent_strategy cannot be provided at the same time). The sync logic therefore lives in a second plugin. Since that plugin cannot use the datasource directly, it gets the page list by calling POST /v1/datasets/{id}/pipeline/datasource/nodes/{node_id}/run over HTTP.
  • Minor, possibly a separate bug: on 1.19.0, running an online_document pipeline through the Service API without credential_id in datasource_info_list fails with invalid input syntax for type uuid: "" instead of using the default credential.

Environment: self-hosted Dify 1.19.0 (docker compose), plugin daemon 0.6.14, dify_plugin 0.10.2. We also checked the 1.17.1 source: the Service API endpoints above are the same there.

3. Can you help us with this feature?
  • I am interested in contributing to this feature.
Dominant language
Python
Stars
162k
Forks
25.6k
Avg merge
15h 9m
Merged PRs (30d)
606

Getting set up

Open in Codespaces

Starts the project's dev container in your browser, under your own GitHub account.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from langgenius/dify

All issues in langgenius/dify

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.