File size: 2,372 Bytes
ca41776
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
673a52e
ca41776
 
 
 
 
 
673a52e
ca41776
 
 
 
 
 
 
 
673a52e
ca41776
 
 
 
 
 
 
 
 
673a52e
ca41776
 
 
 
 
 
673a52e
ca41776
 
673a52e
ca41776
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
673a52e
ca41776
 
 
 
 
 
 
 
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
#!/usr/bin/env python3
"""Test the Enhanced Search API endpoint."""
import requests
import json
import time

BASE_URL = "http://localhost:8000"

def test_health():
    """Test health endpoint."""
    r = requests.get(f"{BASE_URL}/health")
    print(f"Health: {r.status_code}")
    return r.status_code == 200

def test_enhanced_search():
    """Test enhanced search endpoint."""
    data = {
        "query": "BRCA1 breast cancer",
        "top_k": 3,
        "use_mmr": True,
    }
    print(f"\n[TEST] /api/search with: {data}")
    
    r = requests.post(f"{BASE_URL}/api/search", json=data)
    print(f"Status: {r.status_code}")
    
    if r.status_code == 200:
        result = r.json()
        print(f"[OK] Results: {result.get('returned')} of {result.get('total_found')}")
        print(f"   Diversity: {result.get('diversity_score'):.4f}")
        print(f"   Search time: {result.get('search_time_ms'):.1f}ms")
        
        for item in result.get('results', [])[:3]:
            content = item.get('content', '')[:60]
            print(f"   [{item.get('rank')}] score={item.get('score'):.3f} - {content}...")
        return True
    else:
        print(f"[ERROR] {r.text}")
        return False

def test_hybrid_search():
    """Test hybrid search endpoint."""
    data = {
        "query": "kinase inhibitor",
        "keywords": ["cancer", "therapy"],
        "top_k": 3,
    }
    print(f"\n[TEST] /api/search/hybrid with: {data}")
    
    r = requests.post(f"{BASE_URL}/api/search/hybrid", json=data)
    print(f"Status: {r.status_code}")
    
    if r.status_code == 200:
        result = r.json()
        print(f"[OK] Results: {result.get('returned')} of {result.get('total_found')}")
        return True
    else:
        print(f"[ERROR] {r.text}")
        return False

if __name__ == "__main__":
    print("=" * 50)
    print("BioFlow Enhanced Search API Test")
    print("=" * 50)
    
    # Wait for server to be ready
    for i in range(10):
        try:
            if test_health():
                break
        except requests.exceptions.ConnectionError:
            print(f"Waiting for server... ({i+1}/10)")
            time.sleep(1)
    else:
        print("[ERROR] Server not available")
        exit(1)
    
    # Run tests
    test_enhanced_search()
    test_hybrid_search()
    
    print("\n" + "=" * 50)
    print("Tests complete!")