The Vedaya API automatically builds a knowledge graph from your documents. These endpoints allow you to explore and modify the graph structure.

Setup

import requests

# Base URL
BASE_URL = "https://vedaya-kge.fly.dev"

# Authentication
headers = {"Content-Type": "application/json"}
# If you have an API key:
# headers["Authorization"] = f"Bearer {API_KEY}"

Get Graph Labels

Retrieve all entity labels in the graph:
url = f"{BASE_URL}/graph/label/list"
response = requests.get(url)

if response.status_code == 200:
    labels = response.json()
    print(f"Found {len(labels)} entities")
    # Returns: ["machine_learning", "neural_network", "data_science", ...]

Get Knowledge Graph

Retrieve subgraph for a specific entity:
url = f"{BASE_URL}/graphs"

params = {
    "label": "machine_learning",  # Starting entity
    "max_depth": 3,               # Graph traversal depth
    "max_nodes": 100              # Maximum nodes to return
}

response = requests.get(url, params=params)

if response.status_code == 200:
    graph_data = response.json()
    # Returns graph structure with nodes and edges
    print(f"Nodes: {len(graph_data.get('nodes', []))}")
    print(f"Edges: {len(graph_data.get('edges', []))}")

Check Entity Exists

url = f"{BASE_URL}/graph/entity/exists"

params = {"name": "neural_network"}
response = requests.get(url, params=params)

if response.status_code == 200:
    result = response.json()
    if result.get("exists"):
        print("✅ Entity found in graph")
    else:
        print("❌ Entity not found")

Update Entity

url = f"{BASE_URL}/graph/entity/edit"

payload = {
    "entity_name": "machine_learning",
    "updated_data": {
        "description": "A subset of artificial intelligence...",
        "category": "AI Technology",
        "importance": "high"
    },
    "allow_rename": False
}

response = requests.post(
    url, 
    headers={"Content-Type": "application/json"},
    json=payload
)

if response.status_code == 200:
    print("✅ Entity updated successfully")

Update Relationship

url = f"{BASE_URL}/graph/relation/edit"

payload = {
    "source_id": "entity_123",
    "target_id": "entity_456",
    "updated_data": {
        "relationship_type": "prerequisite",
        "strength": 0.9,
        "bidirectional": False
    }
}

response = requests.post(
    url,
    headers={"Content-Type": "application/json"},
    json=payload
)

if response.status_code == 200:
    print("✅ Relationship updated successfully")

Complete Example: Explore Graph After Upload

import requests
import time
from openai import OpenAI

# 1. Upload documents
documents = [
    "Machine learning is a subset of artificial intelligence.",
    "Neural networks are used in deep learning.",
    "Deep learning requires large amounts of data."
]

response = requests.post(
    "https://vedaya-kge.fly.dev/documents/texts",
    json={"texts": documents}
)

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

# 3. Explore the generated graph
labels = requests.get(
    "https://vedaya-kge.fly.dev/graph/label/list"
).json()

print(f"Entities found: {labels}")

# 4. Get subgraph for an entity
if labels:
    graph = requests.get(
        "https://vedaya-kge.fly.dev/graphs",
        params={"label": labels[0], "max_depth": 2}
    ).json()
    print(f"Graph for '{labels[0]}': {len(graph.get('nodes', []))} nodes")

# 5. Query using graph-enhanced 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 graph relationships
    messages=[{"role": "user", "content": "How are the concepts related?"}]
)
print(response.choices[0].message.content)

Graph-Enhanced RAG Modes

Different models leverage the knowledge graph differently:
ModelGraph Usage
vedaya-naiveNo graph usage, keyword only
vedaya-localEntity recognition from graph
vedaya-globalFull graph relationships
vedaya-hybridCombined approach

Important Notes

  • Authentication optional - All endpoints work without authentication
  • Auto-generated - Graph is built automatically during document processing
  • Dynamic updates - Graph evolves as you add more documents
  • Query integration - Graph enhances RAG query responses