KnowledgeBox
@nuclia/core • Docs
@nuclia/core / 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.
Extends
Extended by
Implements
Constructors
new KnowledgeBox()
new KnowledgeBox(
nuclia
,account
,data
):KnowledgeBox
Parameters
• nuclia: INuclia
• account: string
• data: IKnowledgeBoxBase
| IKnowledgeBoxStandalone
Returns
Inherited from
IKnowledgeBox.constructor
Defined in
libs/sdk-core/src/lib/db/kb/kb.ts:144
Properties
accountId
accountId:
string
Defined in
libs/sdk-core/src/lib/db/kb/kb.ts:94
allowed_origins?
optional
allowed_origins:null
|string
[]
Implementation of
Inherited from
Defined in
libs/sdk-core/src/lib/db/kb/kb.models.ts:27
description?
optional
description:string
Implementation of
Inherited from
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
Inherited from
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:95
search_configs?
optional
search_configs:object
Index Signature
[key
: string
]: any
Implementation of
Inherited from
Defined in
libs/sdk-core/src/lib/db/kb/kb.models.ts:28
slug
slug:
string
Implementation of
Inherited from
Defined in
libs/sdk-core/src/lib/db/kb/kb.models.ts:22
state?
optional
state:KBStates
Implementation of
Inherited from
Defined in
libs/sdk-core/src/lib/db/kb/kb.models.ts:24
title
title:
string
Implementation of
Inherited from
Defined in
libs/sdk-core/src/lib/db/kb/kb.models.ts:23
zone
zone:
string
Implementation of
Inherited from
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
Implementation of
Inherited from
Defined in
libs/sdk-core/src/lib/db/kb/kb.ts:140
path
get
path():string
The Knowledge Box path on the regional API.
Example: /v1/kb/3cce4a71-9cb9-4fda-beee-8a1512616bf0
Returns
string
Implementation of
Inherited from
Defined in
libs/sdk-core/src/lib/db/kb/kb.ts:131
Methods
ask()
ask(query, context, features, options)
ask(
query
,context
?,features
?,options
?):Observable
<Answer
|IErrorResponse
>
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
• query: string
• context?: ContextEntry
[]
• features?: Features
[]
• options?: ChatOptions
Returns
Observable
<Answer
| IErrorResponse
>
Inherited from
Defined in
libs/sdk-core/src/lib/db/kb/kb.ts:354
ask(query, context, features, options, callback)
ask(
query
,context
?,features
?,options
?,callback
?):Observable
<null
>
Parameters
• query: string
• context?: ContextEntry
[]
• features?: Features
[]
• options?: ChatOptions
• callback?
Returns
Observable
<null
>
Inherited from
Defined in
libs/sdk-core/src/lib/db/kb/kb.ts:360
catalog()
catalog(
query
,options
?):Observable
<Results
|IErrorResponse
>
Parameters
• query: string
• options?: CatalogOptions
Returns
Observable
<Results
| IErrorResponse
>
Inherited from
Defined in
libs/sdk-core/src/lib/db/kb/kb.ts:632
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
Defined in
libs/sdk-core/src/lib/db/kb/kb.ts:656
createAgenticRAGPipeline()
createAgenticRAGPipeline(
steps
):Pipeline
Parameters
• steps: Steps
Returns
Inherited from
IKnowledgeBox
.createAgenticRAGPipeline
Defined in
libs/sdk-core/src/lib/db/kb/kb.ts:332
feedback()
feedback(
answerId
,good
,feedback
,text_block_id
?):Observable
<void
>
Parameters
• answerId: string
• good: boolean
• feedback: string
= ''
• text_block_id?: string
Returns
Observable
<void
>
Inherited from
Defined in
libs/sdk-core/src/lib/db/kb/kb.ts:645
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
• query: string
• features: Features
[] = []
• options?: SearchOptions
Returns
Observable
<FindResults
| IErrorResponse
>
Inherited from
Defined in
libs/sdk-core/src/lib/db/kb/kb.ts:394
generate()
generate(
question
,context
):Observable
<object
>
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
• question: string
• context: string
[] = []
Returns
Observable
<object
>
answer
answer:
string
cannotAnswer
cannotAnswer:
boolean
Inherited from
Defined in
libs/sdk-core/src/lib/db/kb/kb.ts:516
generateJSON()
generateJSON(
question
,json_schema
,context
):Observable
<object
>
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
• question: string
• json_schema: object
• context: string
[] = []
Returns
Observable
<object
>
answer
answer:
object
success
success:
boolean
Inherited from
Defined in
libs/sdk-core/src/lib/db/kb/kb.ts:560
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
• resource: Resource
Returns
Observable
<string
>
Inherited from
IKnowledgeBox
.generateRandomQuestionAboutResource
Defined in
libs/sdk-core/src/lib/db/kb/kb.ts:606
getConfiguration()
getConfiguration():
Observable
<object
>
Returns
Observable
<object
>
Inherited from
IKnowledgeBox
.getConfiguration
Defined in
libs/sdk-core/src/lib/db/kb/kb.ts:723
getEntities()
getEntities():
Observable
<Entities
>
Returns all the NER families defined in the Knowledge Box.
Returns
Observable
<Entities
>
Inherited from
Defined in
libs/sdk-core/src/lib/db/kb/kb.ts:163
getEntitiesGroup()
getEntitiesGroup(
groupId
):Observable
<EntitiesGroup
>
Returns the NER family with the given id.
Parameters
• groupId: string
Returns
Observable
<EntitiesGroup
>
Inherited from
IKnowledgeBox
.getEntitiesGroup
Defined in
libs/sdk-core/src/lib/db/kb/kb.ts:168
getExtractStrategies()
getExtractStrategies():
Observable
<ExtractStrategies
>
Returns
Observable
<ExtractStrategies
>
Inherited from
IKnowledgeBox
.getExtractStrategies
Defined in
libs/sdk-core/src/lib/db/kb/kb.ts:893
getFacets()
getFacets(
facets
):Observable
<FacetsResult
>
Get the total amount of matches in the Knowledge Box for specific criteria (facets) passed in argument
Parameters
• facets: string
[]
List of facets to request
Returns
Observable
<FacetsResult
>
An observable containing an object where each key is a string and maps to an object containing values and their corresponding counts.
Inherited from
Defined in
libs/sdk-core/src/lib/db/kb/kb.ts:189
getFullResource()
getFullResource(
uuid
):Observable
<Resource
>
Retrieves a resource from the Knowledge Box with all its attached metadata and content.
Parameters
• uuid: string
Returns
Observable
<Resource
>
Inherited from
Defined in
libs/sdk-core/src/lib/db/kb/kb.ts:244
getFullResourceBySlug()
getFullResourceBySlug(
slug
):Observable
<Resource
>
Parameters
• slug: string
Returns
Observable
<Resource
>
Inherited from
IKnowledgeBox
.getFullResourceBySlug
Defined in
libs/sdk-core/src/lib/db/kb/kb.ts:276
getInvites()
getInvites():
Observable
<KbInvite
[]>
Returns
Observable
<KbInvite
[]>
Defined in
libs/sdk-core/src/lib/db/kb/kb.ts:742
getLabels()
getLabels():
Observable
<LabelSets
>
Returns all the labels defined in the Knowledge Box.
Returns
Observable
<LabelSets
>
Inherited from
Defined in
libs/sdk-core/src/lib/db/kb/kb.ts:177
getLearningSchema()
getLearningSchema():
Observable
<LearningConfigurations
>
Returns
Observable
<LearningConfigurations
>
Inherited from
IKnowledgeBox
.getLearningSchema
Defined in
libs/sdk-core/src/lib/db/kb/kb.ts:727
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 ifResourceProperties.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
• uuid: string
• show: ResourceProperties
[] = ...
• extracted: ExtractedDataTypes
[] = []
Returns
Observable
<Resource
>
Inherited from
Defined in
libs/sdk-core/src/lib/db/kb/kb.ts:233
getResourceBySlug()
getResourceBySlug(
slug
,show
,extracted
):Observable
<Resource
>
Parameters
• slug: string
• show: ResourceProperties
[] = ...
• extracted: ExtractedDataTypes
[] = []
Returns
Observable
<Resource
>
Inherited from
IKnowledgeBox
.getResourceBySlug
Defined in
libs/sdk-core/src/lib/db/kb/kb.ts:268
getResourceFromData()
getResourceFromData(
data
):Resource
Parameters
• data: IResource
Returns
Defined in
libs/sdk-core/src/lib/db/kb/kb.ts:328
getSearchConfig()
getSearchConfig(
id
):Observable
<SearchConfig
>
Parameters
• id: string
Returns
Observable
<SearchConfig
>
Inherited from
Defined in
libs/sdk-core/src/lib/db/kb/kb.ts:901
getSearchConfigs()
getSearchConfigs():
Observable
<SearchConfigs
>
Returns
Observable
<SearchConfigs
>
Inherited from
IKnowledgeBox
.getSearchConfigs
Defined in
libs/sdk-core/src/lib/db/kb/kb.ts:905
getSplitStrategies()
getSplitStrategies():
Observable
<SplitStrategies
>
Returns
Observable
<SplitStrategies
>
Inherited from
IKnowledgeBox
.getSplitStrategies
Defined in
libs/sdk-core/src/lib/db/kb/kb.ts:897
getSynonyms()
getSynonyms():
Observable
<Synonyms
>
Returns
Observable
<Synonyms
>
Inherited from
Defined in
libs/sdk-core/src/lib/db/kb/kb.ts:172
getTempToken()
getTempToken(
payload
?,ignoreExpiration
?):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()}`;
Parameters
• payload?: any
Optional payload to provide extra data for the token generation
• ignoreExpiration?: boolean
= false
Optional By default, a temp token is valid for 5min and the same token returned if this method is called several times during this time. Passing ignoreExpiration flag to true will ignore this expiration delay and will always return a new token.
Returns
Observable
<string
>
Inherited from
Defined in
libs/sdk-core/src/lib/db/kb/kb.ts:692
getUsers()
getUsers():
Observable
<FullKbUser
[]>
Returns
Observable
<FullKbUser
[]>
Inherited from
Defined in
libs/sdk-core/src/lib/db/kb/kb.ts:733
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:754
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:833
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:778
listResources()
listResources(
page
?,size
?):Observable
<ResourceList
>
Lists all the resources stored in the Knowledge Box.
Parameters
• page?: number
• size?: number
Returns
Observable
<ResourceList
>
Inherited from
Defined in
libs/sdk-core/src/lib/db/kb/kb.ts:661
predictAnswer()
predictAnswer(
question
,options
?,synchronous
?):Observable
<Answer
|IErrorResponse
>
Performs a question answering operation
Example:
nuclia.knowledgeBox
.predictAnswer('Who is Eric from Toronto?'))
.subscribe((answer) => {
if (answer.type !== 'error') {
console.log('answer', answer.text);
}
});
Parameters
• question: string
• options?: PredictAnswerOptions
• synchronous?: boolean
= true
Returns
Observable
<Answer
| IErrorResponse
>
Inherited from
Defined in
libs/sdk-core/src/lib/db/kb/kb.ts:492
processingStatus()
processingStatus(
cursor
?,scheduled
?,limit
?):Observable
<object
>
Parameters
• cursor?: string
• scheduled?: boolean
• limit?: number
Returns
Observable
<object
>
cursor
cursor:
string
results
results:
ProcessingStatus
[]
Inherited from
IKnowledgeBox
.processingStatus
Defined in
libs/sdk-core/src/lib/db/kb/kb.ts:875
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
• question: string
• user_context?: string
[]
• rephrase_prompt?: string
Returns
Observable
<string
>
Inherited from
Defined in
libs/sdk-core/src/lib/db/kb/kb.ts:584
search()
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
• query: string
• features: Features
[] = []
• options?: SearchOptions
Returns
Observable
<Results
| IErrorResponse
>
Inherited from
Defined in
libs/sdk-core/src/lib/db/kb/kb.ts:416
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:765
suggest()
suggest(
query
,inTitleOnly
,features
):Observable
<Suggestions
|IErrorResponse
>
Suggests paragraphs based on the given query.
Parameters
• query: string
• inTitleOnly: boolean
= false
• features: SuggestionFeatures
[] = []
Returns
Observable
<Suggestions
| IErrorResponse
>
Inherited from
Defined in
libs/sdk-core/src/lib/db/kb/kb.ts:637
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
• ressourceIds: string
[]
• user_prompt?: string
• generative_model?: string
Returns
Observable
<string
>
Inherited from
Defined in
libs/sdk-core/src/lib/db/kb/kb.ts:442
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
• text: string
Returns
Observable
<SentenceToken
[]>