Use this plugin to import repository documents into CNB's knowledge base to support search or LLM RAG Q&A.
Currently supports Markdown, PDF, DOCX, and TXT files. File types are determined solely by their extensions.
As shown in the diagram above, the usage process consists of two steps:
Use this knowledge base plugin to import repository documents into CNB's knowledge base. This plugin runs in CNB cloud-native builds, automatically processes documents, and builds the knowledge base. Once the knowledge base is built, it can be used by downstream LLM applications.
After the knowledge base is built, use CNB's Open API for retrieval and combine with LLM to generate answers.
The typical RAG application workflow is as follows:
User query
Query understanding
Call knowledge base retrieval using CNB's Open API to get relevant documents
Build combined prompt with query + knowledge context, for example:
User: {user question} Knowledge Base: {knowledge base content} Please answer the user's question based on the knowledge base above.
cnbcool/knowledge-base
embedding_model: The embedding model, currently only supports hunyuan.include: Specifies the files to be included, using glob pattern matching.
Defaults to * to include all files. Supports multiple patterns separated
by commas, such as *.md,*.txt,*.pdf.exclude: Specifies the files to be excluded, using glob pattern matching.
By default, no files are excluded.
Supports multiple patterns separated by commas.chunk_size: Specifies the size of text chunks, defaulting to 1500.chunk_overlap: Specifies the number of overlapping tokens between two
adjacent chunks, defaulting to 0.ignore_process_failures: Whether to ignore document processing failures.
When set to true, the knowledge base will be updated even if there are
file processing failures. The default is false.Let me know if you need further adjustments!
Note:
excludehas higher priority thaninclude. Files excluded will not be included.
main:
push:
- stages:
- name: build knowledge base
image: cnbcool/knowledge-base
settings:
include: "**/**.md"
This API is used to query knowledge base content and return relevant information based on the provided query keywords.
Before starting, please read: CNB Open API Usage Guide Access token requires permission:
repo-code:r(read repository code)
https://api.cnb.cool/{slug}/-/knowledge/base/queryNote:
{slug}should be replaced with the repository slug. For example, if the CNB official documentation knowledge base repository address ishttps://cnb.cool/cnb/docs, then{slug}iscnb/docs
The request body should be in JSON format and contain the following fields:
| Parameter Name | Type | Required | Description |
|---|---|---|---|
| query | string | Yes | Keywords or questions to query |
| top_k | number | No | Maximum number of results to return, default is 5 |
{
"query": "Cloud-native development configure custom buttons"
}
The response is in JSON format and contains an array of results, each with the following fields:
| Field Name | Type | Description |
|---|---|---|
| score | number | Relevance score, range 0-1 |
| chunk | string | Matched knowledge base content text |
| metadata | object | Content metadata |
| Field Name | Type | Description |
|---|---|---|
| hash | string | Unique hash value of the content |
| name | string | Document name |
| path | string | Document path |
| position | number | Position of the content in the original document |
| score | number | Relevance score |
[
{
"score": 0.8671732,
"chunk": "This cloud-native remote development solution is based on Docker...",
"metadata": {
"hash": "15f7a1fc4420cbe9d81a946c9fc88814",
"name": "quick-start",
"path": "vscode/quick-start.md",
"position": 0,
"score": 0.8671732
}
}
]
Note: {slug} is the repository slug where the knowledge base plugin is
running, e.g., cnb/docs for CNB official docs
curl -X "POST" "https://api.cnb.cool/{slug}/-/knowledge/base/query" \
-H "accept: application/json" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer ${token}" \
-d '{
"query": "Cloud-native development configure custom buttons"
}'
chunk field in the response contains the matched knowledge base
content fragment in Markdown format.score values indicate better matches.slug in the URL is the repository slug where the knowledge base
plugin is running.