General Entity Extraction
Extract named entities and spans from text using prompted entity extraction.
Endpoint
POST https://api.platform.knowledgator.com/inference/extract/
Headers
| Name | Type | Description |
|---|---|---|
KnowledgatorAPI-Key | String | Primary platform API key. |
Content-Type | String | application/json |
KnowledgatorAPI-Model-ID | String | Optional 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 entitiesentity: Predicted entity labelspan: Substring of text corresponding to the extracted mentionstart: Character offset (0-based, inclusive)end: Character offset (0-based, exclusive)score: Model confidence for this span
Error Codes
| Status Code | Description |
|---|---|
| 200 | OK – Request successful. |
| 400 | Bad Request – Invalid or incomplete input. |
| 401 | Unauthorized – Invalid API key. |
| 404 | Not Found – Invalid endpoint. |
| 413 | Payload Too Large – Exceeds size limit. |
| 500 | Internal 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