scratch_search_test.py 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. import urllib.request, urllib.parse, json
  2. # First test: exactly what user provided
  3. params1 = urllib.parse.urlencode({
  4. "q": "散景 浅景深 逆光 光斑 背景虚化 轮廓光",
  5. "capability_id": "CAP-001",
  6. "types": "strategy,case,tool",
  7. "top_k": 10,
  8. "min_score": 3
  9. })
  10. try:
  11. req1 = urllib.request.Request(f'http://localhost:8000/api/knowledge/search?{params1}')
  12. with urllib.request.urlopen(req1) as f:
  13. print('Search 1 (all types): count =', json.loads(f.read().decode('utf-8')).get('count', 0))
  14. except Exception as e:
  15. print('Search 1 error:', e)
  16. # Second test: only one type
  17. params2 = urllib.parse.urlencode({
  18. "q": "散景 浅景深 逆光 光斑 背景虚化 轮廓光",
  19. "capability_id": "CAP-001",
  20. "types": "case",
  21. "top_k": 10,
  22. "min_score": 3
  23. })
  24. try:
  25. req2 = urllib.request.Request(f'http://localhost:8000/api/knowledge/search?{params2}')
  26. with urllib.request.urlopen(req2) as f:
  27. print('Search 2 (single type case): count =', json.loads(f.read().decode('utf-8')).get('count', 0))
  28. except Exception as e:
  29. print('Search 2 error:', e)
  30. # Third test: no types filter
  31. params3 = urllib.parse.urlencode({
  32. "q": "散景 浅景深 逆光 光斑 背景虚化 轮廓光",
  33. "capability_id": "CAP-001",
  34. "top_k": 10,
  35. "min_score": 3
  36. })
  37. try:
  38. req3 = urllib.request.Request(f'http://localhost:8000/api/knowledge/search?{params3}')
  39. with urllib.request.urlopen(req3) as f:
  40. print('Search 3 (no types filter): count =', json.loads(f.read().decode('utf-8')).get('count', 0))
  41. except Exception as e:
  42. print('Search 3 error:', e)