Skip to main content
The Dify resource exposes completed Dify Knowledge documents as text files mounted at a prefix such as /knowledge/. Each file is assembled from the document’s completed, enabled segments. For API key setup, see Dify Setup.

Config

The resource is read-only and does not support snapshots.

Filesystem Layout

Dify documents are mapped to paths using the configured slug metadata field. The default metadata field name is slug. If a document has no configured slug metadata, Mirage falls back to the Dify document name.
Example mapping:

Creating Slug Metadata in Dify

In the Dify Knowledge UI, open a document and add a metadata item whose name matches slug_metadata_name. The default name is slug.
For a custom Dify metadata name:
Then use:
Mirage reads doc_metadata from Dify and uses this value as the document’s virtual path below the mount prefix. Use these rules for slug metadata values:
  • Use / to create folders.
  • Do not use empty segments, ., or ...
  • Keep each slug metadata value unique across the dataset.
  • Do not use a path that is also needed as a folder. For example, guides and guides/quickstart.md cannot both be document paths.
Only visible documents are included:
  • enabled is true
  • indexing_status is completed
  • archived is false

Reading Documents

cat, head, tail, and grep read Dify document segments. Segment content is joined with a single newline between chunks.
The search command calls Dify’s dataset retrieval API. Use it when meaning matters more than exact text matching.
Supported methods: top-k is capped at 100. threshold must be between 0 and 1. Results are emitted one retrieval hit per block:
Mirage uses the configured slug metadata field to derive the path, and falls back to the Dify document name when that metadata is missing. Multiple hits from the same document remain separate records. Scoped search uses Dify metadata filtering. Documents with the configured slug metadata field are filtered by that field; name-based documents are filtered by document_name, which requires Dify Built-in Fields to be enabled in dataset metadata.

Scoped Search Requirements

Mirage converts a scoped search path into Dify metadata filters: To make scoped search reliable:
  1. Add the configured slug metadata field to every document.
  2. Enable Dify Built-in Fields in the dataset metadata settings.
  3. Ensure document_name is available if you rely on name-based paths.
If Built-in Fields are disabled, scoped search against documents without the configured slug metadata field may return empty results even though cat, grep, and find can still see the same file.

Cache

The resource uses Mirage’s index cache for the virtual tree. Directory listings and path resolution reuse the cached document tree until the index expires or the workspace is recreated. If documents are edited directly in Dify, repeated operations can temporarily see cached paths and metadata. Document content is still read from Dify when commands materialize file data.

Example

A runnable version is available at examples/python/dify/dify.py.

Shell Commands