forked from raphaelmansuy/edgequake
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbasic_usage.py
More file actions
54 lines (43 loc) · 1.46 KB
/
basic_usage.py
File metadata and controls
54 lines (43 loc) · 1.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#!/usr/bin/env python3
"""
Basic Usage — EdgeQuake Python SDK
WHY: Demonstrates the simplest possible setup — create a client,
check health, and run a basic query. Start here if you're new.
Requirements:
- EdgeQuake server running on http://localhost:8080
- EDGEQUAKE_API_KEY environment variable set
Usage:
export EDGEQUAKE_API_KEY="demo-key"
python examples/basic_usage.py
"""
import os
from edgequake import EdgequakeClient
def main():
# WHY: base_url points to your EdgeQuake backend; api_key authenticates.
client = EdgequakeClient(
api_key=os.environ.get("EDGEQUAKE_API_KEY", "demo-key"),
base_url=os.environ.get("EDGEQUAKE_URL", "http://localhost:8080"),
)
# 1. Health check — verify the API is reachable
health = client.health()
print(f"Health: {health}")
# 2. Upload a simple text document
doc = client.documents.upload(
content=(
"EdgeQuake is a graph-based RAG framework written in Rust. "
"It uses knowledge graphs to enhance retrieval-augmented generation."
),
title="EdgeQuake Overview",
)
print(f"Uploaded document: {doc['document_id']}")
# 3. Query the knowledge base
result = client.query.execute(
query="What is EdgeQuake?",
mode="hybrid",
)
print(f"Answer: {result['answer']}")
# 4. Explore the graph
graph = client.graph.get()
print(f"Graph stats: {graph}")
if __name__ == "__main__":
main()