[Feature]: Let data source sync fill CustomMetadata and tags, with per-resource profiles
Affected Component
Backend Service & API
Problem Description
Documents synced from a data source reach the knowledge base with no descriptive metadata and no tags beyond the data source's own name. This matters most in a knowledge base fed by one wiki where every space or collection holds a different kind of document: meeting notes in one, policies in another, FAQs, specs, RFCs. Two things are then impossible:
- The model cannot tell what it is reading. A retrieved chunk from a superseded policy looks the same as one from a current FAQ.
- An agent or session cannot be scoped to one kind of document. For example, a support agent should search only FAQs and policies, never internal specs.
The machinery for both already exists. Data source ingestion just never feeds it.
Descriptive metadata the model already reads. Knowledge.CustomMetadata (internal/types/knowledge.go:227) is kept separate from the internal Metadata by design. It already reaches the model in three places:
- the agent's search results, as a
<metadata>block per document (internal/agent/tools/search_knowledge.go:873); - the chat context (
internal/application/service/chat_pipeline/into_chat_message.go:279); - the summary prompt (
internal/application/service/knowledge_process.go:1141).
It is only ever written by hand, through the knowledge update API.
Filtering that already works. Tags are the one retrieval filter documents have. A session or agent tag scope is resolved to knowledge IDs through ListKnowledgeIDsByTagIDs (internal/application/service/session_knowledge_qa.go:596). A data source gets exactly one tag, named after itself (resolveAutoTagIDs, internal/application/service/datasource_service.go:822).
What a sync writes today.
FetchedItem(internal/types/datasource.go:313) has no field for descriptive metadata or tags. Everything a connector knows goes into the internalMetadata, which the model never sees: IDs,channel, revisions.- Notion writes database properties into the document body instead (
internal/datasource/connector/notion/connector.go:546). - A changed document is deleted and re-created on every sync (
internal/application/service/datasource_service.go:1333). SoCustomMetadataor tags a user added by hand disappear at the next edit in the source.
Proposed Solution
Feed the two existing channels from data source sync, with three layers per document. A higher layer overrides a lower one.
1. Per-resource profiles, configured by the user (applied by the service, generic).
// DataSourceConfig.Settings
"resource_profiles": {
"<resource id>": { // a collection / space / folder the user selected
"document_type": "Policy",
"tags": ["HR", "Internal"],
"metadata": { "audience": "employees" }
}
}The service already knows every item's SourceResourceID, so it can apply the matching profile itself. No connector needs code for this layer, and every connector gets it at once. Saving changed profiles can update the data source's existing knowledge in place: CustomMetadata and tags only, no re-ingest.
2. Source-derived metadata, supplied by each connector. Add two optional fields to FetchedItem:
// CustomMetadata carries descriptive, model-visible fields derived from the
// source (collection, template, source URL, ...). Written to
// Knowledge.CustomMetadata; internal IDs stay in Metadata.
CustomMetadata map[string]string
// TagNames are tags derived from the source; the service finds or creates
// them by name, as it already does for the data source's own tag.
TagNames []stringFor Outline (#3187) this means:
collection,source_urlandsource_updated_at;template: the name of the template the document was created from, onetemplates.listcall per sync on Outline ≥ 1.6;- a tag named after the collection.
Notion could move database properties here instead of into the body.
3. The LLM's guess, as a fallback for context only. KnowledgeProfile.DocType (internal/types/knowledge_profile.go:36) is already generated with the summary. When neither layer above sets a document type, it could fill in the model-visible context. It would never be used to filter, because it is not stable from run to run.
Two supporting changes:
- Keep user edits across re-ingest. The service records which
CustomMetadatakeys and tags it wrote. On re-ingest it rewrites those and carries over the rest, so hand edits survive a source edit. - Refresh metadata without re-embedding. #3187 introduces
FetchedItem.MoveOnly: content unchanged, so the service updates onlyfolder_pathand keeps chunks and embeddings (see #3450). Generalising it toContentUnchanged, which re-applies folder,CustomMetadataand tags, lets a renamed collection or template propagate without re-parsing anything.
The existing CustomMetadata limits apply: 20 fields, 64-character keys, 1000-character values. Profiles win over source-derived fields when the cap is reached.
Alternatives
- A metadata filter on retrieval, as #2090 proposes (
metadata_filteronknowledge_search). It is more expressive, but it is a new filtering surface across every retriever backend. Tags already filter, and #3361 would make them cheaper, so this proposal deliberately stays on tags. Letting the agent choose adocument_typefilter by itself could come later on top of either approach. - One knowledge base per document type. This works today, but it multiplies data sources and credentials, and it breaks cross-type questions.
- Rely on the LLM's
DocTypealone. It needs no configuration, but labels drift between runs, so it cannot back an access scope.
Impact
Many users would benefit
Use Case
A company syncs its self-hosted Outline wiki: 15 collections and about 1,100 documents. The "HR" collection holds policies, "Meetings" holds notes created from a meeting template, and "Support" holds customer-facing FAQs. With this proposal:
- the support agent is scoped to the
SupportandPolicytags; - answers cite a document with its type and last update date;
- renaming the meeting template or retagging a collection is a metadata update, not a re-embedding of hundreds of documents.
Additional Information
Verified against main @ 9842e51d (2026-09-29).
Questions for maintainers before any code:
- Is feeding
CustomMetadataand tags the direction you want, rather than a new metadata filter like #2090's? - Should
resource_profilesbe a generic key inDataSourceConfig.Settingsthat the service interprets (the proposal), or stay connector-specific? - Is carrying hand-edited
CustomMetadataand tags over a re-ingest the semantics you want, or should a synced document be fully owned by its source? - Is it acceptable to generalise #3187's
MoveOnlyintoContentUnchanged?
Related: #2090 (metadata and metadata filtering), #289 (document type as a retrieval signal), #3361 (tag filter pushdown), #3450 (source folder structure; MoveOnly), #2024 (document-level ACL: the same FetchedItem channel could later carry ACL fields), #3016 (source timestamps).
I am happy to implement this, split in two:
FetchedItem.CustomMetadata/TagNamesplus preserving user edits;resource_profileswith its UI in the data source dialog.
The Outline source-derived fields would follow once the first part lands.
Confirmation
- I have searched existing issues and confirmed this is a new request
- I understand this request may need discussion and evaluation
Source: Tencent/WeKnora