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)