Table of Contents

Method ExtractKeywords

Namespace
LMKit.TextAnalysis
Assembly
LM-Kit.NET.dll

ExtractKeywords(string, CancellationToken)

Extracts a set of keywords synchronously from the given text content.

public List<KeywordExtraction.KeywordItem> ExtractKeywords(string content, CancellationToken cancellationToken = default)

Parameters

content string

The text content from which to extract keywords.

cancellationToken CancellationToken

A token to cancel the operation if needed.

Returns

List<KeywordExtraction.KeywordItem>

A list of extracted KeywordExtraction.KeywordItem instances.

Examples

using LMKit.Model;
using LMKit.TextAnalysis;
using System;

LM model = LM.LoadFromModelID("lmkit-tasks:4b-preview");
KeywordExtraction extractor = new KeywordExtraction(model);

var keywords = extractor.ExtractKeywords("Artificial intelligence is revolutionizing the automotive industry with self-driving cars.");
foreach (var keyword in keywords)
{
    Console.WriteLine(keyword.Value);
}

Exceptions

ArgumentNullException

Thrown when the content is null or empty.

ExtractKeywords(Attachment, CancellationToken)

Extracts a set of keywords synchronously from an Attachment. For multi-page documents (e.g. PDF), all pages are analyzed.

public List<KeywordExtraction.KeywordItem> ExtractKeywords(Attachment content, CancellationToken cancellationToken = default)

Parameters

content Attachment

The attachment to analyze. Can be an image or a multi-page document.

cancellationToken CancellationToken

A token to cancel the operation if needed.

Returns

List<KeywordExtraction.KeywordItem>

A list of extracted KeywordExtraction.KeywordItem instances.

Examples

using LMKit.Model;
using LMKit.TextAnalysis;
using LMKit.Data;
using System;

// Load a vision-capable model
LM model = LM.LoadFromModelID("lmkit-tasks:4b-preview");
KeywordExtraction extractor = new KeywordExtraction(model);

// Extract keywords from an image
var imageAttachment = new Attachment("product_photo.jpg");
var keywords = extractor.ExtractKeywords(imageAttachment);

Console.WriteLine("Keywords from image:");
foreach (var keyword in keywords)
{
    Console.WriteLine($"  - {keyword.Value}");
}

Exceptions

ArgumentNullException

Thrown when the attachment is null.

InvalidModelException

Thrown when the underlying language model does not support the required inference modality.

ExtractKeywords(Attachment, string, CancellationToken)

Extracts a set of keywords synchronously from the specified page range of an Attachment.

public List<KeywordExtraction.KeywordItem> ExtractKeywords(Attachment content, string pageRange, CancellationToken cancellationToken = default)

Parameters

content Attachment

The attachment to analyze. Can be an image or a multi-page document.

pageRange string

A page range string using 1-based page numbers (e.g., "1-5, 7, 9-12"). If null, empty, or "*", all pages are analyzed.

cancellationToken CancellationToken

A token to cancel the operation if needed.

Returns

List<KeywordExtraction.KeywordItem>

A list of extracted KeywordExtraction.KeywordItem instances.

Exceptions

ArgumentNullException

Thrown when the attachment is null.

InvalidModelException

Thrown when the underlying language model does not support the required inference modality.

Share