Skip to main content

@nuclia/core / Exports / Db

Class: Db

Allows you to access Nuclia accounts and/or Nuclia Knowledge Boxes.

Implements

Table of contents

Constructors

Methods

Constructors

constructor

new Db(nuclia)

Parameters

NameType
nucliaINuclia

Defined in

libs/sdk-core/src/lib/db/db.ts:52

Methods

createAccount

createAccount(account): Observable<Account>

Creates a new account.

Parameters

NameType
accountAccountCreation

Returns

Observable<Account>

Implementation of

IDb.createAccount

Defined in

libs/sdk-core/src/lib/db/db.ts:70


createKnowledgeBox

createKnowledgeBox(accountId, knowledgeBox, zone?): Observable<WritableKnowledgeBox>

Creates a new Knowledge Box. Zone parameter is mandatory except if the Knowledge Box is from a local NucliaDB instance. Example:

const knowledgeBox = {
slug: 'my-kb',
title: 'My knowledge box',
};
nuclia.db.createKnowledgeBox('my-account-id', 'europe-1', knowledgeBox).subscribe((knowledgeBox) => {
console.log('knowledge box', knowledgeBox);
});

Parameters

NameType
accountIdstring
knowledgeBoxKnowledgeBoxCreation
zone?string

Returns

Observable<WritableKnowledgeBox>

Implementation of

IDb.createKnowledgeBox

Defined in

libs/sdk-core/src/lib/db/db.ts:244


createNUAClient

createNUAClient(accountId, data): Observable<{ client_id: string ; token: string }>

Creates a NUA client and a NUA token. Zone parameter must be provided except when working with a local NucliaDB instance.

Parameters

NameTypeDescription
accountIdstringAccount identifier
dataNUAClientPayloadNUA client data

Returns

Observable<{ client_id: string ; token: string }>

Implementation of

IDb.createNUAClient

Defined in

libs/sdk-core/src/lib/db/db.ts:411

createNUAClient(accountId, data, zone): Observable<{ client_id: string ; token: string }>

Parameters

NameType
accountIdstring
dataNUAClientPayload
zonestring

Returns

Observable<{ client_id: string ; token: string }>

Implementation of

IDb.createNUAClient

Defined in

libs/sdk-core/src/lib/db/db.ts:412


deleteAccount

deleteAccount(accountSlug): Observable<void>

Deletes an account.

Parameters

NameType
accountSlugstring

Returns

Observable<void>

Implementation of

IDb.deleteAccount

Defined in

libs/sdk-core/src/lib/db/db.ts:94


deleteAccountInvitation

deleteAccountInvitation(accountId, email): Observable<void>

Delete account invitation

Parameters

NameType
accountIdstring
emailstring

Returns

Observable<void>

Implementation of

IDb.deleteAccountInvitation

Defined in

libs/sdk-core/src/lib/db/db.ts:665


deleteNUAClient

deleteNUAClient(accountId, client_id): Observable<void>

Deletes a NUA client. Zone parameter must be provided except when working with a local NucliaDB instance.

Parameters

NameType
accountIdstring
client_idstring

Returns

Observable<void>

Implementation of

IDb.deleteNUAClient

Defined in

libs/sdk-core/src/lib/db/db.ts:485

deleteNUAClient(accountId, client_id, zone): Observable<void>

Parameters

NameType
accountIdstring
client_idstring
zonestring

Returns

Observable<void>

Implementation of

IDb.deleteNUAClient

Defined in

libs/sdk-core/src/lib/db/db.ts:486


getAccount

getAccount(): Observable<Account>

Returns the account with the given id or slug, or the one defined in the Nuclia options if no id nor slug is provided.

Returns

Observable<Account>

Implementation of

IDb.getAccount

Defined in

libs/sdk-core/src/lib/db/db.ts:133


getAccountInvitations

getAccountInvitations(accountId): Observable<PendingInvitation[]>

List pending account invitations

Parameters

NameType
accountIdstring

Returns

Observable<PendingInvitation[]>

Implementation of

IDb.getAccountInvitations

Defined in

libs/sdk-core/src/lib/db/db.ts:656


getAccountStatus

getAccountStatus(accountSlug): Observable<AccountStatus>

Returns account status.

Example:

nuclia.db
.getAccountStatus('my-account')
.pipe(filter((status) => status.available))
.subscribe((status) => {
console.log('account ready');
});

Parameters

NameType
accountSlugstring

Returns

Observable<AccountStatus>

Implementation of

IDb.getAccountStatus

Defined in

libs/sdk-core/src/lib/db/db.ts:111


getAccountUser

getAccountUser(accountSlug, userId): Observable<Partial<FullAccountUser>>

Get an account user by their id

Parameters

NameType
accountSlugstring
userIdstring

Returns

Observable<Partial<FullAccountUser>>

Implementation of

IDb.getAccountUser

Defined in

libs/sdk-core/src/lib/db/db.ts:620


getAccountUsers

getAccountUsers(accountSlug): Observable<FullAccountUser[]>

Get the list of all users of an account

Parameters

NameType
accountSlugstring

Returns

Observable<FullAccountUser[]>

Implementation of

IDb.getAccountUsers

Defined in

libs/sdk-core/src/lib/db/db.ts:628


getAccounts

getAccounts(): Observable<Account[]>

Returns a list of all the accounts which are accessible for the current authenticated user.

Returns

Observable<Account[]>

Implementation of

IDb.getAccounts

Defined in

libs/sdk-core/src/lib/db/db.ts:57


getKbIndexes

getKbIndexes(accountSlug): Observable<KbIndex[]>

Returns a list of all the KB indexes (account id, kb id, zone id) for the provided account slug.

Parameters

NameType
accountSlugstring

Returns

Observable<KbIndex[]>

Implementation of

IDb.getKbIndexes

Defined in

libs/sdk-core/src/lib/db/db.ts:65


getKnowledgeBox

getKnowledgeBox(): Observable<WritableKnowledgeBox>

Returns the Knowledge Box corresponding to the account id, Knowledge Box id and zone provided as parameters or the ones defined in the Nuclia options if no parameters are provided. Zone is mandatory except if the Knowledge Box is from a local NucliaDB instance.

Returns

Observable<WritableKnowledgeBox>

Implementation of

IDb.getKnowledgeBox

Defined in

libs/sdk-core/src/lib/db/db.ts:193

getKnowledgeBox(accountId, knowledgeBoxId, zone?): Observable<WritableKnowledgeBox>

Parameters

NameType
accountIdstring
knowledgeBoxIdstring
zone?string

Returns

Observable<WritableKnowledgeBox>

Implementation of

IDb.getKnowledgeBox

Defined in

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


getKnowledgeBoxes

getKnowledgeBoxes(): Observable<IKnowledgeBoxItem[]>

Returns a list of all the Knowledge Boxes for the given account. Account slug and id can be provided in the Nuclia options or as parameters.

Returns

Observable<IKnowledgeBoxItem[]>

Implementation of

IDb.getKnowledgeBoxes

Defined in

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

getKnowledgeBoxes(accountSlug, accountId): Observable<IKnowledgeBoxItem[]>

Parameters

NameType
accountSlugstring
accountIdstring

Returns

Observable<IKnowledgeBoxItem[]>

Implementation of

IDb.getKnowledgeBoxes

Defined in

libs/sdk-core/src/lib/db/db.ts:150


getKnowledgeBoxesForZone

getKnowledgeBoxesForZone(accountId, zone): Observable<IKnowledgeBoxItem[]>

Returns the list of Knowledge Boxes for the given account id and zone.

Parameters

NameType
accountIdstring
zonestring

Returns

Observable<IKnowledgeBoxItem[]>

Implementation of

IDb.getKnowledgeBoxesForZone

Defined in

libs/sdk-core/src/lib/db/db.ts:184


getLearningSchema

getLearningSchema(): Observable<LearningConfigurations>

Get learning configuration schema. When used on Cloud account, this method is requiring account id and zone parameters. When used on standalone, this method doesn't take any parameter

Returns

Observable<LearningConfigurations>

Implementation of

IDb.getLearningSchema

Defined in

libs/sdk-core/src/lib/db/db.ts:496

getLearningSchema(accountId, zone): Observable<LearningConfigurations>

Parameters

NameType
accountIdstring
zonestring

Returns

Observable<LearningConfigurations>

Implementation of

IDb.getLearningSchema

Defined in

libs/sdk-core/src/lib/db/db.ts:497


getNUAActivity

getNUAActivity(accountId, client_id, zoneSlug, pageIndex?): Observable<EventList>

Parameters

NameTypeDefault value
accountIdstringundefined
client_idstringundefined
zoneSlugstringundefined
pageIndexnumber0

Returns

Observable<EventList>

Implementation of

IDb.getNUAActivity

Defined in

libs/sdk-core/src/lib/db/db.ts:356


getNUAClient

getNUAClient(accountId, client_id, zone): Observable<NUAClient>

Parameters

NameType
accountIdstring
client_idstring
zonestring

Returns

Observable<NUAClient>

Implementation of

IDb.getNUAClient

Defined in

libs/sdk-core/src/lib/db/db.ts:387


getNUAClients

getNUAClients(accountId): Observable<NUAClient[]>

Parameters

NameType
accountIdstring

Returns

Observable<NUAClient[]>

Implementation of

IDb.getNUAClients

Defined in

libs/sdk-core/src/lib/db/db.ts:365


getNUAHeader

getNUAHeader(): Object

Returns

Object

NameType
x-nuclia-nuakeystring

Defined in

libs/sdk-core/src/lib/db/db.ts:399


getNUAKey

getNUAKey(): string

Returns

string

Defined in

libs/sdk-core/src/lib/db/db.ts:395


getStandaloneKbs

getStandaloneKbs(): Observable<IStandaloneKb[]>

Returns

Observable<IStandaloneKb[]>

Implementation of

IDb.getStandaloneKbs

Defined in

libs/sdk-core/src/lib/db/db.ts:142


getUsage

getUsage(accountId, from, to?, knowledgeBoxId?, aggregation?): Observable<UsagePoint[]>

Get usage metric for the account.

Parameters

NameTypeDescription
accountIdstringAccount identifier
fromstringTimestamp of the moment from which we want the metrics.
to?stringTimestamp of the moment until which we want the metrics. When not provided, the metrics are returned "until now".
knowledgeBoxId?stringKnowledge Box identifier to get the metrics for a specific Knowledge Box (returns the metrics aggregated for all the Knowledge Boxes of the account by default)
aggregation?UsageAggregationDefine how the metrics are aggregated. By default, the endpoint returns only one point aggregating all the data for the specified date range. But you can have one point by: - "hour" - "day" - "week" - "month" - "quarter" - "year" - "millennium" (used by default)

Returns

Observable<UsagePoint[]>

Implementation of

IDb.getUsage

Defined in

libs/sdk-core/src/lib/db/db.ts:288


getWelcome

getWelcome(): Observable<Welcome>

Returns user information.

Example:

nuclia.db.getWelcome().subscribe((welcome) => {
console.log(`Welcome ${welcome.preferences.name}`);
});

Returns

Observable<Welcome>

Implementation of

IDb.getWelcome

Defined in

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


hasNUAClient

hasNUAClient(): boolean

Returns

boolean

Implementation of

IDb.hasNUAClient

Defined in

libs/sdk-core/src/lib/db/db.ts:391


inviteToAccount

inviteToAccount(accountSlug, data): Observable<void>

Invite a user to an account

Parameters

NameType
accountSlugstring
dataInviteAccountUserPayload

Returns

Observable<void>

Implementation of

IDb.inviteToAccount

Defined in

libs/sdk-core/src/lib/db/db.ts:647


modifyAccount

modifyAccount(accountSlug, data): Observable<void>

Modifies account properties.

Example:

nuclia.db.modifyAccount('my-account', { title: 'My account' }).subscribe({
next: () => {
console.log('account modified');
},
error: (error) => {
console.error(error);
},
});

Parameters

NameType
accountSlugstring
dataAccountModification

Returns

Observable<void>

Implementation of

IDb.modifyAccount

Defined in

libs/sdk-core/src/lib/db/db.ts:89


predictAnswer

predictAnswer(question, context, model?): Observable<string>

Generate an answer from a question and a context.

Parameters

NameType
questionstring
contextstring[]
model?string

Returns

Observable<string>

Implementation of

IDb.predictAnswer

Defined in

libs/sdk-core/src/lib/db/db.ts:529


predictQuery

predictQuery(text, rephrase?, model?, rephrase_prompt?): Observable<QueryInfo>

Analyse a sentence, returning the language, the entities intent and the embeddings.

Parameters

NameType
textstring
rephrase?boolean
model?string
rephrase_prompt?string

Returns

Observable<QueryInfo>

Implementation of

IDb.predictQuery

Defined in

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


predictSummarize

predictSummarize(text, user_prompt?, model?, summary_kind?): Observable<string>

Generate a summary from a text.

The optional user_prompt parameter allows you to provide a custom prompt to the model, it 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}').

Parameters

NameTypeDefault value
textstringundefined
user_prompt?stringundefined
modelstring'chatgpt-azure-4o'
summary_kind"simple" | "extended"'simple'

Returns

Observable<string>

Implementation of

IDb.predictSummarize

Defined in

libs/sdk-core/src/lib/db/db.ts:578


predictTokens

predictTokens(text): Observable<PredictedToken[]>

Extract NER tokens from a text.

Parameters

NameType
textstring

Returns

Observable<PredictedToken[]>

Implementation of

IDb.predictTokens

Defined in

libs/sdk-core/src/lib/db/db.ts:514


pull

pull(): Observable<ProcessingPullResponse>

Pulls the latest data from Nuclia Understanding API.

Requires a NUA token.

Returns

Observable<ProcessingPullResponse>

Implementation of

IDb.pull

Defined in

libs/sdk-core/src/lib/db/db.ts:349


renewNUAClient

renewNUAClient(accountId, client_id): Observable<{ client_id: string ; token: string }>

Renews a NUA token. Zone parameter must be provided except when working with a local NucliaDB instance.

Parameters

NameType
accountIdstring
client_idstring

Returns

Observable<{ client_id: string ; token: string }>

Implementation of

IDb.renewNUAClient

Defined in

libs/sdk-core/src/lib/db/db.ts:464

renewNUAClient(accountId, client_id, zone): Observable<{ client_id: string ; token: string }>

Parameters

NameType
accountIdstring
client_idstring
zonestring

Returns

Observable<{ client_id: string ; token: string }>

Implementation of

IDb.renewNUAClient

Defined in

libs/sdk-core/src/lib/db/db.ts:465


setAccountUsers

setAccountUsers(accountSlug, users): Observable<void>

Add and/or delete users from an account

Parameters

NameType
accountSlugstring
usersAccountUsersPayload

Returns

Observable<void>

Implementation of

IDb.setAccountUsers

Defined in

libs/sdk-core/src/lib/db/db.ts:637


upload

upload(file): Observable<ProcessingPushResponse>

Uploads and pushes a file to Nuclia Understanding API.

Requires a NUA token.

Example:

const file = input.files[0];
nuclia.db.upload(file).subscribe({
next: (response) => {
console.log('file uploaded', response);
},
error: (error) => {
console.error(error);
},
});

Parameters

NameType
fileFileWithMetadata

Returns

Observable<ProcessingPushResponse>

Implementation of

IDb.upload

Defined in

libs/sdk-core/src/lib/db/db.ts:327