General Entity Extraction
Extract named entities and spans from text using prompted entity extraction with the Knowledgator TypeScript SDK.
Example Usage
import { createClient } from '@knowledgator/typescript-sdk';
const kg = createClient();
const result = await kg.extract.it({
text: "John Smith works at Acme Corp in New York.",
tasks: {
entities: {
type: "span",
labels: ["person", "organization", "location"],
threshold: 0.5,
},
},
adapter_id: "your-lora-adapter-id", // Optional LoRA adapter
});
const entitiesTask = result.outputs.entities;
if (Array.isArray(entitiesTask.value)) {
for (const entity of entitiesTask.value) {
console.log(`${entity.span} (${entity.entity}): ${entity.score}`);
}
}
LoRA Adapters vs. Open Models
adapter_id is for fine-tuned LoRA adapters attached to base services. If you trained a standalone Open Model (e.g. GLiClass or GLiNER checkpoint), query it via kg.model(model_id).predict(...) instead.
Expected Output
John Smith (person): 0.93
Acme Corp (organization): 0.87
Result Object Structure
{
"outputs": {
"entities": {
"type": "span",
"value": [
{
"span": "John Smith",
"entity": "person",
"start": 0,
"end": 10,
"score": 0.93
},
{
"span": "Acme Corp",
"entity": "organization",
"start": 25,
"end": 34,
"score": 0.87
}
],
"threshold": 0.5
}
}
}