add_resources_to_knowledge_base¶
- ArtificialIntelligenceApi.add_resources_to_knowledge_base(id, role_id, resource_addition_request, content_type=None, _request_timeout=None, _request_auth=None, _content_type=None, _headers=None, _host_index=0)¶
Add a Dataset or Domain source to a knowledge base
Attaches one Dataset or Domain source. Requires editor access on the knowledge base and on the dataset or domain. Unstructured knowledge bases allow at most 5 sources and accept optional ChunkingConfiguration (default NONE) and ParsingConfiguration (default DEFAULT). Structured knowledge bases ignore chunking/parsing; the dataset TargetLocation must match the knowledge base DataStoreType. Datasets must be internal (not Hudi or Iceberg).
- Parameters:
id (str) – Unique identifier of the knowledge base to add the source to. (required)
role_id (str) – Amorphic role ID of the requesting user. Must be a role the authenticated user belongs to. (required)
resource_addition_request (ResourceAdditionRequest) – ResourceType (Dataset or Domain) and ResourceKey are required. Description is optional. ChunkingConfiguration and ParsingConfiguration apply only to unstructured knowledge bases. (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:
- Returns:
Returns the result object.
Request and Response Examples¶
HTTP: POST /ai/knowledgebases/{id}/resources
Parameter examples¶
Name |
In |
Example |
|---|---|---|
|
path |
|
|
header |
|
|
header |
|
Request¶
ResourceType (Dataset or Domain) and ResourceKey are required. Description is optional. ChunkingConfiguration and ParsingConfiguration apply only to unstructured knowledge bases.
Unstructured dataset source
{
"ResourceType": "Dataset",
"ResourceKey": "ds-123e4567-e89b-12d3-a456-426614174000",
"Description": "Sales documentation",
"ChunkingConfiguration": {
"ChunkingStrategy": "NONE"
},
"ParsingConfiguration": {
"ParsingStrategy": "DEFAULT"
}
}
Structured dataset source
{
"ResourceType": "Dataset",
"ResourceKey": "ds-123e4567-e89b-12d3-a456-426614174000",
"Description": "Sales fact table"
}
Domain source
{
"ResourceType": "Domain",
"ResourceKey": "sales_domain"
}
Unstructured dataset with fixed-size chunking
{
"ResourceType": "Dataset",
"ResourceKey": "ds-123e4567-e89b-12d3-a456-426614174000",
"Description": "Long-form policy documents",
"ChunkingConfiguration": {
"ChunkingStrategy": "FIXED_SIZE",
"MaxTokens": 300,
"OverlapPercentage": 10
}
}
Unstructured dataset with semantic chunking
{
"ResourceType": "Dataset",
"ResourceKey": "ds-123e4567-e89b-12d3-a456-426614174000",
"Description": "Technical documentation",
"ChunkingConfiguration": {
"ChunkingStrategy": "SEMANTIC",
"MaxTokens": 300,
"BufferSize": 1,
"BreakpointPercentileThreshold": 95
}
}
Success (HTTP 200)¶
Source added. Unstructured responses include SourceId; structured responses include KnowledgebaseId. Message names the attached resource.
Unstructured source added
{
"Message": "Resource Dataset sales_docs added to KnowledgeBase.",
"SourceId": "ABCDEFGHIJDS"
}
Structured source added
{
"Message": "Resource Dataset sales_docs added to KnowledgeBase.",
"KnowledgebaseId": "ABCDEFGHIJ"
}
Errors¶
Documented error codes: IPV-1008, IPV-1002, IPV-1061, GE-1096, GE-1009, AUTH-1001, AUTH-1012, AUTH-1011, GE-1085, DB-1002.
HTTP 400
Input validation or authorization failure. Body is {“Message”: “<CODE> - <text>”}. Codes: IPV-1008 (invalid ResourceType/ResourceKey), IPV-1002 (KB or dataset not found), IPV-1061 (unsupported ResourceType or dataset), GE-1096 (maximum 5 sources), GE-1009 (duplicate source), AUTH-1001 (missing role_id), AUTH-1012 (editor required), 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"
}
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"
}