Skip to content

Create a Knowledge Base

client.KnowledgeBases.New(ctx, body) (*KnowledgeBaseNewResponse, error)
post/v2/gen-ai/knowledge_bases

To create a knowledge base, send a POST request to /v2/gen-ai/knowledge_bases.

ParametersExpand Collapse
body KnowledgeBaseNewParams
DatabaseID param.Field[string]optional

Identifier of the DigitalOcean OpenSearch database this knowledge base will use, optional. If not provided, we create a new database for the knowledge base in the same region as the knowledge base.

Datasources param.Field[[]KnowledgeBaseNewParamsDatasource]optional

The data sources to use for this knowledge base. See Organize Data Sources for more information on data sources best practices.

AwsDataSource AwsDataSourceoptional

AWS S3 Data Source

BucketName stringoptional

Spaces bucket name

ItemPath stringoptional
KeyID stringoptional

The AWS Key ID

Region stringoptional

Region of bucket

SecretKey stringoptional

The AWS Secret Key

BucketName stringoptional

Deprecated, moved to data_source_details

BucketRegion stringoptional

Deprecated, moved to data_source_details

ChunkingAlgorithm KnowledgeBaseNewParamsDatasourcesChunkingAlgorithmoptional

The chunking algorithm to use for processing data sources.

Note: This feature requires enabling the knowledgebase enhancements feature preview flag.

Accepts one of the following:
const KnowledgeBaseNewParamsDatasourcesChunkingAlgorithmChunkingAlgorithmUnknown KnowledgeBaseNewParamsDatasourcesChunkingAlgorithm = "CHUNKING_ALGORITHM_UNKNOWN"
const KnowledgeBaseNewParamsDatasourcesChunkingAlgorithmChunkingAlgorithmSectionBased KnowledgeBaseNewParamsDatasourcesChunkingAlgorithm = "CHUNKING_ALGORITHM_SECTION_BASED"
const KnowledgeBaseNewParamsDatasourcesChunkingAlgorithmChunkingAlgorithmHierarchical KnowledgeBaseNewParamsDatasourcesChunkingAlgorithm = "CHUNKING_ALGORITHM_HIERARCHICAL"
const KnowledgeBaseNewParamsDatasourcesChunkingAlgorithmChunkingAlgorithmSemantic KnowledgeBaseNewParamsDatasourcesChunkingAlgorithm = "CHUNKING_ALGORITHM_SEMANTIC"
const KnowledgeBaseNewParamsDatasourcesChunkingAlgorithmChunkingAlgorithmFixedLength KnowledgeBaseNewParamsDatasourcesChunkingAlgorithm = "CHUNKING_ALGORITHM_FIXED_LENGTH"
ChunkingOptions KnowledgeBaseNewParamsDatasourcesChunkingOptionsoptional

Configuration options for the chunking algorithm.

Note: This feature requires enabling the knowledgebase enhancements feature preview flag.

ChildChunkSize int64optional

Hierarchical options

formatint64
MaxChunkSize int64optional

Section_Based and Fixed_Length options

formatint64
ParentChunkSize int64optional

Hierarchical options

formatint64
SemanticThreshold float64optional

Semantic options

formatfloat
DropboxDataSource KnowledgeBaseNewParamsDatasourcesDropboxDataSourceoptional

Dropbox Data Source

Folder stringoptional
RefreshToken stringoptional

Refresh token. you can obrain a refresh token by following the oauth2 flow. see /v2/gen-ai/oauth2/dropbox/tokens for reference.

FileUploadDataSource APIFileUploadDataSourceoptional

File to upload as data source for knowledge base.

OriginalFileName stringoptional

The original file name

SizeInBytes stringoptional

The size of the file in bytes

formatuint64
StoredObjectKey stringoptional

The object key the file was stored as

GoogleDriveDataSource KnowledgeBaseNewParamsDatasourcesGoogleDriveDataSourceoptional

Google Drive Data Source

FolderID stringoptional
RefreshToken stringoptional

Refresh token. you can obrain a refresh token by following the oauth2 flow. see /v2/gen-ai/oauth2/google/tokens for reference.

ItemPath stringoptional
SpacesDataSource APISpacesDataSourceoptional

Spaces Bucket Data Source

BucketName stringoptional

Spaces bucket name

ItemPath stringoptional
Region stringoptional

Region of bucket

WebCrawlerDataSource APIWebCrawlerDataSourceoptional

WebCrawlerDataSource

BaseURL stringoptional

The base url to crawl.

CrawlingOption APIWebCrawlerDataSourceCrawlingOptionoptional

Options for specifying how URLs found on pages should be handled.

  • UNKNOWN: Default unknown value
  • SCOPED: Only include the base URL.
  • PATH: Crawl the base URL and linked pages within the URL path.
  • DOMAIN: Crawl the base URL and linked pages within the same domain.
  • SUBDOMAINS: Crawl the base URL and linked pages for any subdomain.
  • SITEMAP: Crawl URLs discovered in the sitemap.
Accepts one of the following:
const APIWebCrawlerDataSourceCrawlingOptionUnknown APIWebCrawlerDataSourceCrawlingOption = "UNKNOWN"
const APIWebCrawlerDataSourceCrawlingOptionScoped APIWebCrawlerDataSourceCrawlingOption = "SCOPED"
const APIWebCrawlerDataSourceCrawlingOptionPath APIWebCrawlerDataSourceCrawlingOption = "PATH"
const APIWebCrawlerDataSourceCrawlingOptionDomain APIWebCrawlerDataSourceCrawlingOption = "DOMAIN"
const APIWebCrawlerDataSourceCrawlingOptionSubdomains APIWebCrawlerDataSourceCrawlingOption = "SUBDOMAINS"
const APIWebCrawlerDataSourceCrawlingOptionSitemap APIWebCrawlerDataSourceCrawlingOption = "SITEMAP"
EmbedMedia booloptional

Whether to ingest and index media (images, etc.) on web pages.

ExcludeTags []stringoptional

Declaring which tags to exclude in web pages while webcrawling

EmbeddingModelUuid param.Field[string]optional

Identifier for the embedding model.

Name param.Field[string]optional

Name of the knowledge base.

ProjectID param.Field[string]optional

Identifier of the DigitalOcean project this knowledge base will belong to.

Region param.Field[string]optional

The datacenter region to deploy the knowledge base in.

Tags param.Field[[]string]optional

Tags to organize your knowledge base.

VpcUuid param.Field[string]optional

The VPC to deploy the knowledge base database in

ReturnsExpand Collapse
type KnowledgeBaseNewResponse struct{…}

Information about a newly created knowledge base

KnowledgeBase APIKnowledgeBaseoptional

Knowledgebase Description

AddedToAgentAt Timeoptional

Time when the knowledge base was added to the agent

formatdate-time
CreatedAt Timeoptional

Creation date / time

formatdate-time
DatabaseID stringoptional
EmbeddingModelUuid stringoptional
IsPublic booloptional

Whether the knowledge base is public or not

LastIndexingJob APIIndexingJoboptional

IndexingJob description

CompletedDatasources int64optional

Number of datasources indexed completed

formatint64
CreatedAt Timeoptional

Creation date / time

formatdate-time
DataSourceJobs []APIIndexedDataSourceoptional

Details on Data Sources included in the Indexing Job

CompletedAt Timeoptional

Timestamp when data source completed indexing

formatdate-time
DataSourceUuid stringoptional

Uuid of the indexed data source

ErrorDetails stringoptional

A detailed error description

ErrorMsg stringoptional

A string code provinding a hint which part of the system experienced an error

FailedItemCount stringoptional

Total count of files that have failed

formatuint64
IndexedFileCount stringoptional

Total count of files that have been indexed

formatuint64
IndexedItemCount stringoptional

Total count of files that have been indexed

formatuint64
RemovedItemCount stringoptional

Total count of files that have been removed

formatuint64
SkippedItemCount stringoptional

Total count of files that have been skipped

formatuint64
StartedAt Timeoptional

Timestamp when data source started indexing

formatdate-time
Status APIIndexedDataSourceStatusoptional
Accepts one of the following:
const APIIndexedDataSourceStatusDataSourceStatusUnknown APIIndexedDataSourceStatus = "DATA_SOURCE_STATUS_UNKNOWN"
const APIIndexedDataSourceStatusDataSourceStatusInProgress APIIndexedDataSourceStatus = "DATA_SOURCE_STATUS_IN_PROGRESS"
const APIIndexedDataSourceStatusDataSourceStatusUpdated APIIndexedDataSourceStatus = "DATA_SOURCE_STATUS_UPDATED"
const APIIndexedDataSourceStatusDataSourceStatusPartiallyUpdated APIIndexedDataSourceStatus = "DATA_SOURCE_STATUS_PARTIALLY_UPDATED"
const APIIndexedDataSourceStatusDataSourceStatusNotUpdated APIIndexedDataSourceStatus = "DATA_SOURCE_STATUS_NOT_UPDATED"
const APIIndexedDataSourceStatusDataSourceStatusFailed APIIndexedDataSourceStatus = "DATA_SOURCE_STATUS_FAILED"
const APIIndexedDataSourceStatusDataSourceStatusCancelled APIIndexedDataSourceStatus = "DATA_SOURCE_STATUS_CANCELLED"
TotalBytes stringoptional

Total size of files in data source in bytes

formatuint64
TotalBytesIndexed stringoptional

Total size of files in data source in bytes that have been indexed

formatuint64
TotalFileCount stringoptional

Total file count in the data source

formatuint64
DataSourceUuids []stringoptional
FinishedAt Timeoptional
formatdate-time
IsReportAvailable booloptional

Boolean value to determine if the indexing job details are available

KnowledgeBaseUuid stringoptional

Knowledge base id

Phase APIIndexingJobPhaseoptional
Accepts one of the following:
const APIIndexingJobPhaseBatchJobPhaseUnknown APIIndexingJobPhase = "BATCH_JOB_PHASE_UNKNOWN"
const APIIndexingJobPhaseBatchJobPhasePending APIIndexingJobPhase = "BATCH_JOB_PHASE_PENDING"
const APIIndexingJobPhaseBatchJobPhaseRunning APIIndexingJobPhase = "BATCH_JOB_PHASE_RUNNING"
const APIIndexingJobPhaseBatchJobPhaseSucceeded APIIndexingJobPhase = "BATCH_JOB_PHASE_SUCCEEDED"
const APIIndexingJobPhaseBatchJobPhaseFailed APIIndexingJobPhase = "BATCH_JOB_PHASE_FAILED"
const APIIndexingJobPhaseBatchJobPhaseError APIIndexingJobPhase = "BATCH_JOB_PHASE_ERROR"
const APIIndexingJobPhaseBatchJobPhaseCancelled APIIndexingJobPhase = "BATCH_JOB_PHASE_CANCELLED"
StartedAt Timeoptional
formatdate-time
Status APIIndexingJobStatusoptional
Accepts one of the following:
const APIIndexingJobStatusIndexJobStatusUnknown APIIndexingJobStatus = "INDEX_JOB_STATUS_UNKNOWN"
const APIIndexingJobStatusIndexJobStatusPartial APIIndexingJobStatus = "INDEX_JOB_STATUS_PARTIAL"
const APIIndexingJobStatusIndexJobStatusInProgress APIIndexingJobStatus = "INDEX_JOB_STATUS_IN_PROGRESS"
const APIIndexingJobStatusIndexJobStatusCompleted APIIndexingJobStatus = "INDEX_JOB_STATUS_COMPLETED"
const APIIndexingJobStatusIndexJobStatusFailed APIIndexingJobStatus = "INDEX_JOB_STATUS_FAILED"
const APIIndexingJobStatusIndexJobStatusNoChanges APIIndexingJobStatus = "INDEX_JOB_STATUS_NO_CHANGES"
const APIIndexingJobStatusIndexJobStatusPending APIIndexingJobStatus = "INDEX_JOB_STATUS_PENDING"
const APIIndexingJobStatusIndexJobStatusCancelled APIIndexingJobStatus = "INDEX_JOB_STATUS_CANCELLED"
Tokens int64optional

Number of tokens [This field is deprecated]

formatint64
TotalDatasources int64optional

Number of datasources being indexed

formatint64
TotalTokens stringoptional

Total Tokens Consumed By the Indexing Job

formatuint64
UpdatedAt Timeoptional

Last modified

formatdate-time
Uuid stringoptional

Unique id

Name stringoptional

Name of knowledge base

ProjectID stringoptional
Region stringoptional

Region code

Tags []stringoptional

Tags to organize related resources

UpdatedAt Timeoptional

Last modified

formatdate-time
UserID stringoptional

Id of user that created the knowledge base

formatint64
Uuid stringoptional

Unique id for knowledge base

Create a Knowledge Base
package main

import (
  "context"
  "fmt"

  "github.com/stainless-sdks/-go"
  "github.com/stainless-sdks/-go/option"
)

func main() {
  client := gradient.NewClient(
    option.WithAccessToken("My Access Token"),
  )
  knowledgeBase, err := client.KnowledgeBases.New(context.TODO(), gradient.KnowledgeBaseNewParams{

  })
  if err != nil {
    panic(err.Error())
  }
  fmt.Printf("%+v\n", knowledgeBase.KnowledgeBase)
}
{
  "knowledge_base": {
    "added_to_agent_at": "2023-01-01T00:00:00Z",
    "created_at": "2023-01-01T00:00:00Z",
    "database_id": "123e4567-e89b-12d3-a456-426614174000",
    "embedding_model_uuid": "123e4567-e89b-12d3-a456-426614174000",
    "is_public": true,
    "last_indexing_job": {
      "completed_datasources": 123,
      "created_at": "2023-01-01T00:00:00Z",
      "data_source_jobs": [
        {
          "completed_at": "2023-01-01T00:00:00Z",
          "data_source_uuid": "123e4567-e89b-12d3-a456-426614174000",
          "error_details": "example string",
          "error_msg": "example string",
          "failed_item_count": "12345",
          "indexed_file_count": "12345",
          "indexed_item_count": "12345",
          "removed_item_count": "12345",
          "skipped_item_count": "12345",
          "started_at": "2023-01-01T00:00:00Z",
          "status": "DATA_SOURCE_STATUS_UNKNOWN",
          "total_bytes": "12345",
          "total_bytes_indexed": "12345",
          "total_file_count": "12345"
        }
      ],
      "data_source_uuids": [
        "example string"
      ],
      "finished_at": "2023-01-01T00:00:00Z",
      "is_report_available": true,
      "knowledge_base_uuid": "123e4567-e89b-12d3-a456-426614174000",
      "phase": "BATCH_JOB_PHASE_UNKNOWN",
      "started_at": "2023-01-01T00:00:00Z",
      "status": "INDEX_JOB_STATUS_UNKNOWN",
      "tokens": 123,
      "total_datasources": 123,
      "total_tokens": "12345",
      "updated_at": "2023-01-01T00:00:00Z",
      "uuid": "123e4567-e89b-12d3-a456-426614174000"
    },
    "name": "example name",
    "project_id": "123e4567-e89b-12d3-a456-426614174000",
    "region": "example string",
    "tags": [
      "example string"
    ],
    "updated_at": "2023-01-01T00:00:00Z",
    "user_id": "user_id",
    "uuid": "123e4567-e89b-12d3-a456-426614174000"
  }
}
Returns Examples
{
  "knowledge_base": {
    "added_to_agent_at": "2023-01-01T00:00:00Z",
    "created_at": "2023-01-01T00:00:00Z",
    "database_id": "123e4567-e89b-12d3-a456-426614174000",
    "embedding_model_uuid": "123e4567-e89b-12d3-a456-426614174000",
    "is_public": true,
    "last_indexing_job": {
      "completed_datasources": 123,
      "created_at": "2023-01-01T00:00:00Z",
      "data_source_jobs": [
        {
          "completed_at": "2023-01-01T00:00:00Z",
          "data_source_uuid": "123e4567-e89b-12d3-a456-426614174000",
          "error_details": "example string",
          "error_msg": "example string",
          "failed_item_count": "12345",
          "indexed_file_count": "12345",
          "indexed_item_count": "12345",
          "removed_item_count": "12345",
          "skipped_item_count": "12345",
          "started_at": "2023-01-01T00:00:00Z",
          "status": "DATA_SOURCE_STATUS_UNKNOWN",
          "total_bytes": "12345",
          "total_bytes_indexed": "12345",
          "total_file_count": "12345"
        }
      ],
      "data_source_uuids": [
        "example string"
      ],
      "finished_at": "2023-01-01T00:00:00Z",
      "is_report_available": true,
      "knowledge_base_uuid": "123e4567-e89b-12d3-a456-426614174000",
      "phase": "BATCH_JOB_PHASE_UNKNOWN",
      "started_at": "2023-01-01T00:00:00Z",
      "status": "INDEX_JOB_STATUS_UNKNOWN",
      "tokens": 123,
      "total_datasources": 123,
      "total_tokens": "12345",
      "updated_at": "2023-01-01T00:00:00Z",
      "uuid": "123e4567-e89b-12d3-a456-426614174000"
    },
    "name": "example name",
    "project_id": "123e4567-e89b-12d3-a456-426614174000",
    "region": "example string",
    "tags": [
      "example string"
    ],
    "updated_at": "2023-01-01T00:00:00Z",
    "user_id": "user_id",
    "uuid": "123e4567-e89b-12d3-a456-426614174000"
  }
}