create_knowledge_base

ArtificialIntelligenceApi.create_knowledge_base(role_id, knowledge_base_create_request, content_type=None, _request_timeout=None, _request_auth=None, _content_type=None, _headers=None, _host_index=0)

Create a new knowledge base

Creates an unstructured (vector RAG) or structured (SQL) knowledge base in Bedrock and DynamoDB. KnowledgebaseName is required and must be unique. Defaults to unstructured, which also requires EmbeddingModel. Structured requires DataStoreType; TenantName is required for redshift when multi-tenancy is enabled. Account limit is 100 knowledge bases. A 200 response means creation was initiated (unstructured) or datastore setup is in progress (structured).

Parameters:
  • role_id (str) – Amorphic role ID of the requesting user. Must be a role the authenticated user belongs to. (required)

  • knowledge_base_create_request (KnowledgeBaseCreateRequest) – KnowledgebaseName is required. Unstructured also requires EmbeddingModel. Structured requires DataStoreType (and TenantName for redshift when multi-tenancy is on). Description, Keywords, GuardRails, and SmartChunking are optional. (required)

  • content_type (str) – Request body media type.

  • _request_timeout (int, tuple(int, int), optional) – timeout setting for this request. If one number provided, it will be total request timeout. It can also be a pair (tuple) of (connection, read) timeouts.

  • _request_auth (dict, optional) – set to override the auth_settings for an a single request; this effectively ignores the authentication in the spec for a single request.

  • _content_type (str, Optional) – force content-type for the request.

  • _headers (dict, optional) – set to override the headers for a single request; this effectively ignores the headers in the spec for a single request.

  • _host_index (int, optional) – set to override the host_index for a single request; this effectively ignores the host_index in the spec for a single request.

Return type:

Status

Returns:

Returns the result object.

Request and Response Examples

HTTP: POST /ai/knowledgebases

Parameter examples

Name

In

Example

Content-Type

header

"application/json"

role_id

header

"custom-role-123e4567-e89b-12d3-a456-426614174000"

Request

KnowledgebaseName is required. Unstructured also requires EmbeddingModel. Structured requires DataStoreType (and TenantName for redshift when multi-tenancy is on). Description, Keywords, GuardRails, and SmartChunking are optional.

Unstructured vector knowledge base

{
  "KnowledgebaseName": "sales_docs_kb",
  "Description": "Product and sales documentation",
  "KnowledgebaseType": "unstructured",
  "EmbeddingModel": "amazon.titan-embed-text-v2:0",
  "Keywords": [
    "sales",
    "docs"
  ],
  "SmartChunking": false,
  "GuardRails": [
    {
      "Id": "gr-123e4567-e89b-12d3-a456-426614174000",
      "Version": "DRAFT"
    }
  ]
}

Minimal unstructured (name and embedding only)

{
  "KnowledgebaseName": "support_docs_kb",
  "EmbeddingModel": "amazon.titan-embed-text-v2:0"
}

Unstructured with smart chunking enabled

{
  "KnowledgebaseName": "research_docs_kb",
  "Description": "Research papers with contextual chunking",
  "EmbeddingModel": "amazon.titan-embed-text-v2:0",
  "SmartChunking": true
}

Structured Redshift knowledge base

{
  "KnowledgebaseName": "sales_sql_kb",
  "Description": "Natural language queries over sales tables",
  "KnowledgebaseType": "structured",
  "DataStoreType": "redshift",
  "TenantName": "tenant1",
  "Keywords": [
    "sales",
    "sql"
  ]
}

Structured S3 Athena knowledge base

{
  "KnowledgebaseName": "analytics_sql_kb",
  "Description": "Natural language queries over Athena tables",
  "KnowledgebaseType": "structured",
  "DataStoreType": "s3athena"
}

Success (HTTP 200)

Creation initiated. Unstructured Message is “Knowledge base creation initiated.”; structured Message is “Knowledge base creation successful. Data store setup is in progress.” Both include KnowledgebaseId.

Request / response example

{
  "Message": "Knowledge base creation initiated.",
  "KnowledgebaseId": "ABCDEFGHIJ"
}

Errors

Documented error codes: IPV-1008, IPV-1018, IPV-1020, IPV-1041, RS-1020, GE-1034, AI-1004, AUTH-1001, AUTH-1011, GE-1085, DB-1002.

HTTP 400

Input validation or authorization failure. Body is {“Message”: “<CODE> - <text>”}. Codes: IPV-1008 (missing/invalid fields or account quota), IPV-1018 (duplicate KnowledgebaseName), IPV-1020 (wrong field type), IPV-1041 (invalid DataStoreType), RS-1020 (invalid TenantName), GE-1034 (Bedrock quota exceeded), AI-1004 (AICore disabled), AUTH-1001 (missing role_id), AUTH-1011 (caller not authorized).

Missing role_id header

{
  "Message": "AUTH-1001 - Missing role information in event header"
}

Caller not authorized

{
  "Message": "AUTH-1011 - User does not have sufficient permission to perform this action"
}

Duplicate knowledge base name

{
  "Message": "IPV-1018 - Invalid parameter - Knowledgebase Name, parameter value already exists, use different value."
}

HTTP 500

Backend failure. Body is {“Message”: “<CODE> - <text>”}. Codes: GE-1085 (unexpected backend failure), DB-1002 (persistence failure).

Unexpected backend failure

{
  "Message": "GE-1085 - An unexpected error occurred"
}