dify-knowledge-base-upload
Skill11 starsChanged 3 months agoMITView on GitHub
Upload local files to a Dify pipeline knowledge base through the published pipeline datasource flow and optionally apply existing metadata fields. Use when the target dataset is a published rag_pipeline/local_file knowledge base or ordinary Dify document create APIs return completed with 0 chunks.
- Reads credentials
In this repository62 other files it gives its agents.
- AGENTS.mdAGENTS.md
- academic-paper-downloadSkill
- airnow-hourly-obs-fetchSkill
- ai-tech-fulltext-fetchSkill
- ai-tech-rss-fetchSkill
- ai-tech-summarySkill
- apply-environmental-thinkingSkill
- bluesky-cascade-fetchSkill
- convert-image-to-jpgSkill
- dify-knowledge-base-searchSkill
- document-granular-decomposeSkill
- domain-onboardingSkill
- eceee-news-fulltext-fetchSkill
- email-imap-appendSkill
- email-imap-fetchSkill
- email-imap-full-fetchSkill
- email-smtp-sendSkill
- epa-eis-records-fetchSkill
- federal-register-doc-fetchSkill
- fetch-abstract-to-kbSkill
- fetch-meta-from-kbSkill
- fetch-meta-to-kbSkill
- figshare-data-downloadSkill
- gdelt-doc-searchSkill
- gdelt-events-fetchSkill
- gdelt-gkg-fetchSkill
- gdelt-mentions-fetchSkill
- gdelt-web-ngrams-searchSkill
- github-contribution-period-analysisSkill
- nasa-firms-fire-fetchSkill
- notebooklmSkill
- openaq-data-fetchSkill
- open-meteo-air-quality-fetchSkill
- open-meteo-flood-fetchSkill
- open-meteo-historical-fetchSkill
- regulationsgov-attachments-fetchSkill
- regulationsgov-comment-detail-fetchSkill
- regulationsgov-comments-fetchSkill
- remove-similar-imageSkill
- river-outfall-status-visualizerSkill
- sustainability-fulltext-fetchSkill
- sustainability-rss-fetchSkill
- sustainability-summarySkill
- synology-file-stationSkill
- tiangong-auto-researchSkill
- tiangong-auto-research-workbuddySkill
- tiangong-kb-course-fulltext-fetchSkill
- tiangong-kb-course-searchSkill
- tiangong-kb-edu-searchSkill
- tiangong-kb-esg-searchSkill
- tiangong-kb-ingestSkill
- tiangong-kb-patent-searchSkill
- tiangong-kb-report-searchSkill
- tiangong-kb-sci-searchSkill
- tiangong-kb-textbook-searchSkill
- tsinghua-graduate-thesisSkill
- usbr-project-records-fetchSkill
- usbr-rise-fetchSkill
- use-thuenv-presentation-styleSkill
- usgs-water-iv-fetchSkill
- The first 60 shown.
The file
We split this skill into the rules it gives an agent
11 rules. About 0 are common, 2 are distinctive, and 9 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈2
Distinctive · estimate
This author's own choices. Worth a look.
9
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 25
Read references/env.md only if you need env or debug details.
- Very specific: line 31
run the published pipeline through ${DIFY_API_BASE_URL}/datasets/${DIFY_DATASET_ID}/pipeline/run
- Very specific: line 65
If tokens is returned by the document detail API, it should also be greater than 0.
- Very specific: line 67
If --metadata-json is omitted, the script uploads the file only and skips metadata API calls.
- Very specific: line 70
Use --dry-run to validate local files and request shape without calling Dify.
- Very specific: line 73
If auth fails, verify DIFY_API_KEY and Authorization header format.
- Distinctive: line 74
If datasource discovery fails, verify the dataset has a published pipeline datasource and the key belongs to that dataset.
- Very specific: line 75
If the pipeline run fails with missing input errors, inspect user_input_variables from discovery_response and pass the missing keys in …
- Very specific: line 76
If the published datasource is not local_file, this skill is not the right uploader.
- Distinctive: line 77
If metadata resolution fails, rename keys in the metadata JSON to the exact field names defined in Dify.
- Very specific: line 78
If you only have raw text, save it to .txt or .md and upload that file.
≈ “Common” is an estimate: at least 1 in 5 of the 408,460 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Dify Knowledge Base Upload
Use this skill when
- The target Dify knowledge base is backed by a published pipeline datasource.
- UI uploads succeed but
document/create-by-fileorcreate-by-textyieldscompletedwith0 chunks. - You need to upload one local file and optionally write existing metadata fields afterward.
Prepare caller-side inputs
- Provide a local file path to upload.
- For pure text, save it as
.txtor.mdfirst and upload that file. - Set caller env values:
DIFY_API_BASE_URLDIFY_DATASET_IDDIFY_API_KEY
- Optionally provide pipeline
inputsJSON if the published pipeline exposes user input variables. - Optionally provide metadata JSON:
- a flat object mapping existing Dify metadata field names to values, or
- a list of
{ "name": ..., "value": ... }/{ "id": ..., "value": ... }items. - The skill does not hardcode your metadata schema. Pass the current field names or ids in the JSON you provide at runtime.
- Read
references/env.mdonly if you need env or debug details.
Run workflow
- Use
scripts/upload_to_dataset.pyto:- discover the published datasource plugin from
${DIFY_API_BASE_URL}/datasets/${DIFY_DATASET_ID}/pipeline/datasource-plugins?is_published=true - upload the file to
${DIFY_API_BASE_URL}/datasets/pipeline/file-upload - run the published pipeline through
${DIFY_API_BASE_URL}/datasets/${DIFY_DATASET_ID}/pipeline/run - poll
${DIFY_API_BASE_URL}/datasets/${DIFY_DATASET_ID}/documents/{batch}/indexing-status - fetch
${DIFY_API_BASE_URL}/datasets/${DIFY_DATASET_ID}/documents/{document_id}?metadata=without - optionally resolve metadata field names through
${DIFY_API_BASE_URL}/datasets/${DIFY_DATASET_ID}/metadata - optionally update metadata through
${DIFY_API_BASE_URL}/datasets/${DIFY_DATASET_ID}/documents/metadata
- discover the published datasource plugin from
- Upload without metadata:
python3 scripts/upload_to_dataset.py \
--file /path/to/document.pdf- Upload with pipeline inputs:
python3 scripts/upload_to_dataset.py \
--file /path/to/document.pdf \
--inputs-json assets/example-pipeline-inputs.json- Upload and then apply metadata:
python3 scripts/upload_to_dataset.py \
--file /path/to/document.pdf \
--metadata-json assets/example-metadata.jsonInterpret response
- Success prints JSON with
batch,document_id,file_upload_response,pipeline_run_response,indexing_status_response,document_response, optionalmetadata_response, andvalidation. validation.okis only true when:indexing_status = "completed"total_segments > 0segment_count > 0
- If
tokensis returned by the document detail API, it should also be greater than0. Some pipeline deployments leavetokens = null; the script reports that as a warning instead of a hard failure. - The script exits non-zero if the required checks fail.
- If
--metadata-jsonis omitted, the script uploads the file only and skips metadata API calls. - Metadata keys must already exist in the target dataset. Unknown names fail fast before the metadata write request.
assets/example-metadata.jsonis only a template. Replace its keys with your own existing Dify metadata field names before live use.- Use
--dry-runto validate local files and request shape without calling Dify.
Troubleshoot quickly
- If auth fails, verify
DIFY_API_KEYandAuthorizationheader format. - If datasource discovery fails, verify the dataset has a published pipeline datasource and the key belongs to that dataset.
- If the pipeline run fails with missing input errors, inspect
user_input_variablesfromdiscovery_responseand pass the missing keys in--inputs-json. - If the published datasource is not
local_file, this skill is not the right uploader. - If metadata resolution fails, rename keys in the metadata JSON to the exact field names defined in Dify.
- If you only have raw text, save it to
.txtor.mdand upload that file. - In the current tested deployment,
.mduploaded successfully while.txthit a Dify-side indexing400. If plain text fails as.txt, retry as.md.
References
references/env.mdreferences/request-response.mdreferences/testing.md
Assets
assets/example-pipeline-inputs.jsonassets/example-metadata.json
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

