Skip to main content

@nuclia/core / Exports / KnowledgeBox

Class: KnowledgeBox

Provides access to all the Knowledge Box contents and services in read mode.

For any Knowledge Box operation that requires write access, you need to use WritableKnowledgeBox instead.

Hierarchy

Implements

Table of contents

Constructors

Properties

Accessors

Methods

Constructors

constructor

new KnowledgeBox(nuclia, account, data)

Parameters

NameType
nucliaINuclia
accountstring
dataIKnowledgeBoxCreation | IKnowledgeBoxStandalone

Inherited from

IKnowledgeBox.constructor

Defined in

libs/sdk-core/src/lib/db/kb/kb.ts:125

Properties

accountId

accountId: string

Defined in

libs/sdk-core/src/lib/db/kb/kb.ts:75


allowed_origins

Optional allowed_origins: null | string[]

Implementation of

IKnowledgeBox.allowed_origins

Inherited from

IKnowledgeBox.allowed_origins

Defined in

libs/sdk-core/src/lib/db/kb/kb.models.ts:27


description

Optional description: string

Implementation of

IKnowledgeBox.description

Inherited from

IKnowledgeBox.description

Defined in

libs/sdk-core/src/lib/db/kb/kb.models.ts:25


external_index_provider

Optional external_index_provider: "pinecone"

Implementation of

IKnowledgeBox.external_index_provider

Inherited from

IKnowledgeBox.external_index_provider

Defined in

libs/sdk-core/src/lib/db/kb/kb.models.ts:84


hidden_resources_enabled

Optional hidden_resources_enabled: boolean

Implementation of

IKnowledgeBox.hidden_resources_enabled

Inherited from

IKnowledgeBox.hidden_resources_enabled

Defined in

libs/sdk-core/src/lib/db/kb/kb.models.ts:29


hidden_resources_hide_on_creation

Optional hidden_resources_hide_on_creation: boolean

Implementation of

IKnowledgeBox.hidden_resources_hide_on_creation

Inherited from

IKnowledgeBox.hidden_resources_hide_on_creation

Defined in

libs/sdk-core/src/lib/db/kb/kb.models.ts:30


id

id: string

Implementation of

IKnowledgeBox.id

Inherited from

IKnowledgeBox.id

Defined in

libs/sdk-core/src/lib/db/kb/kb.models.ts:21


nuclia

Protected nuclia: INuclia

Defined in

libs/sdk-core/src/lib/db/kb/kb.ts:76


search_configs

Optional search_configs: Object

Index signature

▪ [key: string]: any

Implementation of

IKnowledgeBox.search_configs

Inherited from

IKnowledgeBox.search_configs

Defined in

libs/sdk-core/src/lib/db/kb/kb.models.ts:28


slug

slug: string

Implementation of

IKnowledgeBox.slug

Inherited from

IKnowledgeBox.slug

Defined in

libs/sdk-core/src/lib/db/kb/kb.models.ts:22


state

Optional state: KBStates

Implementation of

IKnowledgeBox.state

Inherited from

IKnowledgeBox.state

Defined in

libs/sdk-core/src/lib/db/kb/kb.models.ts:24


title

title: string

Implementation of

IKnowledgeBox.title

Inherited from

IKnowledgeBox.title

Defined in

libs/sdk-core/src/lib/db/kb/kb.models.ts:23


zone

zone: string

Implementation of

IKnowledgeBox.zone

Inherited from

IKnowledgeBox.zone

Defined in

libs/sdk-core/src/lib/db/kb/kb.models.ts:26

Accessors

fullpath

get fullpath(): string

The Knowledge Box fullpath on the regional API.

Example: https://europe-1.nuclia.cloud/api/v1/kb/3cce4a71-9cb9-4fda-beee-8a1512616bf0

Returns

string

Inherited from

IKnowledgeBox.fullpath

Defined in

libs/sdk-core/src/lib/db/kb/kb.ts:121


path

get path(): string

The Knowledge Box path on the regional API.

Example: /v1/kb/3cce4a71-9cb9-4fda-beee-8a1512616bf0

Returns

string

Inherited from

IKnowledgeBox.path

Defined in

libs/sdk-core/src/lib/db/kb/kb.ts:112

Methods

ask

ask(query, context?, features?, options?): Observable<IErrorResponse | Answer>

Retrieves a generative answer for the given query.

The generative answer is a text that is generated chunk by chunk by the language model. It is retrieved through a readable HTTP stream, so the chat() method returns an Observable emitting a value each time a new chunk is available. The incomplete attribute of the emitted value indicates if the asnwer is complete or not.

Example:

 nuclia.knowledgeBox
.ask('where does the Little Prince live')
.pipe(filter((answer) => !answer.incomplete))
.subscribe((answer) => {
console.log(answer.text);
});

Parameters

NameType
querystring
context?ContextEntry[]
features?Features[]
options?ChatOptions

Returns

Observable<IErrorResponse | Answer>

Inherited from

IKnowledgeBox.ask

Defined in

libs/sdk-core/src/lib/db/kb/kb.ts:304

ask(query, context?, features?, options?, callback?): Observable<null>

Parameters

NameType
querystring
context?ContextEntry[]
features?Features[]
options?ChatOptions
callback?(answer: IErrorResponse | Answer) => void

Returns

Observable<null>

Inherited from

IKnowledgeBox.ask

Defined in

libs/sdk-core/src/lib/db/kb/kb.ts:310


catalog

catalog(query, options?): Observable<Results | IErrorResponse>

Parameters

NameType
querystring
options?SearchOptions

Returns

Observable<Results | IErrorResponse>

Inherited from

IKnowledgeBox.catalog

Defined in

libs/sdk-core/src/lib/db/kb/kb.ts:602


counters

counters(): Observable<Counters>

Returns totals for each kind of contents stored in the Knowledge Box (resources, fields, paragraphs, vectors)

Returns

Observable<Counters>

Inherited from

IKnowledgeBox.counters

Defined in

libs/sdk-core/src/lib/db/kb/kb.ts:626


createAgenticRAGPipeline

createAgenticRAGPipeline(steps): Pipeline

Parameters

NameType
stepsSteps

Returns

Pipeline

Inherited from

IKnowledgeBox.createAgenticRAGPipeline

Defined in

libs/sdk-core/src/lib/db/kb/kb.ts:282


feedback

feedback(answerId, good, feedback?, text_block_id?): Observable<void>

Parameters

NameTypeDefault value
answerIdstringundefined
goodbooleanundefined
feedbackstring''
text_block_id?stringundefined

Returns

Observable<void>

Inherited from

IKnowledgeBox.feedback

Defined in

libs/sdk-core/src/lib/db/kb/kb.ts:615


find

find(query, features?, options?): Observable<FindResults | IErrorResponse>

Performs a find operation in the Knowledge Box, which is the recommended way to search for results.

Example:

nuclia.knowledgeBox
.find('where does the Little Prince live')
.subscribe((searchResult) => {
console.log('search result', searchResult);
});

Parameters

NameTypeDefault value
querystringundefined
featuresFeatures[][]
options?SearchOptionsundefined

Returns

Observable<FindResults | IErrorResponse>

Inherited from

IKnowledgeBox.find

Defined in

libs/sdk-core/src/lib/db/kb/kb.ts:344


generate

generate(question, context?): Observable<{ answer: string ; cannotAnswer: boolean }>

Performs a question answering operation based on a given context.

Example:

nuclia.knowledgeBox
.generate('Who is Eric from Toronto?', [
'Eric is a taxi driver',
'Eric was born in France',
'Eric lives in Toronto',
]))
.subscribe((answer) => {
console.log('answer', answer);
});

Parameters

NameTypeDefault value
questionstringundefined
contextstring[][]

Returns

Observable<{ answer: string ; cannotAnswer: boolean }>

Inherited from

IKnowledgeBox.generate

Defined in

libs/sdk-core/src/lib/db/kb/kb.ts:444


generateJSON

generateJSON(question, json_schema, context?): Observable<{ answer: object ; success: boolean }>

Performs a question answering operation using a JSON schema.

Example:

nuclia.knowledgeBox
.generateJSON(
'Who is Eric from Toronto?',
{
name: 'info',
parameters: {
properties: {
location: {
title: 'Location',
description: 'The location of the person',
type: 'string',
},
name: {
title: 'Name',
description: 'The name of the person',
type: 'string',
},
},
required: ['name', 'location'],
},
},
[
'Eric is a taxi driver',
'Eric was born in France',
'Eric lives in Toronto',
],
)).subscribe((answer) => {
console.log('location', answer.answer.location);
});

Parameters

NameTypeDefault value
questionstringundefined
json_schemaobjectundefined
contextstring[][]

Returns

Observable<{ answer: object ; success: boolean }>

Inherited from

IKnowledgeBox.generateJSON

Defined in

libs/sdk-core/src/lib/db/kb/kb.ts:504


generateRandomQuestionAboutResource

generateRandomQuestionAboutResource(resource): Observable<string>

Generates a random question about the given resource. It picks an entities relation from the extracted metadata and generates a question about it. It returns an empty string if no question can be generated. Example:

 nuclia.knowledgeBox
.getResource('09a94719a6444c5a9689394f6ed9baf6', [ResourceProperties.EXTRACTED], [ExtractedDataTypes.METADATA])
.pipe(
switchMap((resource) => knowledgeBox.generateRandomQuestionAboutResource(resource)),
)
.subscribe((question) => {
console.log('question', question);
});

Parameters

NameType
resourceResource

Returns

Observable<string>

Inherited from

IKnowledgeBox.generateRandomQuestionAboutResource

Defined in

libs/sdk-core/src/lib/db/kb/kb.ts:576


getConfiguration

getConfiguration(): Observable<{ [id: string]: any; }>

Returns

Observable<{ [id: string]: any; }>

Inherited from

IKnowledgeBox.getConfiguration

Defined in

libs/sdk-core/src/lib/db/kb/kb.ts:688


getEntities

getEntities(): Observable<Entities>

Returns all the NER families defined in the Knowledge Box.

Returns

Observable<Entities>

Inherited from

IKnowledgeBox.getEntities

Defined in

libs/sdk-core/src/lib/db/kb/kb.ts:144


getEntitiesGroup

getEntitiesGroup(groupId): Observable<EntitiesGroup>

Returns the NER family with the given id.

Parameters

NameType
groupIdstring

Returns

Observable<EntitiesGroup>

Inherited from

IKnowledgeBox.getEntitiesGroup

Defined in

libs/sdk-core/src/lib/db/kb/kb.ts:149


getFullResource

getFullResource(uuid): Observable<Resource>

Retrieves a resource from the Knowledge Box with all its attached metadata and content.

Parameters

NameType
uuidstring

Returns

Observable<Resource>

Inherited from

IKnowledgeBox.getFullResource

Defined in

libs/sdk-core/src/lib/db/kb/kb.ts:194


getFullResourceBySlug

getFullResourceBySlug(slug): Observable<Resource>

Parameters

NameType
slugstring

Returns

Observable<Resource>

Inherited from

IKnowledgeBox.getFullResourceBySlug

Defined in

libs/sdk-core/src/lib/db/kb/kb.ts:226


getInvites

getInvites(): Observable<KbInvite[]>

Returns

Observable<KbInvite[]>

Defined in

libs/sdk-core/src/lib/db/kb/kb.ts:707


getLabels

getLabels(): Observable<LabelSets>

Returns all the labels defined in the Knowledge Box.

Returns

Observable<LabelSets>

Inherited from

IKnowledgeBox.getLabels

Defined in

libs/sdk-core/src/lib/db/kb/kb.ts:158


getLearningSchema

getLearningSchema(): Observable<LearningConfigurations>

Returns

Observable<LearningConfigurations>

Inherited from

IKnowledgeBox.getLearningSchema

Defined in

libs/sdk-core/src/lib/db/kb/kb.ts:692


getResource

getResource(uuid, show?, extracted?): Observable<Resource>

Retrieves a resource from the Knowledge Box.

  • show defines which properties are returned. Default retrieves only the basic metadata.
  • extracted defines which extracted data are returned. It is ignored if ResourceProperties.EXTRACTED is not in the returned properties. Default is an empty array.

Example:

nuclia.db
.getKnowledgeBox()
.pipe(switchMap((knowledgeBox) => knowledgeBox.getResource('09a94719a6444c5a9689394f6ed9baf6')))
.subscribe((resource) => {
console.log('resource', resource);
});

Parameters

NameTypeDefault value
uuidstringundefined
showResourceProperties[]undefined
extractedExtractedDataTypes[][]

Returns

Observable<Resource>

Inherited from

IKnowledgeBox.getResource

Defined in

libs/sdk-core/src/lib/db/kb/kb.ts:183


getResourceBySlug

getResourceBySlug(slug, show?, extracted?): Observable<Resource>

Parameters

NameTypeDefault value
slugstringundefined
showResourceProperties[]undefined
extractedExtractedDataTypes[][]

Returns

Observable<Resource>

Inherited from

IKnowledgeBox.getResourceBySlug

Defined in

libs/sdk-core/src/lib/db/kb/kb.ts:218


getResourceFromData

getResourceFromData(data): Resource

Parameters

NameType
dataIResource

Returns

Resource

Defined in

libs/sdk-core/src/lib/db/kb/kb.ts:278


getSynonyms

getSynonyms(): Observable<Synonyms>

Returns

Observable<Synonyms>

Inherited from

IKnowledgeBox.getSynonyms

Defined in

libs/sdk-core/src/lib/db/kb/kb.ts:153


getTempToken

getTempToken(): Observable<string>

Returns an ephemeral token. Requires account id and zone to be set in the Nuclia options (except when working with a local NucliaDB instance).

This is useful when displaying a clickable link to a file in a private Knowledge Box (the token will authorize the request even though there are no authentication headers).

Example:

const downloadLink = `${nuclia.rest.getFullpath(filePath)}?eph-token=${nuclia.knowledgeBox.getTempToken()}`;

Returns

Observable<string>

Inherited from

IKnowledgeBox.getTempToken

Defined in

libs/sdk-core/src/lib/db/kb/kb.ts:658


getUsers

getUsers(): Observable<FullKbUser[]>

Returns

Observable<FullKbUser[]>

Inherited from

IKnowledgeBox.getUsers

Defined in

libs/sdk-core/src/lib/db/kb/kb.ts:698


listResources

listResources(page?, size?): Observable<ResourceList>

Lists all the resources stored in the Knowledge Box.

Parameters

NameType
page?number
size?number

Returns

Observable<ResourceList>

Inherited from

IKnowledgeBox.listResources

Defined in

libs/sdk-core/src/lib/db/kb/kb.ts:631


listenToAllNotifications

listenToAllNotifications(): Observable<NotificationMessage[]>

Start listening to all the notifications sent by the Knowledge Box.

Returns

Observable<NotificationMessage[]>

Inherited from

IKnowledgeBox.listenToAllNotifications

Defined in

libs/sdk-core/src/lib/db/kb/kb.ts:719


listenToProcessingNotifications

listenToProcessingNotifications(): Observable<ResourceBaseNotification[]>

Start listening to the Knowledge Box notifications, and returns the list of notifications for resources which have processing completed (either successfully or not). Notifications are sent anytime processing is completed, and processing is done anytime the resource is created or modified (like when a summary is added to the resource for example).

Returns

Observable<ResourceBaseNotification[]>

Inherited from

IKnowledgeBox.listenToProcessingNotifications

Defined in

libs/sdk-core/src/lib/db/kb/kb.ts:798


listenToResourceOperationNotifications

listenToResourceOperationNotifications(): Observable<ResourceOperationNotification[]>

Start listening to the Knowledge Box notifications, and returns the list of notifications corresponding to the different operations affecting the resources: created, modified, deleted. The notification contains the resource id, title, a timestamp and a flag indicating if the operation was successful or not.

Returns

Observable<ResourceOperationNotification[]>

Inherited from

IKnowledgeBox.listenToResourceOperationNotifications

Defined in

libs/sdk-core/src/lib/db/kb/kb.ts:743


processingStatus

processingStatus(cursor?, scheduled?, limit?): Observable<{ cursor: string ; results: ProcessingStatus[] }>

Parameters

NameType
cursor?string
scheduled?boolean
limit?number

Returns

Observable<{ cursor: string ; results: ProcessingStatus[] }>

Inherited from

IKnowledgeBox.processingStatus

Defined in

libs/sdk-core/src/lib/db/kb/kb.ts:840


rephrase

rephrase(question, user_context?, rephrase_prompt?): Observable<string>

Performs a question rephrasing operation. It returns a rephrased question that can be used as input for the generate() method. Example:

nuclia.knowledgeBox
.rephrase('Eric lives Toronto')
.subscribe((rephrased) => {
console.log('rephrased', rephrased); // Where does Eric live?
});

Parameters

NameType
questionstring
user_context?string[]
rephrase_prompt?string

Returns

Observable<string>

Inherited from

IKnowledgeBox.rephrase

Defined in

libs/sdk-core/src/lib/db/kb/kb.ts:554


search(query, features?, options?): Observable<Results | IErrorResponse>

Performs a search operation in the knowledge box.

It is similar to find() but the results are not nested.

Example:

nuclia.knowledgeBox
.search('where does the Little Prince live', [Search.Features.KEYWORD])
.subscribe((searchResult) => {
console.log('search result', searchResult);
});

Parameters

NameTypeDefault value
querystringundefined
featuresFeatures[][]
options?SearchOptionsundefined

Returns

Observable<Results | IErrorResponse>

Inherited from

IKnowledgeBox.search

Defined in

libs/sdk-core/src/lib/db/kb/kb.ts:366


stopListeningToNotifications

stopListeningToNotifications(): void

Stop listening the notifications sent by the Knowledge Box.

Returns

void

Inherited from

IKnowledgeBox.stopListeningToNotifications

Defined in

libs/sdk-core/src/lib/db/kb/kb.ts:730


suggest

suggest(query, inTitleOnly?, features?): Observable<Suggestions | IErrorResponse>

Suggests paragraphs based on the given query.

Parameters

NameTypeDefault value
querystringundefined
inTitleOnlybooleanfalse
featuresSuggestionFeatures[][]

Returns

Observable<Suggestions | IErrorResponse>

Inherited from

IKnowledgeBox.suggest

Defined in

libs/sdk-core/src/lib/db/kb/kb.ts:607


summarize

summarize(ressourceIds, user_prompt?, generative_model?): Observable<string>

Summarize resources.

It reads the resources text content and return a global summary about them and one summery per resource.

The optional user_prompt parameter allows you to specify a text that will be used to generate the summary, and must use the {text} placeholder to indicate where the resource text should be inserted (example: 'Make a one-line summary of the following text: {text}').

Example:

nuclia.knowledgeBox
.summarize(['09a94719a6444c5a9689394f6ed9baf6'])
.subscribe((summary) => {
console.log('Summary', summary);
});

Parameters

NameType
ressourceIdsstring[]
user_prompt?string
generative_model?string

Returns

Observable<string>

Inherited from

IKnowledgeBox.summarize

Defined in

libs/sdk-core/src/lib/db/kb/kb.ts:392


tokens

tokens(text): Observable<SentenceToken[]>

Performs a tokenization of the given text.

Example:

nuclia.knowledgeBox
.tokens('Does James Joyce live in Dublin?')
.subscribe((tokens) => {
console.log('tokens', tokens);
});

Parameters

NameType
textstring

Returns

Observable<SentenceToken[]>

Inherited from

IKnowledgeBox.tokens

Defined in

libs/sdk-core/src/lib/db/kb/kb.ts:422