Skip to main content
The Parser component allows plugins to provide document parsing capabilities for LangBot. When a user uploads a document to a knowledge base, LangBot invokes the parser before the Knowledge Engine’s ingest step, extracting structured text from binary files such as PDF, Word, Markdown, etc. Relationship between Parser and KnowledgeEngine:
  • Parser is responsible for converting files to text (file → text)
  • KnowledgeEngine is responsible for indexing and retrieving text (text → chunks → vectors)
If the Knowledge Engine already has native document parsing capabilities (declared DOC_PARSING capability), users can choose to use the Knowledge Engine’s built-in parsing or an external Parser plugin.

Adding a Parser Component

A single plugin can add any number of parsers. Execute the command lbp comp Parser in the plugin directory and follow the prompts to enter the parser configuration.
This will generate pdf_parser.yaml and pdf_parser.py files in the components/parser/ directory. The .yaml file defines the parser’s basic information and supported MIME types, and the .py file is the handler for this parser:

Manifest File: Parser

supported_mime_types

supported_mime_types declares the file types this parser supports. Common MIME types:

Plugin Handler

The following code will be generated by default (components/parser/<parser_name>.py). You need to implement the parse method.

Parse Method

The parse method is called when a document is uploaded to a knowledge base (before Knowledge Engine ingestion):
ParseContext contains the following information:
ParseResult should return the parsing result:
TextSection represents a section of text extracted from the document:

Integration with KnowledgeEngine

When a user uploads a document, LangBot determines the parsing flow as follows:
  • If the user selects an external Parser plugin, LangBot first calls the Parser’s parse method, then passes the result to the Knowledge Engine’s ingest method via IngestionContext.parsed_content.
  • If the Knowledge Engine declares DOC_PARSING capability and the user does not select an external parser, the Knowledge Engine handles document parsing on its own.
KnowledgeEngine can check IngestionContext.parsed_content to determine whether pre-parsed content is available:

Cross-Plugin Parser Invocation

Before invoking a parser from another plugin, you can use self.plugin.list_parsers to discover the parsers currently available on the host:
If the list is empty, no connected Parser plugin currently supports that MIME type. After obtaining plugin_author and plugin_name, you can call self.plugin.invoke_parser:

Testing the Parser

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. Select a knowledge base and enter document management
  3. When uploading a file, select your plugin’s parser in the parser selector
  4. After uploading, verify that the document is correctly ingested