@nuclia/core / Exports / Db
Class: Db
Allows you to access Nuclia accounts and/or Nuclia Knowledge Boxes.
Implements
Table of contents
Constructors
Methods
- createAccount
- createKnowledgeBox
- createNUAClient
- deleteAccount
- deleteAccountInvitation
- deleteNUAClient
- getAccount
- getAccountInvitations
- getAccountStatus
- getAccountUser
- getAccountUsers
- getAccounts
- getKbIndexes
- getKnowledgeBox
- getKnowledgeBoxes
- getKnowledgeBoxesForZone
- getLearningSchema
- getNUAActivity
- getNUAClient
- getNUAClients
- getNUAHeader
- getNUAKey
- getStandaloneKbs
- getUsage
- getWelcome
- hasNUAClient
- inviteToAccount
- modifyAccount
- predictAnswer
- predictQuery
- predictSummarize
- predictTokens
- pull
- renewNUAClient
- setAccountUsers
- upload
Constructors
constructor
• new Db(nuclia
)
Parameters
Name | Type |
---|---|
nuclia | INuclia |
Defined in
libs/sdk-core/src/lib/db/db.ts:58
Methods
createAccount
▸ createAccount(account
): Observable
<Account
>
Creates a new account.
Parameters
Name | Type |
---|---|
account | AccountCreation |
Returns
Observable
<Account
>
Implementation of
Defined in
libs/sdk-core/src/lib/db/db.ts:76
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
Name | Type |
---|---|
accountId | string |
knowledgeBox | KnowledgeBoxCreation |
zone? | string |
Returns
Observable
<WritableKnowledgeBox
>
Implementation of
Defined in
libs/sdk-core/src/lib/db/db.ts:250
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
Name | Type | Description |
---|---|---|
accountId | string | Account identifier |
data | NUAClientPayload | NUA client data |
Returns
Observable
<{ client_id
: string
; token
: string
}>
Implementation of
Defined in
libs/sdk-core/src/lib/db/db.ts:411
▸ createNUAClient(accountId
, data
, zone
): Observable
<{ client_id
: string
; token
: string
}>
Parameters
Name | Type |
---|---|
accountId | string |
data | NUAClientPayload |
zone | string |
Returns
Observable
<{ client_id
: string
; token
: string
}>
Implementation of
Defined in
libs/sdk-core/src/lib/db/db.ts:412
deleteAccount
▸ deleteAccount(accountSlug
): Observable
<void
>
Deletes an account.
Parameters
Name | Type |
---|---|
accountSlug | string |
Returns
Observable
<void
>
Implementation of
Defined in
libs/sdk-core/src/lib/db/db.ts:100
deleteAccountInvitation
▸ deleteAccountInvitation(accountId
, email
): Observable
<void
>
Delete account invitation
Parameters
Name | Type |
---|---|
accountId | string |
email | string |
Returns
Observable
<void
>
Implementation of
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
Name | Type |
---|---|
accountId | string |
client_id | string |
Returns
Observable
<void
>
Implementation of
Defined in
libs/sdk-core/src/lib/db/db.ts:485
▸ deleteNUAClient(accountId
, client_id
, zone
): Observable
<void
>
Parameters
Name | Type |
---|---|
accountId | string |
client_id | string |
zone | string |
Returns
Observable
<void
>
Implementation of
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
Defined in
libs/sdk-core/src/lib/db/db.ts:139
getAccountInvitations
▸ getAccountInvitations(accountId
): Observable
<PendingInvitation
[]>
List pending account invitations
Parameters
Name | Type |
---|---|
accountId | string |
Returns
Observable
<PendingInvitation
[]>
Implementation of
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
Name | Type |
---|---|
accountSlug | string |
Returns
Observable
<AccountStatus
>
Implementation of
Defined in
libs/sdk-core/src/lib/db/db.ts:117
getAccountUser
▸ getAccountUser(accountSlug
, userId
): Observable
<Partial
<FullAccountUser
>>
Get an account user by their id
Parameters
Name | Type |
---|---|
accountSlug | string |
userId | string |
Returns
Observable
<Partial
<FullAccountUser
>>
Implementation of
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
Name | Type |
---|---|
accountSlug | string |
Returns
Observable
<FullAccountUser
[]>
Implementation of
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
Defined in
libs/sdk-core/src/lib/db/db.ts:63
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
Name | Type |
---|---|
accountSlug | string |
Returns
Observable
<KbIndex
[]>
Implementation of
Defined in
libs/sdk-core/src/lib/db/db.ts:71
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
Defined in
libs/sdk-core/src/lib/db/db.ts:199
▸ getKnowledgeBox(accountId
, knowledgeBoxId
, zone?
): Observable
<WritableKnowledgeBox
>
Parameters
Name | Type |
---|---|
accountId | string |
knowledgeBoxId | string |
zone? | string |
Returns
Observable
<WritableKnowledgeBox
>
Implementation of
Defined in
libs/sdk-core/src/lib/db/db.ts:200
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
Defined in
libs/sdk-core/src/lib/db/db.ts:155
▸ getKnowledgeBoxes(accountSlug
, accountId
): Observable
<IKnowledgeBoxItem
[]>
Parameters
Name | Type |
---|---|
accountSlug | string |
accountId | string |
Returns
Observable
<IKnowledgeBoxItem
[]>
Implementation of
Defined in
libs/sdk-core/src/lib/db/db.ts:156
getKnowledgeBoxesForZone
▸ getKnowledgeBoxesForZone(accountId
, zone
): Observable
<IKnowledgeBoxItem
[]>
Returns the list of Knowledge Boxes for the given account id and zone.
Parameters
Name | Type |
---|---|
accountId | string |
zone | string |
Returns
Observable
<IKnowledgeBoxItem
[]>
Implementation of
Defined in
libs/sdk-core/src/lib/db/db.ts:190
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
Defined in
libs/sdk-core/src/lib/db/db.ts:496
▸ getLearningSchema(accountId
, zone
): Observable
<LearningConfigurations
>
Parameters
Name | Type |
---|---|
accountId | string |
zone | string |
Returns
Observable
<LearningConfigurations
>
Implementation of
Defined in
libs/sdk-core/src/lib/db/db.ts:497
getNUAActivity
▸ getNUAActivity(accountId
, client_id
, zoneSlug
, pageIndex?
): Observable
<EventList
>
Parameters
Name | Type | Default value |
---|---|---|
accountId | string | undefined |
client_id | string | undefined |
zoneSlug | string | undefined |
pageIndex | number | 0 |
Returns
Observable
<EventList
>
Implementation of
Defined in
libs/sdk-core/src/lib/db/db.ts:356
getNUAClient
▸ getNUAClient(accountId
, client_id
, zone
): Observable
<NUAClient
>
Parameters
Name | Type |
---|---|
accountId | string |
client_id | string |
zone | string |
Returns
Observable
<NUAClient
>
Implementation of
Defined in
libs/sdk-core/src/lib/db/db.ts:387
getNUAClients
▸ getNUAClients(accountId
): Observable
<NUAClient
[]>
Parameters
Name | Type |
---|---|
accountId | string |
Returns
Observable
<NUAClient
[]>
Implementation of
Defined in
libs/sdk-core/src/lib/db/db.ts:365
getNUAHeader
▸ getNUAHeader(): Object
Returns
Object
Name | Type |
---|---|
x-nuclia-nuakey | string |
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
Defined in
libs/sdk-core/src/lib/db/db.ts:148
getUsage
▸ getUsage(accountId
, from
, to?
, knowledgeBoxId?
, aggregation?
): Observable
<UsagePoint
[]>
Get usage metric for the account.
Parameters
Name | Type | Description |
---|---|---|
accountId | string | Account identifier |
from | string | Timestamp of the moment from which we want the metrics. |
to? | string | Timestamp of the moment until which we want the metrics. When not provided, the metrics are returned "until now". |
knowledgeBoxId? | string | Knowledge 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? | UsageAggregation | Define 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
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
Defined in
libs/sdk-core/src/lib/db/db.ts:131
hasNUAClient
▸ hasNUAClient(): boolean
Returns
boolean
Implementation of
Defined in
libs/sdk-core/src/lib/db/db.ts:391
inviteToAccount
▸ inviteToAccount(accountSlug
, data
): Observable
<void
>
Invite a user to an account
Parameters
Name | Type |
---|---|
accountSlug | string |
data | InviteAccountUserPayload |
Returns
Observable
<void
>
Implementation of
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
Name | Type |
---|---|
accountSlug | string |
data | AccountModification |
Returns
Observable
<void
>
Implementation of
Defined in
libs/sdk-core/src/lib/db/db.ts:95
predictAnswer
▸ predictAnswer(question
, context
, model?
): Observable
<string
>
Generate an answer from a question and a context.
Parameters
Name | Type |
---|---|
question | string |
context | string [] |
model? | string |
Returns
Observable
<string
>
Implementation of
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
Name | Type |
---|---|
text | string |
rephrase? | boolean |
model? | string |
rephrase_prompt? | string |
Returns
Observable
<QueryInfo
>
Implementation of
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
Name | Type | Default value |
---|---|---|
text | string | undefined |
user_prompt? | string | undefined |
model | string | 'chatgpt-azure-4o' |
summary_kind | "simple" | "extended" | 'simple' |
Returns
Observable
<string
>
Implementation of
Defined in
libs/sdk-core/src/lib/db/db.ts:578
predictTokens
▸ predictTokens(text
): Observable
<PredictedToken
[]>
Extract NER tokens from a text.
Parameters
Name | Type |
---|---|
text | string |
Returns
Observable
<PredictedToken
[]>
Implementation of
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
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
Name | Type |
---|---|
accountId | string |
client_id | string |
Returns
Observable
<{ client_id
: string
; token
: string
}>
Implementation of
Defined in
libs/sdk-core/src/lib/db/db.ts:464
▸ renewNUAClient(accountId
, client_id
, zone
): Observable
<{ client_id
: string
; token
: string
}>
Parameters
Name | Type |
---|---|
accountId | string |
client_id | string |
zone | string |
Returns
Observable
<{ client_id
: string
; token
: string
}>
Implementation of
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
Name | Type |
---|---|
accountSlug | string |
users | AccountUsersPayload |
Returns
Observable
<void
>
Implementation of
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
Name | Type |
---|---|
file | FileWithMetadata |
Returns
Observable
<ProcessingPushResponse
>