Files
railseek6/test_rerank_detailed.py
2026-01-13 09:51:35 +08:00

107 lines
3.4 KiB
Python

import requests
import json
import time
# Test query with enable_rerank=True
url = "http://localhost:3015/query"
headers = {
"Content-Type": "application/json",
"X-API-Key": "jleu1212"
}
# First, let's check the server config
print("Checking server configuration...")
try:
config_response = requests.get("http://localhost:3015/config", headers={"X-API-Key": "jleu1212"})
if config_response.status_code == 200:
config = config_response.json()
print(f"Rerank binding: {config.get('rerank_binding', 'NOT FOUND')}")
print(f"Rerank model: {config.get('rerank_model', 'NOT FOUND')}")
print(f"Enable rerank: {config.get('enable_rerank', 'NOT FOUND')}")
print(f"Min rerank score: {config.get('min_rerank_score', 'NOT FOUND')}")
except Exception as e:
print(f"Error getting config: {e}")
print("\n" + "="*50)
print("Testing query with enable_rerank=True...")
data_with_rerank = {
"query": "test query about safety distances",
"enable_rerank": True,
"only_need_context": True
}
try:
start_time = time.time()
response = requests.post(url, headers=headers, json=data_with_rerank, timeout=30)
elapsed = time.time() - start_time
print(f"Status Code: {response.status_code}")
print(f"Response time: {elapsed:.2f}s")
if response.status_code == 200:
result = response.json()
response_text = result.get('response', '')
# Check if there's a warning about rerank
if "Rerank is enabled but no rerank model is configured" in response_text:
print("✓ Found warning: Rerank is enabled but no rerank model is configured")
print(" This confirms that ticking the checkbox enables rerank BUT it won't work without configuration")
else:
print("✗ No rerank warning found in response")
# Check response length
print(f"Response length: {len(response_text)} chars")
except Exception as e:
print(f"Error: {e}")
print("\n" + "="*50)
print("Testing query with enable_rerank=False...")
data_without_rerank = {
"query": "test query about safety distances",
"enable_rerank": False,
"only_need_context": True
}
try:
start_time = time.time()
response = requests.post(url, headers=headers, json=data_without_rerank, timeout=30)
elapsed = time.time() - start_time
print(f"Status Code: {response.status_code}")
print(f"Response time: {elapsed:.2f}s")
if response.status_code == 200:
result = response.json()
response_text = result.get('response', '')
print(f"Response length: {len(response_text)} chars")
except Exception as e:
print(f"Error: {e}")
print("\n" + "="*50)
print("Testing query with enable_rerank=None (default)...")
data_default = {
"query": "test query about safety distances",
"only_need_context": True
# enable_rerank not specified - should use default
}
try:
start_time = time.time()
response = requests.post(url, headers=headers, json=data_default, timeout=30)
elapsed = time.time() - start_time
print(f"Status Code: {response.status_code}")
print(f"Response time: {elapsed:.2f}s")
if response.status_code == 200:
result = response.json()
response_text = result.get('response', '')
print(f"Response length: {len(response_text)} chars")
except Exception as e:
print(f"Error: {e}")