docs/docs/en/ai-employees/workflow/nodes/knowledge/retrieve-document.md
<PluginInfo name="ai-knowledge-base"></PluginInfo>
In NocoBase, the Retrieve document node searches an AI knowledge base in a workflow and returns matched document snippets. It is suitable before an AI employee node: retrieve knowledge base snippets with task input first, then pass the results to the AI employee as task context.
The Retrieve document node is asynchronous. Before using it, configure the knowledge base and make sure it already contains vectorized documents.
The example workflow listens for new records in Questions, sends matching text to Retrieve document, and passes the retrieval result to a downstream AI employee node for task processing.
Where:
Collection event receives task inputRetrieve document retrieves snippets from the knowledge baseAI employee processes the task based on snippetsIn real business workflows, the result generated by the AI employee usually needs to be saved. You can continue with database operation nodes after it. This guide omits those later saving steps to focus on the Retrieve document node.
This example is an independent retrieval workflow. Before configuring it, confirm that:
Questions collectionSelect Collection event as the trigger. In the trigger configuration:
Collection to the matching-text source collection, such as Main / QuestionsTrigger on to After record addedEach time an input record is added, the workflow automatically enters retrieval and task processing.
Add a Retrieve document node after the trigger. It is recommended to change the node key to an easy-to-reference name, such as retrieve_docs.
Key settings:
Knowledge baseInput matching text to the matching text fieldTop K to the maximum number of snippets to returnScore to the minimum similarity thresholdAfter execution, the node returns an array of document snippets. Each result contains id, content, score, and metadata, sorted by score from high to low.
In the AI employee node, write the retrieval result into the prompt. The example directly references the Retrieve document node output:
Task input: {{$context.data.f_b2izf5j4xx0}}
Knowledge base snippets:
{{$jobsMapByNodeKey.retrieve_docs}}
Use the snippets as context to complete the task. If the snippets are not enough, explain what information is missing.
retrieve_docs is the key of the retrieval node. If your node key is different, replace it with the actual key.
:::tip
If you only want to pass snippet text, reference the content field in the retrieval result through the variable selector. Passing the whole result array also includes score and metadata, which helps the AI judge source and relevance.
:::