dify-knowledge-base-upload
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.
What this skill does
# 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-file` or `create-by-text` yields `completed` with `0 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 `.txt` or `.md` first and upload that file.
- Set caller env values:
- `DIFY_API_BASE_URL`
- `DIFY_DATASET_ID`
- `DIFY_API_KEY`
- Optionally provide pipeline `inputs` JSON 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.md` only if you need env or debug details.
## Run workflow
- Use `scripts/upload_to_dataset.py` to:
- 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`
- Upload without metadata:
```bash
python3 scripts/upload_to_dataset.py \
--file /path/to/document.pdf
```
- Upload with pipeline inputs:
```bash
python3 scripts/upload_to_dataset.py \
--file /path/to/document.pdf \
--inputs-json assets/example-pipeline-inputs.json
```
- Upload and then apply metadata:
```bash
python3 scripts/upload_to_dataset.py \
--file /path/to/document.pdf \
--metadata-json assets/example-metadata.json
```
## Interpret response
- Success prints JSON with `batch`, `document_id`, `file_upload_response`, `pipeline_run_response`, `indexing_status_response`, `document_response`, optional `metadata_response`, and `validation`.
- `validation.ok` is only true when:
- `indexing_status = "completed"`
- `total_segments > 0`
- `segment_count > 0`
- If `tokens` is returned by the document detail API, it should also be greater than `0`. Some pipeline deployments leave `tokens = 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-json` is 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.json` is only a template. Replace its keys with your own existing Dify metadata field names before live use.
- Use `--dry-run` to validate local files and request shape without calling Dify.
## Troubleshoot quickly
- If auth fails, verify `DIFY_API_KEY` and `Authorization` header 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_variables` from `discovery_response` and 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 `.txt` or `.md` and upload that file.
- In the current tested deployment, `.md` uploaded successfully while `.txt` hit a Dify-side indexing `400`. If plain text fails as `.txt`, retry as `.md`.
## References
- `references/env.md`
- `references/request-response.md`
- `references/testing.md`
## Assets
- `assets/example-pipeline-inputs.json`
- `assets/example-metadata.json`
Related in General
modeling-omnistudio-epc-catalog
IncludedSalesforce Industries CME EPC product-modeling skill for Product2-based catalog creation. Use when creating EPC products, configuring product attributes, building offer bundles with Product Child Items, or reviewing EPC DataPack JSON metadata for product catalog changes. TRIGGER when: user creates or updates Product2 EPC records, AttributeAssignment payloads, AttributeMetadata/AttributeDefaultValues, Offer bundles, or ProductChildItem relationships. DO NOT TRIGGER when: designing OmniScripts/FlexCards/Integration Procedures (use building-omnistudio-omniscript, building-omnistudio-flexcard, or building-omnistudio-integration-procedure), implementing Apex business logic (use generating-apex), or troubleshooting deployment pipelines (use deploying-metadata).
relationship-science-coach
IncludedUse this skill for direct, practical adult relationship coaching: couples conflict, repair, trust, marriage, dating, flirting, attachment patterns, emotional connection, sex, desire differences, eroticism, kink negotiation, affection, love languages, breakups, and long-term passion. Draw on Gottman, EFT and Hold Me Tight, attachment science, modern sex research, Perel, Nagoski, Kerner, Schnarch, Love and Stosny, and flexible love-language tools. Be concrete and low-hedge. Redirect only for imminent danger, abuse, coercive control, minors, non-consent, self-harm, stalking, or medical/legal/psychiatric decisions.
building-sf-integrations
IncludedSalesforce integration architecture and runtime plumbing with 120-point scoring. Use this skill to set up Named Credentials, External Credentials, External Services, REST/SOAP callout patterns, Platform Events, and Change Data Capture. TRIGGER when: user sets up Named Credentials, External Services, REST/SOAP callouts, Platform Events, CDC, or touches .namedCredential-meta.xml files. DO NOT TRIGGER when: Connected App/OAuth config (use configuring-connected-apps), Apex-only logic (use generating-apex), or data import/export (use handling-sf-data).
venue-templates
IncludedAccess comprehensive LaTeX templates, formatting requirements, and submission guidelines for major scientific publication venues (Nature, Science, PLOS, IEEE, ACM), academic conferences (NeurIPS, ICML, CVPR, CHI), research posters, and grant proposals (NSF, NIH, DOE, DARPA). This skill should be used when preparing manuscripts for journal submission, conference papers, research posters, or grant proposals and need venue-specific formatting requirements and templates.
let-fate-decide
IncludedDraws the 12 Houses of the Zodiac Tarot spread to inject entropy into planning when prompts are vague, ambiguous, or casually delegated. Interprets the spread to guide next steps. Use when the user says 'let fate decide', 'YOLO', 'whatever', 'idk', or other nonchalant phrases, makes Yu-Gi-Oh references, or when you are about to arbitrarily pick between multiple reasonable approaches. Prefer over ask-questions-if-underspecified when the user's tone is casual or playful rather than precision-seeking.
net-ops
IncludedCross-platform network troubleshooting (Windows, macOS, Linux) via local or remote shell. Use for: DNS broken, can't resolve hostnames, nslookup/dig works but apps fail, NRPT, WFP, scutil, /etc/resolver, systemd-resolved, /etc/resolv.conf, NetworkManager, VPN DNS leak residue (ProtonVPN/Mullvad/WireGuard/AnyConnect), AV/firewall blocking DNS or DoH, Tailscale DNS interaction, intermittent connectivity, remote diagnostics over SSH.