logo
0
0
Login

Knowledge Base Plugin

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.

Knowledge Preparation

Understanding the RAG Application Building Process

Plugin Usage

As shown in the diagram above, the usage process consists of two steps:

1. 📚 Data Preparation Phase

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.

2. 💻 LLM Application Development

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:

  1. User query

  2. Query understanding

  3. Call knowledge base retrieval using CNB's Open API to get relevant documents

  4. 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.
  1. Send the combined prompt to the LLM model, generate an answer, and return it to the user

Plugin Details

Plugin Image Name

cnbcool/knowledge-base

Parameter Description

  • 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: exclude has higher priority than include. Files excluded will not be included.

Using the Plugin in CNB

main: push: - stages: - name: build knowledge base image: cnbcool/knowledge-base settings: include: "**/**.md"

Using CNB's Open API for Knowledge Base Retrieval

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)

API Information

  • URL: https://api.cnb.cool/{slug}/-/knowledge/base/query
  • Method: POST
  • Content Type: application/json

Note: {slug} should be replaced with the repository slug. For example, if the CNB official documentation knowledge base repository address is https://cnb.cool/cnb/docs, then {slug} is cnb/docs

Request Parameters

The request body should be in JSON format and contain the following fields:

Parameter NameTypeRequiredDescription
querystringYesKeywords or questions to query
top_knumberNoMaximum number of results to return, default is 5

Request Example

{ "query": "Cloud-native development configure custom buttons" }

Response Content

The response is in JSON format and contains an array of results, each with the following fields:

Field NameTypeDescription
scorenumberRelevance score, range 0-1
chunkstringMatched knowledge base content text
metadataobjectContent metadata

metadata Field Details

Field NameTypeDescription
hashstringUnique hash value of the content
namestringDocument name
pathstringDocument path
positionnumberPosition of the content in the original document
scorenumberRelevance score

Response Example

[ { "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 } } ]

Usage Example

cURL Request Example

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" }'

Notes

  1. The chunk field in the response contains the matched knowledge base content fragment in Markdown format.
  2. Higher score values indicate better matches.
  3. The slug in the URL is the repository slug where the knowledge base plugin is running.

About

运行在 GPU 环境的知识库插件,对比普通插件,增加了使用 GPU 图片、PDF 进行 OCR 的逻辑。 Power by Hunyuan OCR