> ## Documentation Index
> Fetch the complete documentation index at: https://docs.fastino.ai/llms.txt
> Use this file to discover all available pages before exploring further.

> ## Agent Instructions
> Use https://docs.fastino.ai/llms.txt to discover and navigate pages. Use https://docs.fastino.ai/llms-full.txt when you need the complete documentation corpus. Use https://docs.fastino.ai/openapi.json as the source of truth for customer-facing routes. For GLiDE decision inference, call POST https://api.fastino.ai/v1/systemone with model fastino/GLiDE. Do not infer undocumented routes. Read API keys from FASTINO_API_KEY and never embed credentials in code, logs, or reports.

# Rezept: Relationen zwischen Entitäten extrahieren

> Finden Sie mit GLiNER 2.5 Multi heraus, wer wo arbeitet, was sich wo befindet und wer wen übernommen hat – als Paare aus Head und Tail.

Die Relationsextraktion wandelt Sätze in Fakten um, die Sie in einem Graphen oder einer Tabelle speichern können. Sie definieren die Entitätslabels und die Relationstypen, und GLiNER gibt jede Relation als Head-Entität, Tail-Entität und Relationstyp zurück.

## Anfrage

```bash theme={null}
curl -X POST https://api.fastino.ai/v1/chat/completions \
  -H "Authorization: Bearer $FASTINO_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
  "model": "fastino/gliner2.5-multi-v1",
  "messages": [
    {
      "role": "user",
      "content": "Lena Vogel works for Siemens in Munich. Siemens acquired Altair Engineering in 2025."
    }
  ],
  "schema": {
    "entities": [
      {
        "name": "person",
        "description": "full name of a person"
      },
      {
        "name": "organization",
        "description": "company or institution"
      },
      {
        "name": "location",
        "description": "city or country"
      }
    ],
    "relations": {
      "works_for": {
        "description": "a person is employed by an organization"
      },
      "located_in": {
        "description": "an organization or person is based in a place"
      },
      "acquired": {
        "description": "one organization bought another"
      }
    }
  },
  "threshold": 0.5,
  "store": false
}'
```

## Anfrageschema

| Feld | Typ | In diesem Rezept |
| - | - | - |
| `model` | string | `fastino/gliner2.5-multi-v1`. |
| `messages` | array | Eine `user`-Nachricht mit dem zu lesenden Text. |
| `schema.entities` | array | Die Entitätslabels, die Relationen verbinden. |
| `schema.relations` | object | Ein Schlüssel pro Relationstyp. `description` beschreibt, was die Relation bedeutet, einschließlich ihrer Richtung. |
| `threshold` | number | Mindestkonfidenz, von 0 bis 1. Standard `0.5`. |
| `store` | boolean | Standardmäßig `true`, wodurch die Inferenz gespeichert wird. Mit `false` widersprechen Sie. |

## Antwort

GLiNER gibt das Ergebnis als JSON-String in `choices[0].message.content` zurück. Geparst sieht es so aus. Gemessen gegen `https://api.fastino.ai`; Konfidenzwerte schwanken zwischen Aufrufen geringfügig.

```json theme={null}
{
  "entities": {
    "person": [
      {
        "text": "Lena Vogel",
        "confidence": 1.0,
        "start": 0,
        "end": 10
      }
    ],
    "organization": [
      {
        "text": "Siemens",
        "confidence": 0.996,
        "start": 21,
        "end": 28
      },
      {
        "text": "Siemens",
        "confidence": 0.992,
        "start": 40,
        "end": 47
      },
      {
        "text": "Altair Engineering",
        "confidence": 0.973,
        "start": 57,
        "end": 75
      }
    ],
    "location": [
      {
        "text": "Munich",
        "confidence": 1.0,
        "start": 32,
        "end": 38
      }
    ]
  },
  "relation_extraction": {
    "works_for": [
      {
        "head": {
          "text": "Lena Vogel",
          "start": 0,
          "end": 10,
          "confidence": 0.988
        },
        "tail": {
          "text": "Siemens",
          "start": 21,
          "end": 28,
          "confidence": 0.988
        }
      }
    ],
    "located_in": [
      {
        "head": {
          "text": "Siemens",
          "start": 40,
          "end": 47,
          "confidence": 0.977
        },
        "tail": {
          "text": "Munich",
          "start": 32,
          "end": 38,
          "confidence": 0.977
        }
      }
    ],
    "acquired": [
      {
        "head": {
          "text": "Siemens",
          "start": 40,
          "end": 47,
          "confidence": 0.938
        },
        "tail": {
          "text": "Altair Engineering",
          "start": 57,
          "end": 75,
          "confidence": 0.938
        }
      }
    ]
  }
}
```

## Antwortschema

| Feld | Typ | Bedeutung |
| - | - | - |
| `relation_extraction` | object | Ein Schlüssel pro definiertem Relationstyp. |
| `relation_extraction.<type>[].head` | object | Die Entität, von der die Relation ausgeht, mit `text`, `confidence`, `start` und `end`. |
| `relation_extraction.<type>[].tail` | object | Die Entität, auf die die Relation zeigt, mit denselben Feldern. |

Relationen kommen unter `relation_extraction` zurück, nicht unter `relations`.

## Auf die Antwort reagieren

```python theme={null}
import json

result = json.loads(response.json()["choices"][0]["message"]["content"])

facts = [
    (pair["head"]["text"], relation, pair["tail"]["text"])
    for relation, pairs in result["relation_extraction"].items()
    for pair in pairs
    if min(pair["head"]["confidence"], pair["tail"]["confidence"]) >= 0.5
]
for head, relation, tail in facts:
    graph.add_edge(head, tail, type=relation)
```

## Anpassen

* Geben Sie in jeder Beschreibung die Richtung an, etwa „a person is employed by an organization“, damit Head und Tail richtig herum zurückkommen.
* Definieren Sie Entitätslabels für jede Art von Objekt, die Ihre Relationen verbinden, damit die Entitäten in Ihren Ergebnissen typisiert sind.
* Senken Sie `threshold` während der Abstimmung, um Beinahe-Treffer zu sehen, und filtern Sie dann im Code nach der Konfidenz von Head und Tail.
* Speichern Sie `start` und `end` mit jedem Fakt, damit Sie ihn bis zum Quellsatz zurückverfolgen können.

<CardGroup cols={2}>
  <Card title="GLiNER aufrufen" icon="braces" href="/de/inference/chat-completions">
    Alle GLiNER-Schematypen und wie Sie deren Ergebnis lesen.
  </Card>

  <Card title="Chat-Completions-API-Referenz" icon="code" href="/de/api-reference/inference/chat-completions">
    Alle Felder, Grenzen und Fehler für `POST /v1/chat/completions`.
  </Card>
</CardGroup>


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.