/knowledge/. Each file is assembled from the
document’s completed, enabled segments.
For API key setup, see Dify Setup.
Config
Filesystem Layout
Dify documents are mapped to paths using the configured slug metadata field. The default metadata field name isslug. If a document has no configured slug
metadata, Mirage falls back to the Dify document name.
| Dify document | Metadata | Mirage path |
|---|---|---|
Quickstart | slug=guides/quickstart.md | /knowledge/guides/quickstart.md |
README.md | no slug | /knowledge/README.md |
Creating Slug Metadata in Dify
In the Dify Knowledge UI, open a document and add a metadata item whose name matchesslug_metadata_name. The default name is slug.
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,
guidesandguides/quickstart.mdcannot both be document paths.
enabledistrueindexing_statusiscompletedarchivedisfalse
Reading Documents
cat, head, tail, and grep read Dify document segments. Segment content
is joined with a single newline between chunks.
Search
Thesearch command calls Dify’s dataset retrieval API. Use it when meaning
matters more than exact text matching.
| Method | Dify retrieval mode |
|---|---|
semantic | semantic search |
fulltext | full text search |
hybrid | hybrid search |
keyword | keyword search |
top-k is capped at 100. threshold must be between 0 and 1.
Results are emitted one retrieval hit per block:
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:| Mirage target | Dify metadata filter |
|---|---|
| Document with configured slug metadata | <slug_metadata_name> in [...] |
| Document without configured slug metadata | document_name in [...] |
| Folder or glob | <slug_metadata_name> / document_name filters for all matched files |
- Add the configured slug metadata field to every document.
- Enable Dify Built-in Fields in the dataset metadata settings.
- Ensure
document_nameis available if you rely on name-based paths.
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
examples/python/dify/dify.py.
Shell Commands
| Command | Notes |
|---|---|
ls | List folders and documents |
cat | Read full document text from completed segments |
head / tail | Read the first or last lines/bytes |
grep | Exact or regex matching over streamed document text |
find | Search the virtual tree by name, type, depth, and size |
wc | Count lines, words, bytes, characters, and max line length |
search | Semantic/full-text/hybrid/keyword retrieval through Dify |