@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
-
↳
KnowledgeBox
Implements
Table of contents
Constructors
Properties
- accountId
- allowed_origins
- description
- external_index_provider
- hidden_resources_enabled
- hidden_resources_hide_on_creation
- id
- nuclia
- search_configs
- slug
- state
- title
- uuid
- zone
Accessors
Methods
- ask
- catalog
- counters
- createAgenticRAGPipeline
- feedback
- find
- generate
- generateJSON
- generateRandomQuestionAboutResource
- getConfiguration
- getEntities
- getEntitiesGroup
- getFullResource
- getFullResourceBySlug
- getInvites
- getLabels
- getLearningSchema
- getResource
- getResourceBySlug
- getResourceFromData
- getSynonyms
- getTempToken
- getUsers
- listResources
- listenToAllNotifications
- listenToProcessingNotifications
- listenToResourceOperationNotifications
- processingStatus
- rephrase
- search
- stopListeningToNotifications
- suggest
- summarize
- tokens
Constructors
constructor
• new KnowledgeBox(nuclia
, account
, data
)
Parameters
Name | Type |
---|---|
nuclia | INuclia |
account | string |
data | IKnowledgeBoxCreation |
Inherited from
IKnowledgeBox.constructor
Defined in
libs/sdk-core/src/lib/db/kb/kb.ts:124
Properties
accountId
• accountId: string
Defined in
libs/sdk-core/src/lib/db/kb/kb.ts:74
allowed_origins
• Optional
allowed_origins: null
| string
[]
Implementation of
Inherited from
Defined in
libs/sdk-core/src/lib/db/kb/kb.models.ts:28
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:73
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:30
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:31
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:75
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:29
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
uuid
• Optional
uuid: string
Implementation of
Inherited from
Defined in
libs/sdk-core/src/lib/db/kb/kb.models.ts:27
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
Inherited from
IKnowledgeBox.fullpath
Defined in
libs/sdk-core/src/lib/db/kb/kb.ts:120
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:111
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
Name | Type |
---|---|
query | string |
context? | ContextEntry [] |
features? | Features [] |
options? | ChatOptions |
Returns
Observable
<IErrorResponse
| Answer
>
Inherited from
Defined in
libs/sdk-core/src/lib/db/kb/kb.ts:285
▸ ask(query
, context?
, features?
, options?
, callback?
): Observable
<null
>
Parameters
Name | Type |
---|---|
query | string |
context? | ContextEntry [] |
features? | Features [] |
options? | ChatOptions |
callback? | (answer : IErrorResponse | Answer ) => void |
Returns
Observable
<null
>
Inherited from
Defined in
libs/sdk-core/src/lib/db/kb/kb.ts:291
catalog
▸ catalog(query
, options?
): Observable
<Results
| IErrorResponse
>
Parameters
Name | Type |
---|---|
query | string |
options? | SearchOptions |
Returns
Observable
<Results
| IErrorResponse
>
Inherited from
Defined in
libs/sdk-core/src/lib/db/kb/kb.ts:583
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:607
createAgenticRAGPipeline
▸ createAgenticRAGPipeline(steps
): Pipeline
Parameters
Name | Type |
---|---|
steps | Steps |
Returns
Inherited from
IKnowledgeBox.createAgenticRAGPipeline
Defined in
libs/sdk-core/src/lib/db/kb/kb.ts:263
feedback
▸ feedback(answerId
, good
, feedback?
, text_block_id?
): Observable
<void
>
Parameters
Name | Type | Default value |
---|---|---|
answerId | string | undefined |
good | boolean | undefined |
feedback | string | '' |
text_block_id? | string | undefined |
Returns
Observable
<void
>
Inherited from
Defined in
libs/sdk-core/src/lib/db/kb/kb.ts:596
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
Name | Type | Default value |
---|---|---|
query | string | undefined |
features | Features [] | [] |
options? | SearchOptions | undefined |
Returns
Observable
<FindResults
| IErrorResponse
>
Inherited from
Defined in
libs/sdk-core/src/lib/db/kb/kb.ts:325
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
Name | Type | Default value |
---|---|---|
question | string | undefined |
context | string [] | [] |
Returns
Observable
<{ answer
: string
; cannotAnswer
: boolean
}>
Inherited from
Defined in
libs/sdk-core/src/lib/db/kb/kb.ts:425
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
Name | Type | Default value |
---|---|---|
question | string | undefined |
json_schema | object | undefined |
context | string [] | [] |
Returns
Observable
<{ answer
: object
; success
: boolean
}>
Inherited from
Defined in
libs/sdk-core/src/lib/db/kb/kb.ts:485
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
Name | Type |
---|---|
resource | Resource |
Returns
Observable
<string
>
Inherited from
IKnowledgeBox.generateRandomQuestionAboutResource
Defined in
libs/sdk-core/src/lib/db/kb/kb.ts:557
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:669
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:137
getEntitiesGroup
▸ getEntitiesGroup(groupId
): Observable
<EntitiesGroup
>
Returns the NER family with the given id.
Parameters
Name | Type |
---|---|
groupId | string |
Returns
Observable
<EntitiesGroup
>
Inherited from
IKnowledgeBox.getEntitiesGroup
Defined in
libs/sdk-core/src/lib/db/kb/kb.ts:142
getFullResource
▸ getFullResource(uuid
): Observable
<Resource
>
Retrieves a resource from the Knowledge Box with all its attached metadata and content.
Parameters
Name | Type |
---|---|
uuid | string |
Returns
Observable
<Resource
>
Inherited from
Defined in
libs/sdk-core/src/lib/db/kb/kb.ts:187
getFullResourceBySlug
▸ getFullResourceBySlug(slug
): Observable
<Resource
>
Parameters
Name | Type |
---|---|
slug | string |
Returns
Observable
<Resource
>
Inherited from
IKnowledgeBox.getFullResourceBySlug
Defined in
libs/sdk-core/src/lib/db/kb/kb.ts:213
getInvites
▸ getInvites(): Observable
<KbInvite
[]>
Returns
Observable
<KbInvite
[]>
Defined in
libs/sdk-core/src/lib/db/kb/kb.ts:688
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:151
getLearningSchema
▸ getLearningSchema(): Observable
<LearningConfigurations
>
Returns
Observable
<LearningConfigurations
>
Inherited from
IKnowledgeBox.getLearningSchema
Defined in
libs/sdk-core/src/lib/db/kb/kb.ts:673
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
Name | Type | Default value |
---|---|---|
uuid | string | undefined |
show | ResourceProperties [] | undefined |
extracted | ExtractedDataTypes [] | [] |
Returns
Observable
<Resource
>
Inherited from
Defined in
libs/sdk-core/src/lib/db/kb/kb.ts:176
getResourceBySlug
▸ getResourceBySlug(slug
, show?
, extracted?
): Observable
<Resource
>
Parameters
Name | Type | Default value |
---|---|---|
slug | string | undefined |
show | ResourceProperties [] | undefined |
extracted | ExtractedDataTypes [] | [] |
Returns
Observable
<Resource
>
Inherited from
IKnowledgeBox.getResourceBySlug
Defined in
libs/sdk-core/src/lib/db/kb/kb.ts:205
getResourceFromData
▸ getResourceFromData(data
): Resource
Parameters
Name | Type |
---|---|
data | IResource |
Returns
Defined in
libs/sdk-core/src/lib/db/kb/kb.ts:259
getSynonyms
▸ getSynonyms(): Observable
<Synonyms
>
Returns
Observable
<Synonyms
>
Inherited from
Defined in
libs/sdk-core/src/lib/db/kb/kb.ts:146
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
Defined in
libs/sdk-core/src/lib/db/kb/kb.ts:639
getUsers
▸ getUsers(): Observable
<FullKbUser
[]>
Returns
Observable
<FullKbUser
[]>
Inherited from
Defined in
libs/sdk-core/src/lib/db/kb/kb.ts:679
listResources
▸ listResources(page?
, size?
): Observable
<ResourceList
>
Lists all the resources stored in the Knowledge Box.
Parameters
Name | Type |
---|---|
page? | number |
size? | number |
Returns
Observable
<ResourceList
>
Inherited from
Defined in
libs/sdk-core/src/lib/db/kb/kb.ts:612
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:700
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:779
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:724
processingStatus
▸ processingStatus(cursor?
, scheduled?
, limit?
): Observable
<{ cursor
: string
; results
: ProcessingStatus
[] }>
Parameters
Name | Type |
---|---|
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:821
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
Name | Type |
---|---|
question | string |
user_context? | string [] |
rephrase_prompt? | string |
Returns
Observable
<string
>
Inherited from
Defined in
libs/sdk-core/src/lib/db/kb/kb.ts:535
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
Name | Type | Default value |
---|---|---|
query | string | undefined |
features | Features [] | [] |
options? | SearchOptions | undefined |
Returns
Observable
<Results
| IErrorResponse
>
Inherited from
Defined in
libs/sdk-core/src/lib/db/kb/kb.ts:347
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:711
suggest
▸ suggest(query
, inTitleOnly?
, features?
): Observable
<Suggestions
| IErrorResponse
>
Suggests paragraphs based on the given query.
Parameters
Name | Type | Default value |
---|---|---|
query | string | undefined |
inTitleOnly | boolean | false |
features | SuggestionFeatures [] | [] |
Returns
Observable
<Suggestions
| IErrorResponse
>
Inherited from
Defined in
libs/sdk-core/src/lib/db/kb/kb.ts:588
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
Name | Type |
---|---|
ressourceIds | string [] |
user_prompt? | string |
generative_model? | string |
Returns
Observable
<string
>
Inherited from
Defined in
libs/sdk-core/src/lib/db/kb/kb.ts:373
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
Name | Type |
---|---|
text | string |
Returns
Observable
<SentenceToken
[]>