Skip to main content
The Knowledge Retriever component allows plugins to provide external knowledge base retrieval capabilities for LangBot. When users create an external knowledge base in LangBot, they can choose a knowledge retriever provided by a plugin to retrieve knowledge.

Adding a Knowledge Retriever Component

A single plugin can add any number of knowledge retrievers. Execute the command lbp comp KnowledgeRetriever in the plugin directory and follow the prompts to enter the knowledge retriever configuration.
This will generate fastgpt.yaml and fastgpt.py files in the components/knowledge_retriever/ directory. The .yaml file defines the basic information and configuration parameters of the knowledge retriever, and the .py file is the handler for this retriever:

Manifest File: Knowledge Retriever

For configuration item format reference, see: Plugin Manifest Configuration Format

Plugin Handler

The following code will be generated by default (components/knowledge_retriever/<retriever_name>.py). You need to implement the knowledge retrieval logic in the retrieve method of the FastGPT class. Complete code can be found in langbot-plugin-demo.

Retrieval Context

RetrievalContext contains context information for this retrieval:

Retrieval Results

Retrieval results need to be converted to a list of RetrievalResultEntry objects, each representing a retrieved knowledge chunk:

Getting Configuration Parameters

Get user-configured parameter values using self.config.get(parameter_name, default_value):

Testing the Retriever

After creation, execute the command lbp run in the plugin directory to start debugging. Then in LangBot:
  1. Go to the “Knowledge Base” page
  2. Add an external knowledge base
  3. Select the knowledge retriever provided by your plugin and fill in the configuration
After saving, you can select this knowledge base in the LangBot pipeline.