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

# AI Triple Generation

> Use AI to automatically extract knowledge from natural language

## Overview

Neode can automatically generate triples from natural language using AI. Just describe what you want to know, and Neode extracts structured facts.

## Basic Generation

```bash theme={null}
curl -X POST "https://neode.ai/api/triples/generate?format=json" \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -d '{
    "query": "Extract key facts about Tesla and its products",
    "index_id": "YOUR_INDEX_ID",
    "triple_count": 10
  }'
```

Response:

```json theme={null}
{
  "success": true,
  "data": [
    {
      "id": "uuid-1",
      "subject": "Tesla",
      "predicate": "founded_year",
      "object": "2003",
      "object_type": "literal",
      "confidence": 0.95
    },
    {
      "id": "uuid-2",
      "subject": "Tesla",
      "predicate": "headquarters_in",
      "object": "Austin, Texas",
      "object_type": "entity",
      "confidence": 0.95
    }
    // ... more triples
  ],
  "count": 10,
  "provider": "openai",
  "credits_used": 2,
  "balance_remaining": 98
}
```

## With Web Search

Enable web search for real-time information:

```bash theme={null}
curl -X POST "https://neode.ai/api/triples/generate?format=json" \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -d '{
    "query": "What are the latest SpaceX Starship test flight results?",
    "index_id": "YOUR_INDEX_ID",
    "web_search": true,
    "triple_count": 15
  }'
```

<Tip>
  Web search is great for:

  * Current events and news
  * Recent product releases
  * Updated statistics
  * Real-time information
</Tip>

## Streaming vs JSON

### JSON Format (Recommended for APIs)

Returns complete response after generation:

```bash theme={null}
curl -X POST "https://neode.ai/api/triples/generate?format=json" \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -d '{ ... }'
```

### Streaming Format (Default)

Streams results as they're generated (good for UIs):

```bash theme={null}
curl -X POST "https://neode.ai/api/triples/generate" \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -d '{ ... }'
```

## Request Parameters

| Parameter      | Type      | Required | Description                                     |
| -------------- | --------- | -------- | ----------------------------------------------- |
| `query`        | string    | Yes      | Natural language description of what to extract |
| `index_id`     | UUID      | Yes      | Index for entity disambiguation                 |
| `graph_id`     | UUID      | No       | Graph to store triples in                       |
| `web_search`   | boolean   | No       | Enable web search (default: true)               |
| `triple_count` | integer   | No       | Target number of triples (default: 10, max: 50) |
| `predicates`   | string\[] | No       | Restrict to specific predicate types            |

## Controlling Output

### Specify Triple Count

```json theme={null}
{
  "query": "Facts about Elon Musk's companies",
  "index_id": "YOUR_INDEX_ID",
  "triple_count": 20
}
```

### Restrict Predicates

Focus on specific relationship types:

```json theme={null}
{
  "query": "Information about tech companies",
  "index_id": "YOUR_INDEX_ID",
  "predicates": ["founded_by", "headquarters_in", "industry", "founded_year"]
}
```

### Add to a Graph

Store generated triples in a specific graph:

```json theme={null}
{
  "query": "SpaceX Starship specifications",
  "index_id": "YOUR_INDEX_ID",
  "graph_id": "YOUR_GRAPH_ID",
  "triple_count": 10
}
```

## Credits and Pricing

| Operation                     | Credits |
| ----------------------------- | ------- |
| Generation without web search | 2¢      |
| Generation with web search    | 5¢      |

Check your balance:

```bash theme={null}
curl "https://neode.ai/api/credits" \
  -H "Authorization: Bearer YOUR_API_KEY"
```

### Insufficient Credits

When credits are low, you'll receive:

```json theme={null}
{
  "success": false,
  "error": "Insufficient credits",
  "balance_cents": 3,
  "required_cents": 5,
  "buy_credits_url": "https://neode.ai/dashboard/settings/billing"
}
```

## Query Tips

### Be Specific

```json theme={null}
// Good - specific and focused
{
  "query": "Extract financial metrics from Tesla's Q4 2025 earnings report"
}

// Avoid - too broad
{
  "query": "Tell me about Tesla"
}
```

### Provide Context

```json theme={null}
{
  "query": "Key milestones in SpaceX's Starship development program, including test flights and regulatory approvals"
}
```

### Ask for What You Need

```json theme={null}
{
  "query": "Technical specifications of the iPhone 15 Pro including processor, camera, and battery details"
}
```

## Example Use Cases

### Research Assistant

```json theme={null}
{
  "query": "Summarize the key findings from recent studies on GPT-4 capabilities and limitations",
  "web_search": true,
  "triple_count": 15
}
```

### Competitive Intelligence

```json theme={null}
{
  "query": "Compare features and pricing of major cloud providers: AWS, Azure, and Google Cloud",
  "web_search": true,
  "triple_count": 20
}
```

### Knowledge Base Building

```json theme={null}
{
  "query": "Extract biographical information about Nobel Prize winners in Physics from 2020-2025",
  "web_search": true,
  "triple_count": 30
}
```

### News Monitoring

```json theme={null}
{
  "query": "Latest developments in AI regulation and policy in the European Union",
  "web_search": true,
  "triple_count": 10
}
```

## Error Handling

### Rate Limits

If you hit rate limits:

```json theme={null}
{
  "success": false,
  "error": "Rate limit exceeded",
  "retry_after": 60
}
```

### Invalid Requests

```json theme={null}
{
  "success": false,
  "error": "index_id is required"
}
```

<Card title="API Reference" icon="code" href="/api-reference/endpoint/generation/generate">
  See the complete Generation API documentation.
</Card>
