Back to Lobehub

Knowledge Base, File & Document Commands

.agents/skills/cli/references/knowledge.md

2.1.568.1 KB
Original Source

Knowledge Base, File & Document Commands

Knowledge Base (lh kb)

Manage knowledge bases for RAG (Retrieval-Augmented Generation). Supports directory tree structure with folders, documents, and file uploads.

Source: apps/cli/src/commands/kb.ts

lh kb list

bash
lh kb list [--json [fields]]

Table columns: ID, NAME, DESCRIPTION, UPDATED

lh kb view <id>

bash
lh kb view [fields]] < id > [--json

Displays: Name, description, full directory tree with all files and documents (recursively fetched). Shows indented tree structure with item type (File/Doc), file type, and size.

API: Uses file.getKnowledgeItems to recursively fetch items. Folders (custom/folder fileType) are traversed in parallel via Promise.all for performance.

lh kb create

bash
lh kb create -n [--avatar < name > [-d < desc > ] < url > ]
OptionDescriptionRequired
-n, --name <name>Knowledge base nameYes
-d, --description <desc>DescriptionNo
--avatar <url>Avatar URLNo

Output: Created KB ID. Note: backend returns ID as a string directly (not an object).

lh kb edit <id>

bash
lh kb edit [-d [--avatar < id > [-n < name > ] < desc > ] < url > ]

Requires at least one change flag. Errors if none specified.

lh kb delete <id>

bash
lh kb delete [--yes] < id > [--remove-files]
OptionDescription
--remove-filesAlso delete associated files
--yesSkip confirmation

lh kb add-files <knowledgeBaseId>

bash
lh kb add-files <kbId> --ids <fileId1> <fileId2> ...

Link existing files to a knowledge base.

lh kb remove-files <knowledgeBaseId>

bash
lh kb remove-files <kbId> --ids <fileId1> <fileId2> ... [--yes]

Unlink files from a knowledge base.

lh kb mkdir <knowledgeBaseId>

bash
lh kb mkdir < kbId > -n < name > [--parent < folderId > ]

Create a folder in a knowledge base. Uses document.createDocument with fileType: 'custom/folder'.

OptionDescriptionRequired
-n, --name <name>Folder nameYes
--parent <parentId>Parent folder IDNo

lh kb create-doc <knowledgeBaseId>

bash
lh kb create-doc [--parent < kbId > -t < title > [-c < content > ] < folderId > ]

Create a document in a knowledge base. Uses document.createDocument with fileType: 'custom/document'.

OptionDescriptionRequired
-t, --title <title>Document titleYes
-c, --content <text>Document contentNo
--parent <parentId>Parent folder IDNo

lh kb move <id>

bash
lh kb move < id > --type < file | doc > [--parent < folderId > ]

Move a file or document to a different folder (or to root if --parent is omitted).

OptionDescriptionDefault
--type <type>Item type: file or docfile
--parent <parentId>Target folder ID (omit for root)-

Uses document.updateDocument for docs, file.updateFile for files.

lh kb upload <knowledgeBaseId> <filePath>

bash
lh kb upload <kbId> <filePath> [--parent <folderId>]

Upload a local file to a knowledge base via S3 presigned URL.

OptionDescription
--parent <parentId>Parent folder ID

Flow: Compute SHA-256 hash → get presigned URL via upload.createS3PreSignedUrl → PUT to S3 → create file record via file.createFile.


File Management (lh file)

Manage uploaded files.

Source: apps/cli/src/commands/file.ts

lh file list

bash
lh file list [--kb-id [-L [--json [fields]] < id > ] < n > ]
OptionDescriptionDefault
--kb-id <id>Filter by knowledge base-
-L, --limit <n>Maximum items30

Table columns: ID, NAME, TYPE, SIZE, UPDATED

lh file view <id>

bash
lh file view [fields]] < id > [--json

Displays: Name, type, size, chunking status, embedding status.

lh file delete <ids...>

bash
lh file delete [--yes] < id1 > [id2...]

Supports deleting multiple files at once.

lh file recent

bash
lh file recent [-L [--json [fields]] < n > ]
OptionDescriptionDefault
-L, --limit <n>Number of items10

Document Management (lh doc)

Manage text documents (notes, wiki pages).

Source: apps/cli/src/commands/doc.ts

lh doc list

bash
lh doc list [-L [--file-type [--source-type [--json [fields]] < n > ] < type > ] < type > ]
OptionDescriptionDefault
-L, --limit <n>Maximum items30
--file-type <type>Filter by file type-
--source-type <type>Filter by source type (file, web, api, topic)-

Table columns: ID, TITLE, TYPE, UPDATED

lh doc view <id>

bash
lh doc view [fields]] < id > [--json

Displays: Title, type, KB association, updated time, full content.

lh doc create

bash
lh doc create -t [-F [--parent [--slug [--kb [--file-type < title > [-b < body > ] < path > ] < id > ] < slug > ] < id > ] < type > ]
OptionDescriptionRequired
-t, --title <title>Document titleYes
-b, --body <content>Document body textNo
-F, --body-file <path>Read body from fileNo
--parent <id>Parent document IDNo
--slug <slug>Custom URL slugNo
--kb <id>Knowledge base ID to associate withNo
--file-type <type>File type (e.g. custom/document, custom/folder)No

-b and -F are mutually exclusive; -F reads the file content as the body.

lh doc batch-create <file>

Batch create documents from a JSON file. The file must contain a non-empty array of document objects.

bash
lh doc batch-create documents.json

Each object in the array can have: title, content, fileType, knowledgeBaseId, parentId, slug.

lh doc edit <id>

bash
lh doc edit [-b [-F [--parent [--file-type < id > [-t < title > ] < body > ] < path > ] < id > ] < type > ]

lh doc delete <ids...>

bash
lh doc delete [--yes] < id1 > [id2...]

lh doc parse <fileId>

Parse an uploaded file into a document.

bash
lh doc parse [--json [fields]] < fileId > [--with-pages]
OptionDescription
--with-pagesPreserve page structure

Output: Parsed title and content preview.

Associate a document with a topic. Creates a linked copy via the notebook router.

bash
lh doc link-topic <docId> <topicId>

lh doc topic-docs <topicId>

List documents associated with a topic.

bash
lh doc topic-docs [--json [fields]] < topicId > [--type < type > ]
OptionDescription
--type <type>Filter by type (article, markdown, note, report)