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

# Create Knowledge Base

> ### Description
Creates an EGP knowledge base.

### Details
A knowledge base is a storage device for all data that needs to be accessible to EGP models.         Users can upload data from a variety of data sources into a knowledge base, and then query the         knowledge base for chunks that are semantically relevant to the query.

Every knowledge base must be associated with a fixed embedding model. This embedding model         will be used to embed all data that is stored in the knowledge base. The embedding model         cannot be changed once the knowledge base is created. Only the embedding models in the         dropdown menu below are supported.

#### Differences from V1
- V1 data ingestion consisted of knowledge bases, vector stores, and data connectors.         V1 Knowledge bases interacted with natural language, V1 vector stores interacted with         chunks and embeddings, and V1 data connectors set up automatic ingestion pipelines with third         party data sources.
- In V2, all data ingestion is done through knowledge bases. Low level configuration such as         chunking strategies and data sources are now handled by this unified knowledge base v2
upload API.
- The way data is stores in V2 allows for better observability on the ingestion progress and         content of the knowledge base.
- Reliability and scalability is also improved via distributed temporal workflows.

#### Backwards Compatibility
V2 and V1 Knowledge Bases are entirely separate and not backwards compatible. Users who         have existing V1 knowledge bases will need to migrate their data to V2 knowledge bases.



## OpenAPI

````yaml https://app.stainlessapi.com/api/spec/documented/sgp/openapi.yml post /v4/knowledge-bases
openapi: 3.1.0
info:
  title: EGP API V4
  description: >-
    This is the parent API for all EGP APIs. If you are looking for the EGP API,
    please go to https://api.egp.scale.com/docs.
  contact:
    name: Scale Generative AI Platform
    url: https://scale.com/genai-platform
  version: 0.1.0
servers:
  - url: https://api.egp.scale.com
security: []
tags:
  - name: Models
    description: Model API.
paths:
  /v4/knowledge-bases:
    post:
      tags:
        - Knowledge Bases
      summary: Create Knowledge Base
      description: >-
        ### Description

        Creates an EGP knowledge base.


        ### Details

        A knowledge base is a storage device for all data that needs to be
        accessible to EGP models.         Users can upload data from a variety
        of data sources into a knowledge base, and then query the        
        knowledge base for chunks that are semantically relevant to the query.


        Every knowledge base must be associated with a fixed embedding model.
        This embedding model         will be used to embed all data that is
        stored in the knowledge base. The embedding model         cannot be
        changed once the knowledge base is created. Only the embedding models in
        the         dropdown menu below are supported.


        #### Differences from V1

        - V1 data ingestion consisted of knowledge bases, vector stores, and
        data connectors.         V1 Knowledge bases interacted with natural
        language, V1 vector stores interacted with         chunks and
        embeddings, and V1 data connectors set up automatic ingestion pipelines
        with third         party data sources.

        - In V2, all data ingestion is done through knowledge bases. Low level
        configuration such as         chunking strategies and data sources are
        now handled by this unified knowledge base v2

        upload API.

        - The way data is stores in V2 allows for better observability on the
        ingestion progress and         content of the knowledge base.

        - Reliability and scalability is also improved via distributed temporal
        workflows.


        #### Backwards Compatibility

        V2 and V1 Knowledge Bases are entirely separate and not backwards
        compatible. Users who         have existing V1 knowledge bases will need
        to migrate their data to V2 knowledge bases.
      operationId: POST-V4-/v2/knowledge-bases
      parameters:
        - name: x-selected-account-id
          in: header
          required: false
          schema:
            anyOf:
              - type: string
              - type: 'null'
            title: Account ID Header
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/CreateKnowledgeBaseRequestV2'
      responses:
        '200':
          description: Successful Response
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/CreateKnowledgeBaseResponse'
        '422':
          description: Validation Error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/HTTPValidationError'
      security:
        - APIKeyHeader: []
      x-codeSamples:
        - lang: Python
          source: |-
            import os
            from scale_gp import SGPClient

            client = SGPClient(
                api_key=os.environ.get("SGP_API_KEY"),  # This is the default and can be omitted
            )
            create_knowledge_base_response = client.knowledge_bases.create(
                embedding_config={
                    "model_deployment_id": "model_deployment_id",
                    "type": "models_api",
                },
                knowledge_base_name="knowledge_base_name",
            )
            print(create_knowledge_base_response.knowledge_base_id)
        - lang: Go
          source: "package main\n\nimport (\n\t\"context\"\n\t\"fmt\"\n\n\t\"github.com/stainless-sdks/sgp-go\"\n\t\"github.com/stainless-sdks/sgp-go/option\"\n)\n\nfunc main() {\n\tclient := sgp.NewClient(\n\t\toption.WithAPIKey(\"My API Key\"),\n\t)\n\tcreateKnowledgeBaseResponse, err := client.KnowledgeBases.New(context.TODO(), sgp.KnowledgeBaseNewParams{\n\t\tEmbeddingConfig: sgp.F[sgp.KnowledgeBaseNewParamsEmbeddingConfigUnion](sgp.KnowledgeBaseNewParamsEmbeddingConfigEmbeddingConfigModelsAPI{\n\t\t\tModelDeploymentID: sgp.F(\"model_deployment_id\"),\n\t\t\tType:              sgp.F(sgp.KnowledgeBaseNewParamsEmbeddingConfigEmbeddingConfigModelsAPITypeModelsAPI),\n\t\t}),\n\t\tKnowledgeBaseName: sgp.F(\"knowledge_base_name\"),\n\t})\n\tif err != nil {\n\t\tpanic(err.Error())\n\t}\n\tfmt.Printf(\"%+v\\n\", createKnowledgeBaseResponse.KnowledgeBaseID)\n}\n"
components:
  schemas:
    CreateKnowledgeBaseRequestV2:
      properties:
        embedding_config:
          $ref: '#/components/schemas/EmbeddingConfig'
          description: The configuration of the embedding
        account_id:
          title: Account Id
          description: >-
            Account to create knowledge base in. If you have access to more than
            one account, you must specify an account_id
          type: string
        knowledge_base_name:
          type: string
          title: Knowledge Base Name
          description: A unique name for the knowledge base
        metadata:
          title: Metadata
          description: Metadata associated with the knowledge base
          additionalProperties: true
          type: object
        kb_index_configuration:
          $ref: '#/components/schemas/KBIndexConfiguration'
          description: >-
            Configuration for metadata schema in the knowledge base, including
            field definitions and index settings
      type: object
      required:
        - embedding_config
        - knowledge_base_name
      title: CreateKnowledgeBaseRequestV2
    CreateKnowledgeBaseResponse:
      properties:
        knowledge_base_id:
          type: string
          title: Knowledge Base Id
          description: The unique ID of the created knowledge base
      type: object
      required:
        - knowledge_base_id
      title: CreateKnowledgeBaseResponse
    HTTPValidationError:
      properties:
        detail:
          items:
            $ref: '#/components/schemas/ValidationError'
          type: array
          title: Detail
      type: object
      title: HTTPValidationError
    EmbeddingConfig:
      anyOf:
        - $ref: '#/components/schemas/EmbeddingConfigModelsAPI'
        - $ref: '#/components/schemas/EmbeddingConfigBase'
      title: EmbeddingConfig
    KBIndexConfiguration:
      properties:
        fields:
          additionalProperties: true
          type: object
          title: Fields
          description: >-
            Schema defining metadata fields for the knowledge base. Each field
            can have properties: type (string, int32, int64, double, boolean,
            complex), filterable (bool), searchable (bool). Complex types can
            have nested 'fields' with the same structure.
          example:
            author:
              fields:
                age:
                  filterable: true
                  type: int32
                name:
                  filterable: true
                  searchable: true
                  type: string
              type: complex
            priority:
              filterable: true
              type: int32
        max_index_size:
          title: Max Index Size
          description: >-
            Maximum size (in bytes) for the index. If not provided, uses the
            default.
          type: integer
          exclusiveMinimum: 0
      additionalProperties: true
      type: object
      required:
        - fields
      title: KBIndexConfiguration
      description: >-
        Configuration for knowledge base metadata schema.


        This configuration determines how metadata fields are created in the
        search index.
    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
          additionalProperties: true
      type: object
      required:
        - loc
        - msg
        - type
      title: ValidationError
    EmbeddingConfigModelsAPI:
      properties:
        type:
          type: string
          const: models_api
          title: Type
          description: The type of the embedding configuration.
        model_deployment_id:
          type: string
          title: Model Deployment Id
          description: The ID of the deployment of the created model in the Models API V3.
      type: object
      required:
        - type
        - model_deployment_id
      title: EmbeddingConfigModelsAPI
    EmbeddingConfigBase:
      properties:
        type:
          type: string
          const: base
          title: Type
          description: The type of the embedding configuration.
          default: base
        embedding_model:
          $ref: '#/components/schemas/EmbeddingModelName'
          description: >-
            The name of the base embedding model to use. To use custom models,
            change to type 'models'.
      type: object
      required:
        - embedding_model
      title: EmbeddingConfigBase
    EmbeddingModelName:
      type: string
      enum:
        - sentence-transformers/all-MiniLM-L12-v2
        - sentence-transformers/all-mpnet-base-v2
        - sentence-transformers/multi-qa-distilbert-cos-v1
        - sentence-transformers/paraphrase-multilingual-mpnet-base-v2
        - openai/text-embedding-ada-002
        - openai/text-embedding-3-small
        - openai/text-embedding-3-large
        - embed-english-v3.0
        - embed-english-light-v3.0
        - embed-multilingual-v3.0
        - gemini/text-embedding-005
        - gemini/text-multilingual-embedding-002
        - gemini/gemini-embedding-001
      title: EmbeddingModelName
  securitySchemes:
    APIKeyHeader:
      type: apiKey
      in: header
      name: x-api-key

````