File size: 1,650 Bytes
7b374c9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import requests
import json

BASE_URL = "http://localhost:8000"

def search(query, filters=None):
    payload = {
        "query": query,
        "filters": filters or {},
        "top_k": 5,
        "use_reranking": False,
        "use_explanations": False
    }
    try:
        response = requests.post(f"{BASE_URL}/search/text", json=payload)
        response.raise_for_status()
        return response.json()
    except Exception as e:
        print(f"Error: {e}")
        return None

def run_tests():
    print("=== Test 1: Filter Only (Emerald) ===")
    res1 = search("", {"primary_stone": "Emerald"})
    if res1 and res1["results"]:
        print(f"Success. Found {len(res1['results'])} items.")
        print(f"Sample: {res1['results'][0]['metadata'].get('primary_stone')}")
    else:
        print("Failed. No results or error.")

    print("\n=== Test 2: Filter (Gold) + Query (Necklace) ===")
    res2 = search("necklace", {"metal": "Gold"})
    if res2 and res2["results"]:
        print(f"Success. Found {len(res2['results'])} items.")
        print(f"Sample Metal: {res2['results'][0]['metadata'].get('metal')}")
        print(f"Sample Category: {res2['results'][0]['metadata'].get('category')}")
    else:
        print("Failed. No results.")

    print("\n=== Test 3: Filter (Ring) + Query (Blue) ===")
    res3 = search("blue", {"category": "Ring"})
    if res3 and res3["results"]:
        print(f"Success. Found {len(res3['results'])} items.")
        print(f"Sample Category: {res3['results'][0]['metadata'].get('category')}")
    else:
        print("Failed. No results.")
        
if __name__ == "__main__":
    run_tests()