-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_packer_full.py
More file actions
executable file
·152 lines (126 loc) · 4.82 KB
/
test_packer_full.py
File metadata and controls
executable file
·152 lines (126 loc) · 4.82 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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
#!/usr/bin/env python3
"""
Full test client for Cognee API - Complete packer workflow
Adds, cognifies, and searches with multiple queries
"""
import asyncio
import sys
from pathlib import Path
from client import CogneeClient, SearchType
async def main():
# Configuration
COGNEE_URL = "http://eva_cognee:8181"
PACKER_DOC_PATH = "/home/steve/DevOps/workspaces/DesconSimGui/docs/packer.md"
DATASET_NAME = "DesconSim_Packer"
print("=" * 80)
print("Cognee API Test - Full Packer Documentation Workflow")
print("=" * 80)
print()
# Read the document
print("[1/7] Reading packer.md document...")
try:
packer_doc_path = Path(PACKER_DOC_PATH)
if not packer_doc_path.exists():
print(f"ERROR: File not found: {PACKER_DOC_PATH}")
return 1
packer_content = packer_doc_path.read_text()
print(f"✓ Document loaded ({len(packer_content)} characters)")
print()
except Exception as e:
print(f"ERROR: Failed to read document: {e}")
return 1
# Initialize client
print(f"[2/7] Connecting to Cognee API at {COGNEE_URL}...")
client = CogneeClient(base_url=COGNEE_URL, timeout=1800.0)
print("✓ Client initialized (30 minute timeout)")
print()
try:
# Health check
print("[3/7] Checking server health...")
health_result = await client.health()
print(f"✓ Server is healthy: {health_result}")
print()
# Prune the old dataset first to start fresh
print("[4/7] Pruning old data (starting fresh)...")
try:
prune_result = await client.prune()
print(f"✓ Old data pruned: {prune_result.get('message')}")
except Exception as e:
print(f"Note: Prune may have failed (this is ok): {e}")
print()
# Add document
print(f"[5/7] Adding packer.md to dataset '{DATASET_NAME}'...")
print(f" This may take several minutes...")
add_result = await client.add(
text=packer_content,
dataset_name=DATASET_NAME
)
if add_result.get("success"):
print(f"✓ Document added successfully")
else:
print(f"ERROR: Failed to add document: {add_result}")
return 1
print()
# Cognify
print(f"[6/7] Building knowledge graph...")
print(f" This may take several minutes...")
cognify_result = await client.cognify(datasets=[DATASET_NAME])
if cognify_result.get("success"):
print(f"✓ Knowledge graph built successfully")
else:
print(f"ERROR: Failed to cognify: {cognify_result}")
return 1
print()
# Multiple searches with different queries
print("[7/7] Performing searches...")
print()
queries = [
("What is priming and downstream control in the packer?", SearchType.CHUNKS),
("Explain the packer speed control system", SearchType.SUMMARIES),
("How does the virtual conveyor work?", SearchType.GRAPH_COMPLETION),
("What are the packer configuration properties?", SearchType.CHUNKS_LEXICAL)
]
for i, (query, search_type) in enumerate(queries, 1):
print("=" * 80)
print(f"SEARCH {i}/{len(queries)}: '{query}'")
print(f" Search Type: {search_type.value}")
print("=" * 80)
try:
search_result = await client.search(
query_text=query,
query_type=search_type
)
if search_result.get("success"):
search_data = search_result.get("data", [])
if isinstance(search_data, list):
if len(search_data) == 0 or (len(search_data) == 1 and not search_data[0]):
print(" No results returned")
else:
for j, item in enumerate(search_data, 1):
if item: # Only print non-empty results
print(f" Result {j}:")
print(f" {item}")
else:
print(f" {search_data}")
else:
print(f" Search failed: {search_result}")
except Exception as e:
print(f" ERROR: {e}")
print()
except Exception as e:
print(f"ERROR: Operation failed: {e}")
import traceback
traceback.print_exc()
return 1
finally:
await client.close()
print()
print("✓ Client connection closed")
print()
print("=" * 80)
print("Test completed!")
print("=" * 80)
return 0
if __name__ == "__main__":
exit_code = asyncio.run(main())
sys.exit(exit_code)