Skip to main content
The Knowledge Engine component allows plugins to provide full knowledge base indexing and retrieval capabilities for LangBot. When users create a knowledge base in LangBot, they can choose a Knowledge Engine provided by a plugin to manage document ingestion, retrieval, and deletion. Plugins can also bridge advanced knowledge base services such as Dify, RAGFlow, FastGPT, and more.

Adding a Knowledge Engine Component

A single plugin can add any number of Knowledge Engines. Execute the command lbp comp KnowledgeEngine in the plugin directory and follow the prompts to enter the Knowledge Engine configuration.
This will generate simple_rag.yaml and simple_rag.py files in the components/knowledge_engine/ directory. The .yaml file defines the Knowledge Engine’s basic information and configuration schemas, and the .py file is the handler for this engine:

Manifest File: Knowledge Engine

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

creation_schema and retrieval_schema

Unlike the old KnowledgeRetriever component which used a single spec.config, KnowledgeEngine uses two separate schemas:
  • creation_schema: Parameters users fill in when creating a knowledge base. These are passed to the plugin via creation_settings during ingestion and retrieval.
  • retrieval_schema: Parameters users can adjust when querying the knowledge base. These are passed to the plugin via retrieval_settings.

Capability Declaration

KnowledgeEngine can declare its supported capabilities. LangBot uses these capability declarations to determine UI behavior and available operations:
Available capability constants:
Other retrieval behaviors (such as reranking, hybrid search, etc.) are controlled by the plugin’s retrieval_schema and do not need capability flags.

Plugin Handler

The following code will be generated by default (components/knowledge_engine/<engine_name>.py). You need to implement the three core methods: ingest, retrieve, and delete_document. Complete code can be found in the SimpleKnowledgeEngine example in langbot-plugin-demo.

Lifecycle Hooks

KnowledgeEngine provides two lifecycle hooks that are called when knowledge bases are created and deleted:

Document Ingestion

The ingest method is called when a user uploads a document to the knowledge base:
IngestionContext contains the following information:
FileObject contains file metadata:
IngestionResult should return the ingestion result:

Knowledge Retrieval

The retrieve method is called when the knowledge base is queried:
RetrievalContext contains the following information:
The LangBot host automatically injects a default top_k value (default 5) into retrieval_settings before passing it to the plugin. Plugins can access it via context.retrieval_settings.get('top_k', 5).The filters field contains Chroma-style where filter conditions extracted from retrieval_settings. When the caller provides filters in the retrieval settings (e.g., filtering by time range, file type, or custom metadata fields), the host populates this field so plugins can apply them during retrieval. If no filters are provided, this field is an empty dict.
RetrievalResponse should return the retrieval results:
RetrievalResultEntry represents a single retrieval result:

Document Deletion

The delete_document method is called when a user deletes a document from the knowledge base:

Host RAG APIs

KnowledgeEngine components can call LangBot host-provided RAG APIs via self.plugin, including embedding model invocation, vector database operations, and file retrieval.

Invoke Embedding Model

Vector Upsert

Each result returned by vector_search is a dict containing id (vector ID), score (distance score), and metadata (metadata provided during upsert). If you need text content in retrieval results, store the text in metadata during ingestion.

Vector Delete

The filters parameter supports Chroma-style where syntax for metadata filtering. Multiple top-level keys are AND-ed. Supported operators: $eq, $ne, $gt, $gte, $lt, $lte, $in, $nin. Example: {"file_id": {"$eq": "abc"}}.Note: Chroma, Qdrant, and SeekDB store full metadata and can filter on any field. Milvus and pgvector only store text, file_id, and chunk_uuid — filters on other fields will be silently ignored.

Testing the Knowledge Engine

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. Click “Create Knowledge Base”
  3. Select the Knowledge Engine provided by your plugin and fill in the configuration based on the engine’s creation_schema
  4. After creation, upload documents to test ingestion capabilities (if the engine declares DOC_INGESTION capability)
  5. Bind the knowledge base to a pipeline and test retrieval capabilities