> ## Documentation Index
> Fetch the complete documentation index at: https://docs.agentscope.io/llms.txt
> Use this file to discover all available pages before exploring further.

# Create a new knowledge base

> Create a new knowledge base for the authenticated user.

Allocates a fresh vector store collection sized to the embedding
model's output dimension and persists the knowledge base record.

Args:
    body (`CreateKnowledgeBaseRequest`):
        Knowledge base name, description, and embedding model
        configuration.
    user_id (`str`):
        Injected authenticated user ID.
    service (`KnowledgeBaseService`):
        Injected knowledge base service.

Returns:
    `CreateKnowledgeBaseResponse`:
        The server-assigned knowledge base identifier.



## OpenAPI

````yaml /versions/2.0.4dev/en/deploy/openapi.json post /knowledge_bases/
openapi: 3.1.0
info:
  title: AgentScope
  version: 2.0.3
servers: []
security: []
paths:
  /knowledge_bases/:
    post:
      tags:
        - knowledge_bases
      summary: Create a new knowledge base
      description: |-
        Create a new knowledge base for the authenticated user.

        Allocates a fresh vector store collection sized to the embedding
        model's output dimension and persists the knowledge base record.

        Args:
            body (`CreateKnowledgeBaseRequest`):
                Knowledge base name, description, and embedding model
                configuration.
            user_id (`str`):
                Injected authenticated user ID.
            service (`KnowledgeBaseService`):
                Injected knowledge base service.

        Returns:
            `CreateKnowledgeBaseResponse`:
                The server-assigned knowledge base identifier.
      operationId: create_knowledge_base_knowledge_bases__post
      parameters:
        - name: x-user-id
          in: header
          required: true
          schema:
            type: string
            description: >-
              Caller's user ID. Temporary header-based identity; will be
              replaced by JWT auth.
            title: X-User-Id
          description: >-
            Caller's user ID. Temporary header-based identity; will be replaced
            by JWT auth.
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/CreateKnowledgeBaseRequest'
      responses:
        '201':
          description: Successful Response
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/CreateKnowledgeBaseResponse'
        '404':
          description: Not found
        '422':
          description: Validation Error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/HTTPValidationError'
components:
  schemas:
    CreateKnowledgeBaseRequest:
      properties:
        name:
          type: string
          title: Name
          description: Display name of the knowledge base.
        description:
          type: string
          title: Description
          description: Free-form description shown in the UI.
          default: ''
        embedding_model_config:
          $ref: '#/components/schemas/EmbeddingModelConfig'
          description: >-
            Embedding model used both at indexing and at query time. Cannot be
            changed after creation — switching would invalidate every previously
            inserted vector.
      type: object
      required:
        - name
        - embedding_model_config
      title: CreateKnowledgeBaseRequest
      description: Request body for creating a new knowledge base.
    CreateKnowledgeBaseResponse:
      properties:
        knowledge_base_id:
          type: string
          title: Knowledge Base Id
          description: Server-assigned knowledge base identifier.
      type: object
      required:
        - knowledge_base_id
      title: CreateKnowledgeBaseResponse
      description: Response body after creating a knowledge base.
    HTTPValidationError:
      properties:
        detail:
          items:
            $ref: '#/components/schemas/ValidationError'
          type: array
          title: Detail
      type: object
      title: HTTPValidationError
    EmbeddingModelConfig:
      properties:
        type:
          type: string
          title: Type
        credential_id:
          type: string
          title: Credential Id
        model:
          type: string
          title: Model
        dimensions:
          type: integer
          exclusiveMinimum: 0
          title: Dimensions
        parameters:
          additionalProperties: true
          type: object
          title: Parameters
      type: object
      required:
        - type
        - credential_id
        - model
        - dimensions
      title: EmbeddingModelConfig
      description: |-
        Configuration for constructing an embedding model from a credential.

        Mirrors :class:`ChatModelConfig` but targets
        :class:`~agentscope.embedding.EmbeddingModelBase` subclasses.
        Used by :class:`KnowledgeBaseRecord` to persist the user's
        embedding model selection.
    ValidationError:
      properties:
        loc:
          items:
            anyOf:
              - type: string
              - type: integer
          type: array
          title: Location
        msg:
          type: string
          title: Message
        type:
          type: string
          title: Error Type
        input:
          title: Input
        ctx:
          type: object
          title: Context
      type: object
      required:
        - loc
        - msg
        - type
      title: ValidationError

````