Skip to main content

General Entity Extraction

Extract named entities and spans from text using prompted entity extraction.

Endpoint​

POST https://api.platform.knowledgator.com/inference/extract/


Headers​

NameTypeDescription
KnowledgatorAPI-KeyStringPrimary platform API key.
Content-TypeStringapplication/json
KnowledgatorAPI-Model-IDStringOptional LoRA adapter ID for fine-tuned models.

Request Body​

{
"text": "Your input text here.",
"entities": ["person", "location", "organization"],
"prompt": "Extract all people and organizations mentioned.",
"threshold": 0.5
}

Parameters​

  • text (string, required): Input text to analyze.
  • entities (array of strings, required): List of entity types/concepts to extract (e.g., ["person", "location", "product"]).
  • prompt (string, optional): Additional instruction/task hint.
  • threshold (float, optional): Minimum score to keep a span. Default: 0.5

Response​

{
"outputs": [
{
"entity": "person",
"span": "John Smith",
"start": 0,
"end": 10,
"score": 0.93
},
{
"entity": "organization",
"span": "Acme Corp",
"start": 25,
"end": 34,
"score": 0.87
}
]
}

Response Fields​

  • outputs: Array of extracted entities
    • entity: Predicted entity label
    • span: Substring of text corresponding to the extracted mention
    • start: Character offset (0-based, inclusive)
    • end: Character offset (0-based, exclusive)
    • score: Model confidence for this span

Error Codes​

Status CodeDescription
200OK – Request successful.
400Bad Request – Invalid or incomplete input.
401Unauthorized – Invalid API key.
404Not Found – Invalid endpoint.
413Payload Too Large – Exceeds size limit.
500Internal Server Error – Server-side issue.

Example Usage​

SDK Usage​

💡 Dedicated SDK Guides: See Python SDK | TypeScript SDK

TypeScript/JavaScript​

import { createClient } from '@knowledgator/typescript-sdk';

const kg = createClient('YOUR_API_KEY');

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}`);
}
}

Python​

from knowledgator import Knowledgator

kg = Knowledgator(api_key="YOUR_API_KEY")

result = 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
)

for entity in result.outputs["entities"].value:
print(f"{entity.span} ({entity.entity}): {entity.score}")

Expected SDK Output​

John Smith (person): 0.93
Acme Corp (organization): 0.87

Python (requests)​

import requests

url = "https://api.platform.knowledgator.com/inference/extract/"
headers = {
"Content-Type": "application/json",
"KnowledgatorAPI-Key": "YOUR_API_KEY",
"KnowledgatorAPI-Model-ID": "your-model-id" # Optional
}
payload = {
"text": "John Smith works at Acme Corp in New York.",
"entities": ["person", "organization", "location"],
"threshold": 0.5
}

response = requests.post(url, json=payload, headers=headers)
print(response.json())

cURL​

curl -X POST https://api.platform.knowledgator.com/inference/extract/ \
-H "Content-Type: application/json" \
-H "KnowledgatorAPI-Key: YOUR_API_KEY" \
-H "KnowledgatorAPI-Model-ID: your-model-id" \
-d '{
"text": "John Smith works at Acme Corp in New York.",
"entities": ["person", "organization", "location"],
"threshold": 0.5
}'

Expected Response (cURL & requests)​

{
"outputs": [
{
"entity": "person",
"span": "John Smith",
"start": 0,
"end": 10,
"score": 0.93
},
{
"entity": "organization",
"span": "Acme Corp",
"start": 25,
"end": 34,
"score": 0.87
}
]
}

Additional Information​

  • Entity Flexibility: Supports any entity types in natural language
  • Use Cases:
    • Named entity recognition (NER)
    • Custom entity extraction
    • Document information extraction
    • Knowledge base population