-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_rag_em_api.py
More file actions
92 lines (77 loc) · 2.49 KB
/
test_rag_em_api.py
File metadata and controls
92 lines (77 loc) · 2.49 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
"""
Test RAG EM API endpoints after adding deleteDocument and purgeNamespace.
Usage:
python test_rag_em_api.py
"""
import os
import requests
import json
REDCAP_API_URL = os.getenv("REDCAP_API_URL", "http://localhost/api/")
REDCAP_API_TOKEN = os.getenv("REDCAP_API_TOKEN")
if not REDCAP_API_TOKEN:
print("❌ ERROR: Set REDCAP_API_TOKEN environment variable")
exit(1)
print("Testing RAG EM API endpoints...")
print("=" * 60)
# Test 1: Store a document (should return vector_id now)
print("\n1️⃣ Testing storeDocument (should return vector_id)...")
response = requests.post(REDCAP_API_URL, data={
"token": REDCAP_API_TOKEN,
"content": "externalModule",
"prefix": "redcap_rag",
"action": "storeDocument",
"format": "json",
"returnFormat": "json",
"title": "test_document_123",
"text": "This is test content for automated ingestion"
})
result = response.json()
print(json.dumps(result, indent=2))
vector_id = result.get("vector_id")
if vector_id:
print(f"✅ storeDocument returned vector_id: {vector_id}")
else:
print("❌ storeDocument did NOT return vector_id")
exit(1)
# Test 2: Delete the document
print("\n2️⃣ Testing deleteDocument...")
response = requests.post(REDCAP_API_URL, data={
"token": REDCAP_API_TOKEN,
"content": "externalModule",
"prefix": "redcap_rag",
"action": "deleteDocument",
"format": "json",
"returnFormat": "json",
"vector_id": vector_id
})
result = response.json()
print(json.dumps(result, indent=2))
if result.get("status") == "success":
print("✅ deleteDocument succeeded")
else:
print("❌ deleteDocument failed")
exit(1)
# Test 3: Purge namespace (optional - for testing)
print("\n3️⃣ Testing purgeNamespace (with confirmation)...")
response = requests.post(REDCAP_API_URL, data={
"token": REDCAP_API_TOKEN,
"content": "externalModule",
"prefix": "redcap_rag",
"action": "purgeNamespace",
"format": "json",
"returnFormat": "json",
"confirm": "yes"
})
result = response.json()
print(json.dumps(result, indent=2))
if result.get("status") == "success":
print("✅ purgeNamespace succeeded")
else:
print("⚠️ purgeNamespace may have failed (check if namespace was already empty)")
print("\n" + "=" * 60)
print("✅ All RAG EM API tests completed!")
print("")
print("Your RAG EM now supports:")
print(" - storeDocument (with vector_id in response)")
print(" - deleteDocument (deletes from dense + sparse)")
print(" - purgeNamespace (useful for testing)")