Skip to main content

Knowledge Graph API

The Knowledge Graph API provides endpoints for retrieving and managing the knowledge graph structure, including entities, relationships, and graph visualization data.

Quick Start

import requests

# No authentication needed!
response = requests.get("https://vedaya-kge.fly.dev/graph/label/list")
labels = response.json()
print(f"Available labels: {labels}")

# Get knowledge graph for a specific label
response = requests.get(
    "https://vedaya-kge.fly.dev/graphs",
    params={"label": "machine_learning", "max_depth": 2}
)
graph_data = response.json()

Get Graph Labels

Get all available graph labels in the knowledge graph.

Response

Returns a list of all graph labels as an array of strings.
curl -X GET "https://vedaya-kge.fly.dev/graph/label/list"
[
  "machine_learning",
  "neural_network",
  "artificial_intelligence",
  "deep_learning",
  "data_science",
  "computer_vision",
  "natural_language_processing"
]

Get Knowledge Graph

Retrieve a connected subgraph of nodes where the label includes the specified label.

Query Parameters

label
string
required
Label to get knowledge graph for
max_depth
integer
default:"3"
Maximum depth of graph traversal (min: 1)
max_nodes
integer
default:"1000"
Maximum nodes to return (min: 1)

Response

Returns a knowledge graph for the specified label. When reducing the number of nodes, prioritization is based on:
  1. Hops (path) to the starting node take precedence
  2. Followed by the degree of the nodes
curl -X GET "https://vedaya-kge.fly.dev/graphs?label=machine_learning&max_depth=2&max_nodes=100"
{
  "nodes": [
    {
      "id": "machine_learning",
      "label": "Machine Learning",
      "properties": {
        "type": "concept",
        "importance": "high"
      }
    },
    {
      "id": "neural_network",
      "label": "Neural Network",
      "properties": {
        "type": "technology"
      }
    }
  ],
  "edges": [
    {
      "source": "machine_learning",
      "target": "neural_network",
      "relationship": "includes",
      "weight": 0.9
    }
  ]
}

Check Entity Exists

Check if an entity with the given name exists in the knowledge graph.

Query Parameters

name
string
required
Entity name to check

Response

Returns a dictionary with an ‘exists’ key indicating if the entity exists.
{
  "exists": true
}
curl -X GET "https://vedaya-kge.fly.dev/graph/entity/exists?name=neural_network"
{
  "exists": true
}

Update Entity

Update an entity’s properties in the knowledge graph.

Request Body

entity_name
string
required
Name of the entity to update
updated_data
object
required
Updated properties for the entity
allow_rename
boolean
default:"false"
Whether to allow renaming the entity

Response

Returns the updated entity information.
curl -X POST "https://vedaya-kge.fly.dev/graph/entity/edit" \
  -H "Content-Type: application/json" \
  -d '{
    "entity_name": "machine_learning",
    "updated_data": {
      "description": "Advanced pattern recognition techniques",
      "category": "AI Technology",
      "importance": "high"
    },
    "allow_rename": false
  }'
{
  "entity_name": "machine_learning",
  "updated": true,
  "properties": {
    "description": "Advanced pattern recognition techniques",
    "category": "AI Technology",
    "importance": "high"
  }
}

Update Relation

Update a relation’s properties in the knowledge graph.

Request Body

source_id
string
required
ID of the source entity
target_id
string
required
ID of the target entity
updated_data
object
required
Updated properties for the relation

Response

Returns the updated relation information.
curl -X POST "https://vedaya-kge.fly.dev/graph/relation/edit" \
  -H "Content-Type: application/json" \
  -d '{
    "source_id": "entity_123",
    "target_id": "entity_456",
    "updated_data": {
      "relationship_type": "influences",
      "strength": 0.8,
      "confidence": 0.95
    }
  }'
{
  "source_id": "entity_123",
  "target_id": "entity_456",
  "updated": true,
  "properties": {
    "relationship_type": "influences",
    "strength": 0.8,
    "confidence": 0.95
  }
}

Complete Knowledge Graph Workflow

Here’s how to work with the knowledge graph after uploading documents:
import requests
import time
from openai import OpenAI

# 1. Upload documents (creates knowledge graph automatically)
docs = ["Document about AI and machine learning..."]
requests.post(
    "https://vedaya-kge.fly.dev/documents/texts",
    json={"texts": docs}
)

# 2. Wait for processing
time.sleep(5)

# 3. Explore the knowledge graph
labels = requests.get("https://vedaya-kge.fly.dev/graph/label/list").json()
print(f"Discovered entities: {labels[:10]}")

# 4. Get graph for specific concept
graph = requests.get(
    "https://vedaya-kge.fly.dev/graphs",
    params={"label": labels[0], "max_depth": 2}
).json()

# 5. Query using graph-aware RAG
client = OpenAI(api_key="sk-dummy", base_url="https://vedaya-kge.fly.dev/v1")
response = client.chat.completions.create(
    model="vedaya-global",  # Use global mode for relationship queries
    messages=[{"role": "user", "content": f"What is related to {labels[0]}?"}]
)
print(response.choices[0].message.content)

Knowledge Graph RAG Modes

Different RAG modes leverage the knowledge graph differently:
ModeModel NameGraph Usage
Naivevedaya-naiveNo graph usage, keyword only
Localvedaya-localEntity-focused retrieval
Globalvedaya-globalRelationship traversal
Hybridvedaya-hybridCombined approach
Use vedaya-global for best results when querying relationships and connections in the knowledge graph.