Credentials
Mirage uses the Dify Knowledge Base API. You need a dataset API key and the dataset ID for the knowledge base you want to mount.1. Get a Knowledge API Key
- Open your Dify workspace.
- Go to the target knowledge base.
- Open API Access or the dataset API settings.
- Create or copy an API key with permission to read documents, segments, and retrieval results.
2. Find the Dataset ID
Use the dataset ID from the knowledge base URL or Dify API settings. The ID is used in API paths such as:3. Set Environment Variables
DIFY_BASE_URL to your API base URL, for example:
Document Metadata
Mirage can mount a Dify dataset without custom metadata, but scoped search works best when every document has a stable slug metadata field. Mirage looks for a field namedslug by default; Python users can change that field name with
DifyConfig(slug_metadata_name="...").
Recommended: Add a Slug Metadata Field
Create a metadata field on the Dify knowledge dataset and use the value as the virtual path below the Mirage mount. The default field name isslug.
| Dify document | slug metadata value | Mirage path |
|---|---|---|
| Quickstart | guides/quickstart.md | /knowledge/guides/quickstart.md |
| Support Policy | policies/support.md | /knowledge/policies/support.md |
path, set slug_metadata_name="path" in
the Dify resource config and use name: path in Dify metadata.
Guidelines:
- Use forward slashes to create folders.
- Do not start with
/; Mirage normalizes leading and trailing slashes. - Do not use empty segments,
., or... - Keep values unique. Two documents with the same slug metadata value will raise a duplicate path error.
- Avoid making one document’s slug metadata value a parent of another document’s slug metadata value. For example, do not use both
guidesandguides/quickstart.md; Mirage treats that as a path collision.
Add or Update Slug Metadata in Dify
In Dify’s Knowledge UI, open each document and edit its metadata. Add a custom metadata item:doc_metadata field and looks for an item
whose name matches slug_metadata_name.
Enable Built-in Fields for Name-Based Documents
If a document does not have the configured slug metadata field, Mirage falls back to the Dify document name for its file path. Scopedsearch can still
target those name-based documents, but Dify must expose the document_name
built-in field for metadata filtering.
In the Dify knowledge dataset settings:
- Open the dataset metadata settings.
- Enable Built-in Fields.
- Ensure
document_nameis available for metadata filtering.
ls, find, cat, and grep still
work because Mirage resolves files through the document list and segment APIs.
Scoped search against name-based paths may return no records because Dify
cannot filter retrieval by document_name.
For the most predictable behavior, add the configured slug metadata field to
every document and use slug-based paths.
For Python configuration, see the Python Dify Setup guide.