@nuclia/core / Exports / Resource
Class: Resource
Extends ReadableResource
and implements all the write operations.
Hierarchy
-
↳
Resource
Implements
Table of contents
Constructors
Properties
- computedmetadata
- created
- data
- extra
- fieldmetadata
- hidden
- icon
- id
- kb
- last_account_seq
- last_seqid
- metadata
- modified
- origin
- queue
- security
- slug
- summary
- thumbnail
- title
- usermetadata
- uuid
Accessors
Methods
- ask
- askToResource
- batchUpload
- delete
- deleteField
- find
- getClassifications
- getExtractedSummaries
- getExtractedTexts
- getField
- getFieldData
- getFields
- getFiles
- getNamedEntities
- getParagraphText
- getPositionedNamedEntities
- getSentenceText
- getThumbnails
- getThumbnailsUrl
- modify
- reprocess
- search
- setField
- setLabels
- upload
Constructors
constructor
• new Resource(nuclia
, kb
, data
)
Parameters
Name | Type |
---|---|
nuclia | INuclia |
kb | string |
data | IResource |
Overrides
Defined in
libs/sdk-core/src/lib/db/resource/resource.ts:196
Properties
computedmetadata
• Optional
computedmetadata: ComputedMetadata
Implementation of
Inherited from
ReadableResource.computedmetadata
Defined in
libs/sdk-core/src/lib/db/resource/resource.models.ts:10
created
• Optional
created: string
Implementation of
Inherited from
Defined in
libs/sdk-core/src/lib/db/resource/resource.models.ts:14
data
• data: ResourceData
= {}
Implementation of
Inherited from
Defined in
libs/sdk-core/src/lib/db/resource/resource.ts:42
extra
• Optional
extra: ExtraMetadata
Implementation of
Inherited from
Defined in
libs/sdk-core/src/lib/db/resource/resource.models.ts:11
fieldmetadata
• Optional
fieldmetadata: UserFieldMetadata
[]
Implementation of
Inherited from
ReadableResource.fieldmetadata
Defined in
libs/sdk-core/src/lib/db/resource/resource.models.ts:9
hidden
• Optional
hidden: boolean
Implementation of
Inherited from
Defined in
libs/sdk-core/src/lib/db/resource/resource.models.ts:20
icon
• Optional
icon: string
Implementation of
Inherited from
Defined in
libs/sdk-core/src/lib/db/resource/resource.models.ts:6
id
• id: string
Implementation of
Inherited from
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
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
Inherited from
Defined in
libs/sdk-core/src/lib/db/resource/resource.models.ts:17
metadata
• Optional
metadata: Metadata
Implementation of
Inherited from
Defined in
libs/sdk-core/src/lib/db/resource/resource.models.ts:7
modified
• Optional
modified: string
Implementation of
Inherited from
Defined in
libs/sdk-core/src/lib/db/resource/resource.models.ts:15
origin
• Optional
origin: Origin
Implementation of
Inherited from
Defined in
libs/sdk-core/src/lib/db/resource/resource.models.ts:12
queue
• Optional
queue: "private"
| "shared"
Implementation of
Inherited from
Defined in
libs/sdk-core/src/lib/db/resource/resource.models.ts:19
security
• Optional
security: Security
Implementation of
Inherited from
Defined in
libs/sdk-core/src/lib/db/resource/resource.models.ts:13
slug
• Optional
slug: string
Implementation of
Inherited from
Defined in
libs/sdk-core/src/lib/db/resource/resource.models.ts:3
summary
• Optional
summary: string
Implementation of
Inherited from
Defined in
libs/sdk-core/src/lib/db/resource/resource.models.ts:5
thumbnail
• Optional
thumbnail: string
Implementation of
Inherited from
Defined in
libs/sdk-core/src/lib/db/resource/resource.models.ts:16
title
• Optional
title: string
Implementation of
Inherited from
Defined in
libs/sdk-core/src/lib/db/resource/resource.models.ts:4
usermetadata
• Optional
usermetadata: UserMetadata
Implementation of
Inherited from
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
Name | Type |
---|---|
query | string |
context? | ContextEntry [] |
features? | Features [] |
options? | ChatOptions |
Returns
Observable
<IErrorResponse
| Answer
>
Defined in
libs/sdk-core/src/lib/db/resource/resource.ts:357
▸ 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
>
Defined in
libs/sdk-core/src/lib/db/resource/resource.ts:363
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
Name | Type |
---|---|
query | string |
context? | ContextEntry [] |
features? | Features [] |
options? | ChatOptions |
Returns
Observable
<IErrorResponse
| Answer
>
Defined in
libs/sdk-core/src/lib/db/resource/resource.ts:389
▸ askToResource(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
>
Defined in
libs/sdk-core/src/lib/db/resource/resource.ts:395
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
Name | Type |
---|---|
files | FileList | File [] |
Returns
Observable
<UploadStatus
>
Defined in
libs/sdk-core/src/lib/db/resource/resource.ts:324
delete
▸ delete(synchronous?
): Observable
<void
>
Deletes the resource.
Parameters
Name | Type | Default value |
---|---|---|
synchronous | boolean | true |
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
Name | Type | Default value |
---|---|---|
type | FIELD_TYPE | undefined |
field | string | undefined |
synchronous | boolean | false |
Returns
Observable
<void
>
Defined in
libs/sdk-core/src/lib/db/resource/resource.ts:262
find
▸ find(query
, features?
, options?
): Observable
<FindResults
| IErrorResponse
>
Performs a find operation in the resource.
Parameters
Name | Type | Default value |
---|---|---|
query | string | undefined |
features | ResourceFeatures [] | [] |
options? | SearchOptions | undefined |
Returns
Observable
<FindResults
| IErrorResponse
>
Defined in
libs/sdk-core/src/lib/db/resource/resource.ts:338
getClassifications
▸ getClassifications(): Classification
[]
Returns
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
Inherited from
ReadableResource.getExtractedTexts
Defined in
libs/sdk-core/src/lib/db/resource/resource.ts:77
getField
▸ getField(type
, field
, show?
, extracted?
): Observable
<ResourceField
>
Parameters
Name | Type |
---|---|
type | FIELD_TYPE |
field | string |
show | ResourceFieldProperties [] |
extracted | ExtractedDataTypes [] |
Returns
Observable
<ResourceField
>
Defined in
libs/sdk-core/src/lib/db/resource/resource.ts:237
getFieldData
▸ getFieldData<T
>(type
, fieldId
): undefined
| T
Type parameters
Name | Type |
---|---|
T | IFieldData |
Parameters
Name | Type |
---|---|
type | keyof ResourceData |
fieldId | string |
Returns
undefined
| T
Inherited from
Defined in
libs/sdk-core/src/lib/db/resource/resource.ts:64
getFields
▸ getFields<T
>(types?
): T
[]
Type parameters
Name | Type |
---|---|
T | IFieldData |
Parameters
Name | Type |
---|---|
types | keyof ResourceData [] |
Returns
T
[]
Inherited from
Defined in
libs/sdk-core/src/lib/db/resource/resource.ts:55
getFiles
▸ getFiles(): CloudLink
[]
Returns the files contained in the resource.
Returns
Inherited from
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
Name | Type |
---|---|
fieldType | FIELD_TYPE |
fieldId | string |
paragraph | Paragraph |
Returns
string
Inherited from
ReadableResource.getParagraphText
Defined in
libs/sdk-core/src/lib/db/resource/resource.ts:159
getPositionedNamedEntities
▸ getPositionedNamedEntities(fieldType
, fieldId
): PositionedNER
[]
Parameters
Name | Type |
---|---|
fieldType | keyof ResourceData |
fieldId | string |
Returns
Inherited from
ReadableResource.getPositionedNamedEntities
Defined in
libs/sdk-core/src/lib/db/resource/resource.ts:136
getSentenceText
▸ getSentenceText(fieldType
, fieldId
, sentence
): string
Parameters
Name | Type |
---|---|
fieldType | FIELD_TYPE |
fieldId | string |
sentence | Sentence |
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
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:253
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
Name | Type | Default value |
---|---|---|
data | Partial <ICreateResource > | undefined |
synchronous | boolean | true |
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
▸ search(query
, features?
, options?
): Observable
<Results
| IErrorResponse
>
Performs a search operation in the resource (similar as find()
but results are not nested).
Parameters
Name | Type | Default value |
---|---|---|
query | string | undefined |
features | ResourceFeatures [] | [] |
options? | SearchOptions | undefined |
Returns
Observable
<Results
| IErrorResponse
>
Defined in
libs/sdk-core/src/lib/db/resource/resource.ts:329
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
Name | Type |
---|---|
type | FIELD_TYPE |
field | string |
data | FileField | LinkField | TextField |
Returns
Observable
<void
>
Defined in
libs/sdk-core/src/lib/db/resource/resource.ts:290
setLabels
▸ setLabels(fieldId
, fieldType
, paragraphId
, labels
): Observable
<void
>
Parameters
Name | Type |
---|---|
fieldId | string |
fieldType | string |
paragraphId | string |
labels | Classification [] |
Returns
Observable
<void
>
Defined in
libs/sdk-core/src/lib/db/resource/resource.ts:413
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
Name | Type |
---|---|
field | string |
file | File |
TUS? | boolean |
metadata? | FileMetadata |
Returns
Observable
<UploadResponse
>
Defined in
libs/sdk-core/src/lib/db/resource/resource.ts:310
▸ upload(field
, buffer
, TUS?
, metadata?
): Observable
<UploadResponse
>
Parameters
Name | Type |
---|---|
field | string |
buffer | ArrayBuffer |
TUS? | boolean |
metadata? | FileMetadata |
Returns
Observable
<UploadResponse
>