dify/knowledge-fs
2026-08-14 02:27:03 -04:00
..
.codex chore: migrate knowledge-fs source tree 2026-07-20 04:54:20 -04:00
.github/workflows chore: migrate knowledge-fs source tree 2026-07-20 04:54:20 -04:00
.harness restore semantic document compilation pipeline 2026-08-13 13:10:39 -04:00
apps restore semantic document compilation pipeline 2026-08-13 13:10:39 -04:00
contracts Improve application workflows and user experience 2026-08-14 02:27:03 -04:00
design/productized-knowledgefs chore: migrate knowledge-fs source tree 2026-07-20 04:54:20 -04:00
docs feat(knowledge-fs): unify public error handling 2026-08-12 07:00:59 -04:00
infra Update frontend components and application workflows 2026-07-29 06:18:05 -04:00
packages Improve application workflows and user experience 2026-08-14 02:27:03 -04:00
scripts Improve application workflows and user experience 2026-08-14 02:27:03 -04:00
test Refactor codebase and remove obsolete implementations 2026-07-23 01:53:40 -04:00
tools/swagger chore: migrate knowledge-fs source tree 2026-07-20 04:54:20 -04:00
.dockerignore chore: migrate knowledge-fs source tree 2026-07-20 04:54:20 -04:00
.gitignore Expand application capabilities and refactor core workflows 2026-07-22 05:09:09 -04:00
biome.json chore: migrate knowledge-fs source tree 2026-07-20 04:54:20 -04:00
main.py chore: migrate knowledge-fs source tree 2026-07-20 04:54:20 -04:00
package.json restore semantic document compilation pipeline 2026-08-13 13:10:39 -04:00
pnpm-lock.yaml Improve application workflows and user experience 2026-08-14 02:27:03 -04:00
pnpm-workspace.yaml chore: migrate knowledge-fs source tree 2026-07-20 04:54:20 -04:00
README.md Refactor codebase and remove obsolete implementations 2026-07-23 01:53:40 -04:00
secret-scan-allowlist.json feat(knowledge-fs): update space tag management and improve type annotations 2026-08-13 11:14:52 +08:00
tsconfig.base.json chore: migrate knowledge-fs source tree 2026-07-20 04:54:20 -04:00
turbo.json chore: migrate knowledge-fs source tree 2026-07-20 04:54:20 -04:00
upstream-provenance.json Expand application capabilities and refactor core workflows 2026-07-22 05:09:09 -04:00

KnowledgeFS

KnowledgeFS is Dify's backend knowledge runtime. It provides tenant-scoped ingestion, parsing, indexing, retrieval, KnowledgeFS commands, MCP tools, durable jobs, traces, and evaluation APIs.

KnowledgeFS is not an independently deployable product. It must run with the Dify API:

  • Dify owns model and datasource plugin credentials.
  • Dify creates model and datasource plugin instances and performs plugin invocation.
  • Dify owns physical object storage through its configured STORAGE_TYPE.
  • KnowledgeFS reaches those capabilities only through the authenticated Dify inner API.
  • KNOWLEDGE_INTEGRATED_MODE_ENABLED is a Workspace rollout/cutover gate; it never selects a different runtime or credential owner.

Runtime architecture

Dify API
  ├─ model manager / plugin daemon
  ├─ datasource plugins
  ├─ unified object storage
  └─ authenticated inner API
          │
          ▼
KnowledgeFS API
  ├─ document compilation and retrieval
  ├─ KnowledgeFS / MCP command surfaces
  ├─ PostgreSQL repositories and durable jobs
  └─ optional Unstructured parser dependency

Main directories:

apps/api/                              KnowledgeFS backend entrypoint
packages/api/                          Hono gateway, repositories, retrieval, jobs, auth
packages/adapters/                     Database, Dify storage, cache, and queue adapters
packages/dify-model-runtime-client/    Bounded Dify model inner-API client
packages/dify-datasource-runtime-client/
                                       Bounded Dify datasource inner-API client
packages/core/                         Shared contracts and schemas
packages/database/                     Schema catalog and SQL migrations
packages/compute/                      Bounded pure TypeScript compute
packages/parsers/                      Native and Unstructured parser adapters
infra/local/                           Developer harness; requires a running Dify API
infra/kubernetes/                      Inert Dify integration baseline

The repository still contains reusable lower-level adapters and an optional local Admin test harness. They are development assets, not alternative production deployment modes.

Required production configuration

The canonical Dify Compose service loads docker/envs/core-services/knowledge-fs.env.example. Operator-owned inputs are limited to:

  • DATABASE_URL
  • DIFY_INNER_API_URL and DIFY_INNER_API_KEY, injected by Dify Compose
  • UNSTRUCTURED_API_URL and optional UNSTRUCTURED_API_KEY
  • KnowledgeFS capability/JWKS and document-compilation rollout settings

Do not configure storage-provider credentials, model-provider keys, datasource credentials, or a direct Plugin Daemon endpoint in KnowledgeFS. The Dify inner key must match INNER_API_KEY_FOR_PLUGIN.

See production deployment and the operator manual.

Development

Prerequisites:

  • Node.js 22+
  • pnpm 10.33.0 through Corepack
  • Docker
  • A reachable Dify API

Install dependencies:

corepack enable
pnpm install
cp infra/local/.env.example infra/local/.env

Set DIFY_INNER_API_URL and DIFY_INNER_API_KEY in the ignored local env, then start the local database and parser:

pnpm dev:infra
pnpm local:db:migrate

Run the backend from source:

pnpm dev:api

For the optional local Admin test harness:

pnpm --filter @knowledge/admin dev

Run the bounded local smoke after Dify and the local processes are available:

pnpm local:happy-path

It validates health, workspace bootstrap, Markdown upload, parse artifacts, and query evidence. Use LOCAL_SMOKE_ADMIN_BASE when the Admin harness is not on its default port. Other useful forms:

LOCAL_SMOKE_RUN_MIGRATIONS=1 pnpm local:happy-path
pnpm local:happy-path:durable
pnpm local:happy-path:api

The durable smoke requires database health and Dify-backed object-storage health. The API-only smoke skips the Admin BFF.

See the local developer guide for details.

Validation

pnpm typecheck
pnpm test
pnpm lint:backend
pnpm openapi:export:test
pnpm db:migrations:check
pnpm compose:middleware:test
pnpm compose:apps:test
pnpm dify:compose:config
git diff --check

Build the backend production bundle or image:

pnpm --filter @knowledge/api-app build:prod
pnpm docker:api:build
pnpm docker:api:bundle-smoke

The isolated image smoke proves the bundle can boot and remains unhealthy while Dify is absent; a Dify Compose/Kubernetes smoke is required to validate the real inner API, storage, database, models, and datasources.

API and design references