---
title: "创建知识库"
method: POST
path: "/knowledge-bases"
tags: ["知识库"]
---

# 创建知识库

`POST /knowledge-bases`

创建新的知识库

## Request body

- GithubComTencentWeKnoraInternalTypesKnowledgeBase
  - `asr_config` GithubComTencentWeKnoraInternalTypesASRConfig
    - `enabled` boolean
    - `language` string — optional: language hint for transcription
    - `model_id` string
  - `chunk_count` integer — Chunk count (not stored in database, calculated on query)
  - `chunking_config` GithubComTencentWeKnoraInternalTypesChunkingConfig
    - `child_chunk_size` integer — ChildChunkSize is the size of child chunks used for embedding (default: 384). Only used when EnableParentChild is true.
    - `chunk_overlap` integer — Chunk overlap
    - `chunk_size` integer — Chunk size
    - `enable_parent_child` boolean — EnableParentChild enables two-level parent-child chunking strategy. When enabled, large parent chunks provide context while small child chunks are used for vector matching. Retrieval matches on child but returns parent content.
    - `languages` string[] — Languages hints the heuristic patterns. Empty = auto-detect from content. Examples: ["de"], ["en", "zh"].
    - `parent_chunk_size` integer — ParentChunkSize is the size of parent chunks (default: 4096). Only used when EnableParentChild is true.
    - `parser_engine_rules` GithubComTencentWeKnoraInternalTypesParserEngineRule[] — ParserEngineRules configures which parser engine to use for each file type. When empty, the builtin engine is used for all types.
      - `engine` string
      - `file_types` string[]
    - `separators` string[] — Separators
    - `strategy` string — Strategy selects the adaptive chunking tier. Empty / "legacy" preserves the historical recursive splitter; "auto" lets a profiler pick between heading-aware, heuristic and recursive tiers; "heading" / "heuristic" / "recursive" pin the tier explicitly.
    - `token_limit` integer — TokenLimit caps chunk size in approximate tokens. 0 = use ChunkSize as a character count.
  - `created_at` string — Creation time of the knowledge base
  - `creator_id` string — CreatorID records the user ID of whoever originally created the KB. Used by the tenant-level RBAC middleware to let Contributors edit their own KBs without granting them access to everyone else's. Nullable for backward compatibility with rows created before the RBAC migration backfilled the column to the tenant Owner.
  - `creator_name` string — CreatorName 是 CreatorID 对应用户的展示名（username / email 等）， 仅在列表场景由 handler 批量回填，不落库；为空表示创建者无法解析（用户已删除、 CreatorID 为空的老数据等）。前端用它在卡片来源徽章上做 mine vs tenant 的二分。
  - `deleted_at` GormDeletedAt
    - `time` string
    - `valid` boolean — Valid is true if Time is not NULL
  - `description` string — Description of the knowledge base
  - `embedding_model_id` string — ID of the embedding model
  - `extract_config` GithubComTencentWeKnoraInternalTypesExtractConfig
    - `enabled` boolean
    - `nodes` GithubComTencentWeKnoraInternalTypesGraphNode[]
      - `attributes` string[]
      - `chunks` string[]
      - `name` string
    - `relations` GithubComTencentWeKnoraInternalTypesGraphRelation[]
      - `node1` string
      - `node2` string
      - `type` string
    - `tags` string[]
    - `text` string
  - `faq_config` GithubComTencentWeKnoraInternalTypesFAQConfig
    - `index_mode` 'question_only' | 'question_answer'
    - `question_index_mode` 'combined' | 'separate'
  - `id` string — Unique identifier of the knowledge base
  - `image_processing_config` GithubComTencentWeKnoraInternalTypesImageProcessingConfig
    - `model_id` string — Model ID
  - `indexing_strategy` GithubComTencentWeKnoraInternalTypesIndexingStrategy
    - `graph_enabled` boolean — GraphEnabled enables knowledge graph entity/relation extraction
    - `keyword_enabled` boolean — KeywordEnabled enables keyword-based (BM25) search
    - `vector_enabled` boolean — VectorEnabled enables semantic vector embedding and search
    - `wiki_enabled` boolean — WikiEnabled enables automatic wiki page generation from documents
  - `is_pinned` boolean — IsPinned and PinnedAt are computed per-caller from user_kb_pins (see migration 000050). They used to be stored on the row itself, which made pinning a tenant-wide ordering decision gated behind the kb-edit RBAC guard. The columns are still present in legacy schemas for rollback safety but are no longer read or written by the application — both fields are tagged `gorm:"-"` so GORM ignores them on every CRUD call and the list handler stamps them after enriching with the caller's pin set.
  - `is_processing` boolean — IsProcessing indicates if there is a processing import task (for FAQ type knowledge bases)
  - `is_temporary` boolean — Whether this knowledge base is temporary (ephemeral) and should be hidden from UI
  - `knowledge_count` integer — Knowledge count (not stored in database, calculated on query)
  - `name` string — Name of the knowledge base
  - `pinned_at` string — PinnedAt records when the current caller pinned this knowledge base; nil when they have not.
  - `processing_count` integer — ProcessingCount indicates the number of knowledge items being processed (for document type knowledge bases)
  - `question_generation_config` GithubComTencentWeKnoraInternalTypesQuestionGenerationConfig
    - `enabled` boolean
    - `question_count` integer — Number of questions to generate per chunk (default: 3, max: 10)
  - `share_count` integer — ShareCount indicates the number of organizations this knowledge base is shared with (not stored in database)
  - `storage_config` GithubComTencentWeKnoraInternalTypesStorageConfig
    - `app_id` string — App ID (COS specific)
    - `bucket_name` string — Bucket Name
    - `endpoint` string — Endpoint (S3 specific) - e.g., s3.amazonaws.com, oss-cn-hangzhou.aliyuncs.com
    - `force_path_style` boolean — ForcePathStyle (S3 specific) - whether to use path-style URLs
    - `path_prefix` string — Path Prefix
    - `provider` string — Provider: "cos", "minio", "s3"
    - `region` string — Region
    - `secret_id` string — Secret ID (COS) / Access Key ID (S3, MinIO)
    - `secret_key` string — Secret Key (COS) / Secret Access Key (S3, MinIO)
    - `use_ssl` boolean — UseSSL (S3 specific) - whether to use HTTPS
  - `storage_provider_config` GithubComTencentWeKnoraInternalTypesStorageProviderConfig
    - `provider` string — "local", "minio", "cos", "tos", "s3", "oss", "ks3", "obs"
  - `summary_model_id` string — Summary model ID
  - `tenant_id` integer — Tenant ID
  - `type` string — Type of the knowledge base (document, faq, etc.)
  - `updated_at` string — Last updated time of the knowledge base
  - `vector_store_id` string — VectorStoreID references the VectorStore this knowledge base is bound to. When nil, the KB falls back to the tenant's effective engines derived from the RETRIEVE_DRIVER environment variable (env store flow). This field is set once at creation time and must not be modified afterwards; enforcement lives at the GORM layer (`<-:create`) plus the service-layer KB update path, which omits this field from its update DTO.
  - `vlm_config` GithubComTencentWeKnoraInternalTypesVLMConfig
    - `api_key` string — API Key
    - `base_url` string — Base URL
    - `enabled` boolean
    - `interface_type` string — Interface Type: "ollama" or "openai"
    - `model_id` string
    - `model_name` string — 兼容老版本 Model Name
  - `wiki_config` GithubComTencentWeKnoraInternalTypesWikiConfig
    - `extraction_granularity` 'focused' | 'standard' | 'exhaustive'
    - `ingest_batch_size` integer — IngestBatchSize controls how many pending ops a single batch processes before scheduling a follow-up. 0 falls back to the hard-coded default (5). Operators on large KBs (4w+ docs) can raise this to 10–20 to amortize the lock-acquire / index-rebuild overhead across more documents per round.
    - `ingest_map_parallel` integer — IngestMapParallel sets the errgroup limit for the Map phase (per-document extraction + summary + chunk citation). 0 falls back to 10. Bound by the LLM provider's concurrency limit and the worker's outbound HTTP pool.
    - `ingest_reduce_parallel` integer — IngestReduceParallel sets the errgroup limit for the Reduce phase (per-slug page write). 0 falls back to 10. Bound by the same LLM concurrency / HTTP pool considerations as the Map phase, plus DB connection pool size.
    - `max_pages_per_ingest` integer — MaxPagesPerIngest limits pages created/updated per ingest operation (0 = no limit)
    - `synthesis_model_id` string — SynthesisModelID is the LLM model ID used for wiki page generation and updates

## Response `201`

创建的知识库

- object

## Other responses

- `400` — 请求参数错误

## Changes

- **2025-12-22** `e625bcd5b8b9` — 1 info
  - the endpoint scheme security `ApiKeyAuth` was added to the API
- **2025-12-16** `edf61e68559d` — 1 info
  - the endpoint scheme security `ApiKeyAuth` was removed from the API

[Change history](https://skmtc.dev/tencentblueking/apis/weknora-api/changes/knowledge-bases/post.md)

---

[API](https://skmtc.dev/tencentblueking/apis/weknora-api.md) · [All operations](https://skmtc.dev/tencentblueking/apis/weknora-api/llms.txt) · [OpenAPI document](https://skmtc-service-production.skmtc.workers.dev/v1/apis/tencentblueking/weknora-api/revisions/d113fcd208b2/schema)
