Skip to main content
Community Hub
TL;DR

Link knowledge files to assets in Atlan using KnowledgeFile and the Python SDK (pyatlan). Append, replace, or remove linked files programmatically, and read the files linked to an asset.

Your AI can read this via Docs MCPInstall MCP →Connect

KnowledgeFile: Link knowledge files to assets

Use KnowledgeFile in the Atlan Python SDK to programmatically link knowledge files to assets. A linked file appears on the asset's profile, and the Description and README agents read it the next time they enrich that asset. See Link knowledge files to assets for what linking changes in the product.

A knowledge file can be linked to any asset type. The link lives on the asset side, in its knowledgeLinkedFiles relationship.

note

The knowledge_linked_files attribute is available from pyatlan 11.2.0. The append_knowledge_files, replace_knowledge_files, and remove_knowledge_files methods are available in releases after 11.2.0.

Prerequisites

Before you begin, make sure you have:

  • The Python SDK set up with an API token that can update the target assets
  • pyatlan 11.2.0 or later (see the note earlier in this page for the linking methods)
  • The qualified_name or GUID of the asset to link, and the GUIDs of the knowledge files. Knowledge files are uploaded through knowledge folders; find their GUIDs with a search on the KnowledgeFile type

Append knowledge files to asset

To link more knowledge files to an asset, without changing any of the files already linked to it:

Append knowledge files to an asset
from pyatlan.client.atlan import AtlanClient
from pyatlan.model.assets import KnowledgeFile, Table

client = AtlanClient()
table = client.asset.append_knowledge_files( # (1)
asset_type=Table, # (2)
qualified_name="default/snowflake/1657037873/SAMPLE_DATA/FOOD_BEVERAGE/ORDER_ANALYSIS", # (3)
files=[KnowledgeFile.ref_by_guid(guid="b4113341-251b-4adc-81fb-2420501c30e6"), # (4)
KnowledgeFile.ref_by_guid(guid="b267858d-8316-4c41-a56a-6e9b840cef4a")]
) # (5)
  1. Use the asset.append_knowledge_files() method, which constructs the necessary request and calls the necessary APIs to link the files all-in-one.
  2. The asset_type of the asset on which to link the files.
  3. The qualified_name of the asset on which to link the files.
    • Note: Alternatively the parameter name guid can be specified along with the guid of the asset on which to link the files.
  4. A list of knowledge file references. Each reference can be to a file by its GUID or its qualified_name. At the completion of this code, the files in this list are added to any other files already linked to the asset. Linking a file that's already linked is a no-op.
  5. The asset returned by this call is a minimal asset and won't contain any linked files. If you need an asset which contains them, retrieve it via the asset.get_by_guid or asset.get_by_qualified_name methods, or see Read linked knowledge files.

Replace knowledge files on asset

To replace all the knowledge files linked to an asset, meaning any not specified in the request are unlinked from the asset:

Replace knowledge files on an asset
from pyatlan.client.atlan import AtlanClient
from pyatlan.model.assets import KnowledgeFile, Table

client = AtlanClient()
table = client.asset.replace_knowledge_files( # (1)
asset_type=Table, # (2)
qualified_name="default/snowflake/1657037873/SAMPLE_DATA/FOOD_BEVERAGE/ORDER_ANALYSIS", # (3)
files=[KnowledgeFile.ref_by_guid(guid="b4113341-251b-4adc-81fb-2420501c30e6")] # (4)
) # (5)
  1. Use the asset.replace_knowledge_files() method, which constructs the necessary request and calls the necessary APIs to replace the linked files all-in-one.
  2. The asset_type of the asset on which to replace the files.
  3. The qualified_name of the asset on which to replace the files.
    • Note: Alternatively the parameter name guid can be specified along with the guid of the asset.
  4. A list of knowledge file references. After the completion of this code, only the files in this list are linked to the asset. Pass an empty list to unlink every file from the asset.
  5. The asset returned by this call is a minimal asset and won't contain any linked files.

Remove knowledge files from asset

To unlink some knowledge files from an asset, without unlinking all of the files on the asset:

Remove knowledge files from an asset
from pyatlan.client.atlan import AtlanClient
from pyatlan.model.assets import KnowledgeFile, Table

client = AtlanClient()
table = client.asset.remove_knowledge_files( # (1)
asset_type=Table, # (2)
qualified_name="default/snowflake/1657037873/SAMPLE_DATA/FOOD_BEVERAGE/ORDER_ANALYSIS", # (3)
files=[KnowledgeFile.ref_by_guid(guid="b4113341-251b-4adc-81fb-2420501c30e6")] # (4)
)
  1. Use the asset.remove_knowledge_files() method, which constructs the necessary request and calls the necessary APIs to unlink the files all-in-one.
  2. The asset_type of the asset from which to unlink the files.
  3. The qualified_name of the asset from which to unlink the files.
    • Note: Alternatively the parameter name guid can be specified along with the guid of the asset.
  4. A list of knowledge file references, by GUID. At the completion of this code, the files in this list are unlinked from the asset. Other linked files stay linked. Unlinking a file doesn't delete the knowledge file.

Read linked knowledge files

Linked files are a relationship on the asset, so you read them the same way as any other relationship: include knowledge_linked_files on a search, or retrieve the asset.

Read the knowledge files linked to an asset
from pyatlan.client.atlan import AtlanClient
from pyatlan.model.assets import Asset, KnowledgeFile, Table
from pyatlan.model.fluent_search import FluentSearch

client = AtlanClient()
request = (
FluentSearch()
.where(FluentSearch.active_assets()) # (1)
.where(FluentSearch.asset_type(Table))
.where(Table.QUALIFIED_NAME.eq("default/snowflake/1657037873/SAMPLE_DATA/FOOD_BEVERAGE/ORDER_ANALYSIS"))
.include_on_results(Asset.KNOWLEDGE_LINKED_FILES) # (2)
.include_on_relations(KnowledgeFile.NAME) # (3)
).to_request()

for table in client.asset.search(request):
for file in table.knowledge_linked_files or []: # (4)
print(file.guid, file.name)
  1. Restrict the search to active assets.
  2. Include the knowledge_linked_files relationship on each result.
  3. Include the file's name on the related KnowledgeFile objects, so you don't need a second lookup to display them.
  4. knowledge_linked_files is None when the asset has no linked files.

See also

Was this page helpful?