Skip to main content

Db

@nuclia/coreDocs


@nuclia/core / Db

Class: Db

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

Implements

Constructors

new Db()

new Db(nuclia): Db

Parameters

nuclia: INuclia

Returns

Db

Defined in

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

Methods

addModelToKb()

addModelToKb(modelId, accountId, kbId, zone): Observable<void>

Add a custom model to a Knowledge Box

Parameters

modelId: string

accountId: string

kbId: string

zone: string

Returns

Observable<void>

Implementation of

IDb.addModelToKb

Defined in

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


createAccount()

createAccount(account): Observable<Account>

Creates a new account.

Parameters

account: AccountCreation

Returns

Observable<Account>

Implementation of

IDb.createAccount

Defined in

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


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

accountId: string

knowledgeBox: KnowledgeBoxCreation

zone?: string

Returns

Observable<WritableKnowledgeBox>

Implementation of

IDb.createKnowledgeBox

Defined in

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


createNUAClient()

createNUAClient(accountId, data)

createNUAClient(accountId, data): Observable<object>

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

Parameters

accountId: string

Account identifier

data: NUAClientPayload

NUA client data

Returns

Observable<object>

client_id

client_id: string

token

token: string

Implementation of

IDb.createNUAClient

Defined in

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

createNUAClient(accountId, data, zone)

createNUAClient(accountId, data, zone): Observable<object>

Parameters

accountId: string

data: NUAClientPayload

zone: string

Returns

Observable<object>

client_id

client_id: string

token

token: string

Implementation of

IDb.createNUAClient

Defined in

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


createRetrievalAgent()

createRetrievalAgent(accountId, retrievalAgent, zone): Observable<RetrievalAgent>

Creates a new Retrieval Agent.

const retrievalAgent = {
slug: 'my-arag',
title: 'My retrieval agent',
mode: 'agent'
};
nuclia.db.createRetrievalAgent('my-account-id', 'europe-1', retrievalAgent).subscribe((retrievalAgent) => {
console.log('retrieval agent', retrievalAgent);
});

#### Parameters

**accountId**: `string`

**retrievalAgent**: [`RetrievalAgentCreation`](../interfaces/RetrievalAgentCreation.md)

**zone**: `string`

#### Returns

`Observable`\<[`RetrievalAgent`](RetrievalAgent.md)\>

#### Implementation of

[`IDb`](../interfaces/IDb.md).[`createRetrievalAgent`](../interfaces/IDb.md#createretrievalagent)

#### Defined in

[libs/sdk-core/src/lib/db/db.ts:366](https://github.com/nuclia/frontend/blob/126db2bbf98f73c1f7b0ed36358198bf31bed3da/libs/sdk-core/src/lib/db/db.ts#L366)

***

### deleteAccount()

> **deleteAccount**(`accountSlug`): `Observable`\<`void`\>

Deletes an account.

#### Parameters

**accountSlug**: `string`

#### Returns

`Observable`\<`void`\>

#### Implementation of

[`IDb`](../interfaces/IDb.md).[`deleteAccount`](../interfaces/IDb.md#deleteaccount)

#### Defined in

[libs/sdk-core/src/lib/db/db.ts:103](https://github.com/nuclia/frontend/blob/126db2bbf98f73c1f7b0ed36358198bf31bed3da/libs/sdk-core/src/lib/db/db.ts#L103)

***

### deleteAccountInvitation()

> **deleteAccountInvitation**(`accountId`, `email`): `Observable`\<`void`\>

Delete account invitation

#### Parameters

**accountId**: `string`

**email**: `string`

#### Returns

`Observable`\<`void`\>

#### Implementation of

[`IDb`](../interfaces/IDb.md).[`deleteAccountInvitation`](../interfaces/IDb.md#deleteaccountinvitation)

#### Defined in

[libs/sdk-core/src/lib/db/db.ts:776](https://github.com/nuclia/frontend/blob/126db2bbf98f73c1f7b0ed36358198bf31bed3da/libs/sdk-core/src/lib/db/db.ts#L776)

***

### deleteModelFromKb()

> **deleteModelFromKb**(`modelId`, `accountId`, `kbId`, `zone`): `Observable`\<`void`\>

Add a custom model to a Knowledge Box

#### Parameters

**modelId**: `string`

**accountId**: `string`

**kbId**: `string`

**zone**: `string`

#### Returns

`Observable`\<`void`\>

#### Implementation of

[`IDb`](../interfaces/IDb.md).[`deleteModelFromKb`](../interfaces/IDb.md#deletemodelfromkb)

#### Defined in

[libs/sdk-core/src/lib/db/db.ts:811](https://github.com/nuclia/frontend/blob/126db2bbf98f73c1f7b0ed36358198bf31bed3da/libs/sdk-core/src/lib/db/db.ts#L811)

***

### deleteNUAClient()

#### deleteNUAClient(accountId, client_id)

> **deleteNUAClient**(`accountId`, `client_id`): `Observable`\<`void`\>

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

##### Parameters

**accountId**: `string`

**client\_id**: `string`

##### Returns

`Observable`\<`void`\>

##### Implementation of

[`IDb`](../interfaces/IDb.md).[`deleteNUAClient`](../interfaces/IDb.md#deletenuaclient)

##### Defined in

[libs/sdk-core/src/lib/db/db.ts:596](https://github.com/nuclia/frontend/blob/126db2bbf98f73c1f7b0ed36358198bf31bed3da/libs/sdk-core/src/lib/db/db.ts#L596)

#### deleteNUAClient(accountId, client_id, zone)

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

##### Parameters

**accountId**: `string`

**client\_id**: `string`

**zone**: `string`

##### Returns

`Observable`\<`void`\>

##### Implementation of

[`IDb`](../interfaces/IDb.md).[`deleteNUAClient`](../interfaces/IDb.md#deletenuaclient)

##### Defined in

[libs/sdk-core/src/lib/db/db.ts:597](https://github.com/nuclia/frontend/blob/126db2bbf98f73c1f7b0ed36358198bf31bed3da/libs/sdk-core/src/lib/db/db.ts#L597)

***

### getAccount()

> **getAccount**(): `Observable`\<[`Account`](../interfaces/Account.md)\>

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`](../interfaces/Account.md)\>

#### Implementation of

[`IDb`](../interfaces/IDb.md).[`getAccount`](../interfaces/IDb.md#getaccount)

#### Defined in

[libs/sdk-core/src/lib/db/db.ts:142](https://github.com/nuclia/frontend/blob/126db2bbf98f73c1f7b0ed36358198bf31bed3da/libs/sdk-core/src/lib/db/db.ts#L142)

***

### getAccountInvitations()

> **getAccountInvitations**(`accountId`): `Observable`\<[`PendingInvitation`](../interfaces/PendingInvitation.md)[]\>

List pending account invitations

#### Parameters

**accountId**: `string`

#### Returns

`Observable`\<[`PendingInvitation`](../interfaces/PendingInvitation.md)[]\>

#### Implementation of

[`IDb`](../interfaces/IDb.md).[`getAccountInvitations`](../interfaces/IDb.md#getaccountinvitations)

#### Defined in

[libs/sdk-core/src/lib/db/db.ts:767](https://github.com/nuclia/frontend/blob/126db2bbf98f73c1f7b0ed36358198bf31bed3da/libs/sdk-core/src/lib/db/db.ts#L767)

***

### getAccounts()

> **getAccounts**(): `Observable`\<[`Account`](../interfaces/Account.md)[]\>

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

#### Returns

`Observable`\<[`Account`](../interfaces/Account.md)[]\>

#### Implementation of

[`IDb`](../interfaces/IDb.md).[`getAccounts`](../interfaces/IDb.md#getaccounts)

#### Defined in

[libs/sdk-core/src/lib/db/db.ts:66](https://github.com/nuclia/frontend/blob/126db2bbf98f73c1f7b0ed36358198bf31bed3da/libs/sdk-core/src/lib/db/db.ts#L66)

***

### getAccountStatus()

> **getAccountStatus**(`accountSlug`): `Observable`\<[`AccountStatus`](../interfaces/AccountStatus.md)\>

Returns account status.

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

Parameters

accountSlug: string

Returns

Observable<AccountStatus>

Implementation of

IDb.getAccountStatus

Defined in

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


getAccountUser()

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

Get an account user by their id

Parameters

accountSlug: string

userId: string

Returns

Observable<Partial<FullAccountUser>>

Implementation of

IDb.getAccountUser

Defined in

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


getAccountUsers()

getAccountUsers(accountSlug): Observable<FullAccountUser[]>

Get the list of all users of an account

Parameters

accountSlug: string

Returns

Observable<FullAccountUser[]>

Implementation of

IDb.getAccountUsers

Defined in

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


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

accountSlug: string

Returns

Observable<KbIndex[]>

Implementation of

IDb.getKbIndexes

Defined in

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


getKnowledgeBox()

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:246

getKnowledgeBox(accountId, knowledgeBoxId, zone)

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

Parameters

accountId: string

knowledgeBoxId: string

zone?: string

Returns

Observable<WritableKnowledgeBox>

Implementation of

IDb.getKnowledgeBox

Defined in

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


getKnowledgeBoxes()

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:208

getKnowledgeBoxes(accountSlug, accountId)

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

Parameters

accountSlug: string

accountId: string

Returns

Observable<IKnowledgeBoxItem[]>

Implementation of

IDb.getKnowledgeBoxes

Defined in

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


getKnowledgeBoxesForZone()

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

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

Parameters

accountId: string

zone: string

Returns

Observable<IKnowledgeBoxItem[]>

Implementation of

IDb.getKnowledgeBoxesForZone

Defined in

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


getLearningSchema()

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:607

getLearningSchema(accountId, zone)

getLearningSchema(accountId, zone): Observable<LearningConfigurations>

Parameters

accountId: string

zone: string

Returns

Observable<LearningConfigurations>

Implementation of

IDb.getLearningSchema

Defined in

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


getModel()

getModel(modelId, accountId, zone): Observable<CustomModel>

Get a custom models

Parameters

modelId: string

accountId: string

zone: string

Returns

Observable<CustomModel>

Implementation of

IDb.getModel

Defined in

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


getModels()

getModels(accountId, zone): Observable<CustomModelItem[]>

Get the list of custom models of an account

Parameters

accountId: string

zone: string

Returns

Observable<CustomModelItem[]>

Implementation of

IDb.getModels

Defined in

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


getNUAActivity()

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

Parameters

accountId: string

client_id: string

zoneSlug: string

pageIndex: number = 0

Returns

Observable<EventList>

Implementation of

IDb.getNUAActivity

Defined in

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


getNUAClient()

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

Parameters

accountId: string

client_id: string

zone: string

Returns

Observable<NUAClient>

Implementation of

IDb.getNUAClient

Defined in

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


getNUAClients()

getNUAClients(accountId): Observable<NUAClient[]>

Parameters

accountId: string

Returns

Observable<NUAClient[]>

Implementation of

IDb.getNUAClients

Defined in

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


getNUAHeader()

getNUAHeader(): object

Returns

object

x-nuclia-nuakey

x-nuclia-nuakey: string

Defined in

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


getNUAKey()

getNUAKey(): string

Returns

string

Defined in

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


getRetrievalAgent()

getRetrievalAgent()

getRetrievalAgent(): Observable<RetrievalAgent>

Returns

Observable<RetrievalAgent>

Implementation of

IDb.getRetrievalAgent

Defined in

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

getRetrievalAgent(accountId, retrievalAgentId, zone)

getRetrievalAgent(accountId, retrievalAgentId, zone?): Observable<RetrievalAgent>

Parameters

accountId: string

retrievalAgentId: string

zone?: string

Returns

Observable<RetrievalAgent>

Implementation of

IDb.getRetrievalAgent

Defined in

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


getRetrievalAgents()

getRetrievalAgents()

getRetrievalAgents(): Observable<IKnowledgeBoxItem[]>

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

Returns

Observable<IKnowledgeBoxItem[]>

Implementation of

IDb.getRetrievalAgents

Defined in

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

getRetrievalAgents(accountSlug, accountId)

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

Parameters

accountSlug: string

accountId: string

Returns

Observable<IKnowledgeBoxItem[]>

Implementation of

IDb.getRetrievalAgents

Defined in

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


getRetrievalAgentsForZone()

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

Returns the list of Retrieval Agents for the given account id and zone.

Parameters

accountId: string

zone: string

Returns

Observable<IKnowledgeBoxItem[]>

Implementation of

IDb.getRetrievalAgentsForZone

Defined in

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


getStandaloneKbs()

getStandaloneKbs(): Observable<IStandaloneKb[]>

Returns

Observable<IStandaloneKb[]>

Implementation of

IDb.getStandaloneKbs

Defined in

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


getUsage()

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

Get usage metric for the account.

Parameters

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

IDb.getUsage

Defined in

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


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:134


hasNUAClient()

hasNUAClient(): boolean

Returns

boolean

Implementation of

IDb.hasNUAClient

Defined in

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


inviteToAccount()

inviteToAccount(accountSlug, data): Observable<void>

Invite a user to an account

Parameters

accountSlug: string

data: InviteAccountUserPayload

Returns

Observable<void>

Implementation of

IDb.inviteToAccount

Defined in

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


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

accountSlug: string

data: AccountModification

Returns

Observable<void>

Implementation of

IDb.modifyAccount

Defined in

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


predictAnswer()

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

Generate an answer from a question and a context.

Parameters

question: string

context: string[]

model?: string

Returns

Observable<string>

Implementation of

IDb.predictAnswer

Defined in

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


predictQuery()

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

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

Parameters

text: string

rephrase?: boolean

model?: string

rephrase_prompt?: string

Returns

Observable<QueryInfo>

Implementation of

IDb.predictQuery

Defined in

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


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

text: string

user_prompt?: string

model?: string = '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:689


predictTokens()

predictTokens(text): Observable<PredictedToken[]>

Extract NER tokens from a text.

Parameters

text: string

Returns

Observable<PredictedToken[]>

Implementation of

IDb.predictTokens

Defined in

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


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:460


renewNUAClient()

renewNUAClient(accountId, client_id)

renewNUAClient(accountId, client_id): Observable<object>

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

Parameters

accountId: string

client_id: string

Returns

Observable<object>

client_id

client_id: string

token

token: string

Implementation of

IDb.renewNUAClient

Defined in

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

renewNUAClient(accountId, client_id, zone)

renewNUAClient(accountId, client_id, zone): Observable<object>

Parameters

accountId: string

client_id: string

zone: string

Returns

Observable<object>

client_id

client_id: string

token

token: string

Implementation of

IDb.renewNUAClient

Defined in

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


setAccountUsers()

setAccountUsers(accountSlug, users): Observable<void>

Add and/or delete users from an account

Parameters

accountSlug: string

users: AccountUsersPayload

Returns

Observable<void>

Implementation of

IDb.setAccountUsers

Defined in

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


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

file: FileWithMetadata

Returns

Observable<ProcessingPushResponse>

Implementation of

IDb.upload

Defined in

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