dify/api/tests/unit_tests
Jyong 0340784d57 feat(knowledge-fs): add automatic metadata filtering to retrieval node
Bring the LLM-driven "automatic" metadata filtering mode from the legacy
Knowledge Retrieval node to the KnowledgeFS retrieval node
(knowledge-retrieval-v2).

Backend:
- Accept `automatic` in `metadata_filtering_mode` and add
  `metadata_model_config` to the node entity.
- Add `automatic_metadata_filter.py`, which reuses the legacy metadata
  filter prompt templates, invokes the configured model, parses the JSON
  answer and normalises operators/values against the KnowledgeFS
  metadata catalog before building custom metadata conditions.
- Resolve the shared metadata catalog across the selected spaces through
  the new `list_metadata_fields` app execution capability (paginated),
  fail closed on missing/unavailable models and catalog admission errors,
  fail open on extraction errors, and expose the outcome via
  `metrics.metadata_filtering` and `llm_usage`.
- Inject the default extractor from the node factory.
- Fix an unescaped brace in the legacy completion prompt template that
  broke `.format()`.

Frontend:
- Offer disabled/automatic/manual modes, normalise unknown persisted
  modes to disabled, store the automatic model and completion params,
  render the model selector through the shared MetadataFilter, and
  require a model when saving in automatic mode.

Co-Authored-By: Claude Code <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WnUM1CdV5LpcxZEQ2vu9Xc
2026-09-02 02:55:12 -04:00
..
clients test: enforce centralized config overrides (#40869) 2026-08-29 14:05:35 +00:00
commands Merge remote-tracking branch 'origin/main' into deploy/konwledge 2026-09-01 09:45:49 +08:00
configs fix(knowledge-fs): align retrieval test timeout 2026-09-01 13:51:15 -04:00
controllers feat(knowledge-fs): add profile-driven multimodal retrieval 2026-09-02 01:01:57 -04:00
core feat(knowledge-fs): add automatic metadata filtering to retrieval node 2026-09-02 02:55:12 -04:00
dev feat(knowledge-fs): add migration to merge agent drive and KnowledgeFS heads 2026-08-20 11:04:02 +08:00
enterprise/telemetry fix: add missing metrics back and enhance typing (#40935) 2026-08-21 09:46:45 +00:00
enums test: use typed config overrides in service coverage (#40848) 2026-08-18 11:59:58 +00:00
events Merge remote-tracking branch 'origin/main' into deploy/konwledge 2026-09-02 10:31:10 +08:00
extensions Merge remote-tracking branch 'origin/main' into deploy/konwledge 2026-09-02 10:31:10 +08:00
factories fix(api): align Service API OpenAPI contract (#41248) 2026-08-25 10:54:14 +00:00
fields test: migrate residual model sessions and ORM models to SQLite (#40531) 2026-08-18 12:23:02 +00:00
libs Merge remote-tracking branch 'origin/main' into deploy/konwledge 2026-09-02 10:31:10 +08:00
machinery refactor(api): move account lifecycle into application services (#40438) 2026-08-21 08:05:43 +00:00
migrations test(knowledge-fs): align sync policy expectations 2026-08-28 15:09:44 +08:00
models Merge remote-tracking branch 'origin/main' into deploy/konwledge 2026-09-02 10:31:10 +08:00
oss test: eliminate remaining whole config mocks (#40855) 2026-08-18 12:01:49 +00:00
providers/trace/unified_trace feat(trace): add provider-neutral unified tracing (#39451) 2026-08-21 11:28:18 +00:00
repositories Merge remote-tracking branch 'origin/main' into deploy/konwledge 2026-09-02 10:31:10 +08:00
services feat(knowledge-fs): add automatic metadata filtering to retrieval node 2026-09-02 02:55:12 -04:00
tasks fix(knowledge-fs): reconcile main merge regressions 2026-09-01 10:10:52 +08:00
tools fix: fix mcp output_schema is optional (#39453) 2026-07-28 02:31:18 +00:00
utils test: move pure integration cases to unit tests (#40705) 2026-08-25 06:19:48 +00:00
__init__.py
.gitignore
.ruff.toml refactor(api): replace legacy recommended app retrieval stack (#40395) 2026-08-20 13:13:43 +00:00
config_override.py test: enforce centralized config overrides (#40869) 2026-08-29 14:05:35 +00:00
conftest.py test: enforce centralized config overrides (#40869) 2026-08-29 14:05:35 +00:00
pyrefly.toml refactor(api): decouple system features and web adapters (#40772) 2026-09-01 11:50:52 +00:00
test_app_factory.py test: enforce centralized config overrides (#40869) 2026-08-29 14:05:35 +00:00
test_config_overrides.py test: enforce centralized config overrides (#40869) 2026-08-29 14:05:35 +00:00
test_constants.py test: enforce centralized config overrides (#40869) 2026-08-29 14:05:35 +00:00
test_makefile_backend_tests.py
test_pytest_dify.py refactor: thread explicit sessions through app retrieval paths (#38309) 2026-07-02 17:00:47 +00:00
test_sqlite_fixtures.py test: share unbound unit test sessions (#39690) 2026-07-28 14:12:08 +00:00