Skip to main content

@nuclia/core / Exports / Resource

Class: Resource

Extends ReadableResource and implements all the write operations.

Hierarchy

Implements

Table of contents

Constructors

Properties

Accessors

Methods

Constructors

constructor

new Resource(nuclia, kb, data)

Parameters

NameType
nucliaINuclia
kbstring
dataIResource

Overrides

ReadableResource.constructor

Defined in

libs/sdk-core/src/lib/db/resource/resource.ts:196

Properties

computedmetadata

Optional computedmetadata: ComputedMetadata

Implementation of

IResource.computedmetadata

Inherited from

ReadableResource.computedmetadata

Defined in

libs/sdk-core/src/lib/db/resource/resource.models.ts:10


created

Optional created: string

Implementation of

IResource.created

Inherited from

ReadableResource.created

Defined in

libs/sdk-core/src/lib/db/resource/resource.models.ts:14


data

data: ResourceData = {}

Implementation of

IResource.data

Inherited from

ReadableResource.data

Defined in

libs/sdk-core/src/lib/db/resource/resource.ts:42


extra

Optional extra: ExtraMetadata

Implementation of

IResource.extra

Inherited from

ReadableResource.extra

Defined in

libs/sdk-core/src/lib/db/resource/resource.models.ts:11


fieldmetadata

Optional fieldmetadata: UserFieldMetadata[]

Implementation of

IResource.fieldmetadata

Inherited from

ReadableResource.fieldmetadata

Defined in

libs/sdk-core/src/lib/db/resource/resource.models.ts:9


hidden

Optional hidden: boolean

Implementation of

IResource.hidden

Inherited from

ReadableResource.hidden

Defined in

libs/sdk-core/src/lib/db/resource/resource.models.ts:20


icon

Optional icon: string

Implementation of

IResource.icon

Inherited from

ReadableResource.icon

Defined in

libs/sdk-core/src/lib/db/resource/resource.models.ts:6


id

id: string

Implementation of

IResource.id

Inherited from

ReadableResource.id

Defined in

libs/sdk-core/src/lib/db/resource/resource.models.ts:2


kb

kb: string

Defined in

libs/sdk-core/src/lib/db/resource/resource.ts:181


last_account_seq

Optional last_account_seq: number

Implementation of

IResource.last_account_seq

Inherited from

ReadableResource.last_account_seq

Defined in

libs/sdk-core/src/lib/db/resource/resource.models.ts:18


last_seqid

Optional last_seqid: number

Implementation of

IResource.last_seqid

Inherited from

ReadableResource.last_seqid

Defined in

libs/sdk-core/src/lib/db/resource/resource.models.ts:17


metadata

Optional metadata: Metadata

Implementation of

IResource.metadata

Inherited from

ReadableResource.metadata

Defined in

libs/sdk-core/src/lib/db/resource/resource.models.ts:7


modified

Optional modified: string

Implementation of

IResource.modified

Inherited from

ReadableResource.modified

Defined in

libs/sdk-core/src/lib/db/resource/resource.models.ts:15


origin

Optional origin: Origin

Implementation of

IResource.origin

Inherited from

ReadableResource.origin

Defined in

libs/sdk-core/src/lib/db/resource/resource.models.ts:12


queue

Optional queue: "private" | "shared"

Implementation of

IResource.queue

Inherited from

ReadableResource.queue

Defined in

libs/sdk-core/src/lib/db/resource/resource.models.ts:19


security

Optional security: Security

Implementation of

IResource.security

Inherited from

ReadableResource.security

Defined in

libs/sdk-core/src/lib/db/resource/resource.models.ts:13


slug

Optional slug: string

Implementation of

IResource.slug

Inherited from

ReadableResource.slug

Defined in

libs/sdk-core/src/lib/db/resource/resource.models.ts:3


summary

Optional summary: string

Implementation of

IResource.summary

Inherited from

ReadableResource.summary

Defined in

libs/sdk-core/src/lib/db/resource/resource.models.ts:5


thumbnail

Optional thumbnail: string

Implementation of

IResource.thumbnail

Inherited from

ReadableResource.thumbnail

Defined in

libs/sdk-core/src/lib/db/resource/resource.models.ts:16


title

Optional title: string

Implementation of

IResource.title

Inherited from

ReadableResource.title

Defined in

libs/sdk-core/src/lib/db/resource/resource.models.ts:4


usermetadata

Optional usermetadata: UserMetadata

Implementation of

IResource.usermetadata

Inherited from

ReadableResource.usermetadata

Defined in

libs/sdk-core/src/lib/db/resource/resource.models.ts:8


uuid

uuid: string

Defined in

libs/sdk-core/src/lib/db/resource/resource.ts:182

Accessors

kbPath

get kbPath(): string

Returns

string

Defined in

libs/sdk-core/src/lib/db/resource/resource.ts:185


path

get path(): string

Returns

string

Defined in

libs/sdk-core/src/lib/db/resource/resource.ts:189

Methods

ask

ask(query, context?, features?, options?): Observable<IErrorResponse | Answer>

Retrieves a generative answer for the given query based on the results of a search operation performed on the resource.

Parameters

NameType
querystring
context?ContextEntry[]
features?Features[]
options?ChatOptions

Returns

Observable<IErrorResponse | Answer>

Defined in

libs/sdk-core/src/lib/db/resource/resource.ts:361

ask(query, context?, features?, options?, callback?): Observable<null>

Parameters

NameType
querystring
context?ContextEntry[]
features?Features[]
options?ChatOptions
callback?(answer: IErrorResponse | Answer) => void

Returns

Observable<null>

Defined in

libs/sdk-core/src/lib/db/resource/resource.ts:367


askToResource

askToResource(query, context?, features?, options?): Observable<IErrorResponse | Answer>

Retrieves a generative answer for the given query using the entire resource as context (the resource's text might be shorten if too large).

Parameters

NameType
querystring
context?ContextEntry[]
features?Features[]
options?ChatOptions

Returns

Observable<IErrorResponse | Answer>

Defined in

libs/sdk-core/src/lib/db/resource/resource.ts:393

askToResource(query, context?, features?, options?, callback?): Observable<null>

Parameters

NameType
querystring
context?ContextEntry[]
features?Features[]
options?ChatOptions
callback?(answer: IErrorResponse | Answer) => void

Returns

Observable<null>

Defined in

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


batchUpload

batchUpload(files): Observable<UploadStatus>

Uploads a list of files in the resource. It automatically creates a new field for each file (named according to the filename). It uses the TUS protocol to upload the files.

Parameters

NameType
filesFileList | File[]

Returns

Observable<UploadStatus>

Defined in

libs/sdk-core/src/lib/db/resource/resource.ts:328


delete

delete(synchronous?): Observable<void>

Deletes the resource.

Parameters

NameTypeDefault value
synchronousbooleantrue

Returns

Observable<void>

Defined in

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


deleteField

deleteField(type, field, synchronous?): Observable<void>

Deletes the field with the given type and id.

Parameters

NameTypeDefault value
typeFIELD_TYPEundefined
fieldstringundefined
synchronousbooleanfalse

Returns

Observable<void>

Defined in

libs/sdk-core/src/lib/db/resource/resource.ts:266


find

find(query, features?, options?): Observable<FindResults | IErrorResponse>

Performs a find operation in the resource.

Parameters

NameTypeDefault value
querystringundefined
featuresResourceFeatures[][]
options?SearchOptionsundefined

Returns

Observable<FindResults | IErrorResponse>

Defined in

libs/sdk-core/src/lib/db/resource/resource.ts:342


getClassifications

getClassifications(): Classification[]

Returns

Classification[]

Inherited from

ReadableResource.getClassifications

Defined in

libs/sdk-core/src/lib/db/resource/resource.ts:119


getExtractedSummaries

getExtractedSummaries(): string[]

Returns the summaries generated by Nuclia for every resource fields.

Returns

string[]

Inherited from

ReadableResource.getExtractedSummaries

Defined in

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


getExtractedTexts

getExtractedTexts(): ExtractedText[]

Returns the texts generated by Nuclia for every resource fields.

Returns

ExtractedText[]

Inherited from

ReadableResource.getExtractedTexts

Defined in

libs/sdk-core/src/lib/db/resource/resource.ts:77


getField

getField(type, field, show?, extracted?, page?): Observable<ResourceField>

Parameters

NameTypeDefault value
typeFIELD_TYPEundefined
fieldstringundefined
showResourceFieldProperties[]undefined
extractedExtractedDataTypes[]undefined
pageundefined | number | "last"undefined

Returns

Observable<ResourceField>

Defined in

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


getFieldData

getFieldData<T>(type, fieldId): undefined | T

Type parameters

NameType
TIFieldData

Parameters

NameType
typekeyof ResourceData
fieldIdstring

Returns

undefined | T

Inherited from

ReadableResource.getFieldData

Defined in

libs/sdk-core/src/lib/db/resource/resource.ts:64


getFields

getFields<T>(types?): T[]

Type parameters

NameType
TIFieldData

Parameters

NameType
typeskeyof ResourceData[]

Returns

T[]

Inherited from

ReadableResource.getFields

Defined in

libs/sdk-core/src/lib/db/resource/resource.ts:55


getFiles

getFiles(): CloudLink[]

Returns the files contained in the resource.

Returns

CloudLink[]

Inherited from

ReadableResource.getFiles

Defined in

libs/sdk-core/src/lib/db/resource/resource.ts:84


getNamedEntities

getNamedEntities(): Object

Returns the entities extracted from the resource.

Returns

Object

Inherited from

ReadableResource.getNamedEntities

Defined in

libs/sdk-core/src/lib/db/resource/resource.ts:99


getParagraphText

getParagraphText(fieldType, fieldId, paragraph): string

Parameters

NameType
fieldTypeFIELD_TYPE
fieldIdstring
paragraphParagraph

Returns

string

Inherited from

ReadableResource.getParagraphText

Defined in

libs/sdk-core/src/lib/db/resource/resource.ts:159


getPositionedNamedEntities

getPositionedNamedEntities(fieldType, fieldId): PositionedNER[]

Parameters

NameType
fieldTypekeyof ResourceData
fieldIdstring

Returns

PositionedNER[]

Inherited from

ReadableResource.getPositionedNamedEntities

Defined in

libs/sdk-core/src/lib/db/resource/resource.ts:136


getSentenceText

getSentenceText(fieldType, fieldId, sentence): string

Parameters

NameType
fieldTypeFIELD_TYPE
fieldIdstring
sentenceSentence

Returns

string

Inherited from

ReadableResource.getSentenceText

Defined in

libs/sdk-core/src/lib/db/resource/resource.ts:163


getThumbnails

getThumbnails(): CloudLink[]

Returns the thumbnails generated by Nuclia for every resource fields.

Returns

CloudLink[]

Inherited from

ReadableResource.getThumbnails

Defined in

libs/sdk-core/src/lib/db/resource/resource.ts:91


getThumbnailsUrl

getThumbnailsUrl(): Observable<string[]>

Returns the thumbnails generated by Nuclia for every resource fields as blob: URLs.

Returns

Observable<string[]>

Defined in

libs/sdk-core/src/lib/db/resource/resource.ts:257


modify

modify(data, synchronous?): Observable<void>

Modifies the resource attributes.

Example:

nuclia.db
.getKnowledgeBox('my-account', 'my-kb')
.pipe(
switchMap((knowledgeBox) => knowledgeBox.getResource('my-resource')),
switchMap((resource) => resource.modify({ description: 'new description' })),
)
.subscribe(() => {
console.log('resource modified');
});

Parameters

NameTypeDefault value
dataPartial<ICreateResource>undefined
synchronousbooleantrue

Returns

Observable<void>

Defined in

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


reprocess

reprocess(): Observable<void>

Triggers a resource reprocessing.

Returns

Observable<void>

Defined in

libs/sdk-core/src/lib/db/resource/resource.ts:231


search(query, features?, options?): Observable<Results | IErrorResponse>

Performs a search operation in the resource (similar as find() but results are not nested).

Parameters

NameTypeDefault value
querystringundefined
featuresResourceFeatures[][]
options?SearchOptionsundefined

Returns

Observable<Results | IErrorResponse>

Defined in

libs/sdk-core/src/lib/db/resource/resource.ts:333


setField

setField(type, field, data): Observable<void>

Adds or updates a field in the resource.

Example:

nuclia.db
.getKnowledgeBox('my-account', 'my-kb')
.pipe(
switchMap((knowledgeBox) =>
knowledgeBox.getResource('my-resource').pipe(
switchMap((resource) =>
resource.setField(FIELD_TYPE.text, 'my-field', {
body: '*my text*',
format: 'MARKDOWN',
}),
),
),
),
)
.subscribe(() => {
console.log('field added');
});

Parameters

NameType
typeFIELD_TYPE
fieldstring
dataFileField | LinkField | TextField

Returns

Observable<void>

Defined in

libs/sdk-core/src/lib/db/resource/resource.ts:294


setLabels

setLabels(fieldId, fieldType, paragraphId, labels): Observable<void>

Parameters

NameType
fieldIdstring
fieldTypestring
paragraphIdstring
labelsClassification[]

Returns

Observable<void>

Defined in

libs/sdk-core/src/lib/db/resource/resource.ts:417


upload

upload(field, file, TUS?, metadata?): Observable<UploadResponse>

Uploads a file in the resource. The field will be stored in the indicated field.

Example:

nuclia.db
.getKnowledgeBox('my-account', 'my-kb')
.pipe(
switchMap((knowledgeBox) => knowledgeBox.getResource('my-resource')),
switchMap((resource) => resource.upload(fileInputElement.files[0])),
)
.subscribe(() => {
console.log('file uploaded');
});

Parameters

NameType
fieldstring
fileFile
TUS?boolean
metadata?FileMetadata

Returns

Observable<UploadResponse>

Defined in

libs/sdk-core/src/lib/db/resource/resource.ts:314

upload(field, buffer, TUS?, metadata?): Observable<UploadResponse>

Parameters

NameType
fieldstring
bufferArrayBuffer
TUS?boolean
metadata?FileMetadata

Returns

Observable<UploadResponse>

Defined in

libs/sdk-core/src/lib/db/resource/resource.ts:315