| #!/bin/bash |
|
|
| |
| |
|
|
| echo "🚀 LightRAG aquery_data Endpoint Test (New Data Format Validation)" |
| echo "==================================================" |
|
|
| |
| BASE_URL="http://localhost:9621" |
|
|
| |
| RED='\033[0;31m' |
| GREEN='\033[0;32m' |
| YELLOW='\033[1;33m' |
| BLUE='\033[0;34m' |
| NC='\033[0m' |
|
|
| |
| TOTAL_TESTS=0 |
| PASSED_TESTS=0 |
| FAILED_TESTS=0 |
|
|
| |
| validate_success_response() { |
| local response="$1" |
| local test_name="$2" |
| local expected_mode="$3" |
|
|
| echo -e "${BLUE}Validating $test_name response format...${NC}" |
|
|
| |
| if ! echo "$response" | jq . >/dev/null 2>&1; then |
| echo -e "${RED}❌ Response is not valid JSON format${NC}" |
| return 1 |
| fi |
|
|
| |
| local status=$(echo "$response" | jq -r '.status // "missing"') |
| local message=$(echo "$response" | jq -r '.message // "missing"') |
| local data_exists=$(echo "$response" | jq 'has("data")') |
| local metadata_exists=$(echo "$response" | jq 'has("metadata")') |
|
|
| echo " Status: $status" |
| echo " Message: $message" |
|
|
| |
| if [[ "$data_exists" == "true" ]]; then |
| local entities_count=$(echo "$response" | jq '.data.entities | length // 0') |
| local relationships_count=$(echo "$response" | jq '.data.relationships | length // 0') |
| local chunks_count=$(echo "$response" | jq '.data.chunks | length // 0') |
| local references_count=$(echo "$response" | jq '.data.references | length // 0') |
|
|
| echo " Data.entities: $entities_count" |
| echo " Data.relationships: $relationships_count" |
| echo " Data.chunks: $chunks_count" |
| echo " Data.references: $references_count" |
| else |
| echo -e "${RED} ❌ Missing 'data' field${NC}" |
| return 1 |
| fi |
|
|
| |
| if [[ "$metadata_exists" == "true" ]]; then |
| local query_mode=$(echo "$response" | jq -r '.metadata.query_mode // "missing"') |
| local keywords_exists=$(echo "$response" | jq 'has("metadata") and (.metadata | has("keywords"))') |
| local processing_info_exists=$(echo "$response" | jq 'has("metadata") and (.metadata | has("processing_info"))') |
|
|
| echo " Metadata.query_mode: $query_mode" |
| echo " Metadata.keywords: $keywords_exists" |
| echo " Metadata.processing_info: $processing_info_exists" |
|
|
| |
| if [[ "$expected_mode" != "" && "$query_mode" != "$expected_mode" ]]; then |
| echo -e "${YELLOW} ⚠️ Query mode mismatch: expected '$expected_mode', actual '$query_mode'${NC}" |
| fi |
| else |
| echo -e "${RED} ❌ Missing 'metadata' field${NC}" |
| return 1 |
| fi |
|
|
| |
| if [[ "$status" == "success" ]]; then |
| echo -e "${GREEN} ✅ Response format validation passed${NC}" |
| return 0 |
| else |
| echo -e "${RED} ❌ Status is not 'success': $status${NC}" |
| return 1 |
| fi |
| } |
|
|
| |
| validate_error_response() { |
| local response="$1" |
| local test_name="$2" |
|
|
| echo -e "${BLUE}Validating $test_name response format...${NC}" |
|
|
| |
| if ! echo "$response" | jq . >/dev/null 2>&1; then |
| echo -e "${RED}❌ Response is not valid JSON format${NC}" |
| return 1 |
| fi |
|
|
| |
| local status=$(echo "$response" | jq -r '.status // "missing"') |
| local message=$(echo "$response" | jq -r '.message // "missing"') |
| local data_exists=$(echo "$response" | jq 'has("data")') |
| local metadata_exists=$(echo "$response" | jq 'has("metadata")') |
|
|
| echo " Status: $status" |
| echo " Message: $message" |
|
|
| |
| if [[ "$data_exists" != "true" ]]; then |
| echo -e "${RED} ❌ Missing 'data' field${NC}" |
| return 1 |
| fi |
|
|
| if [[ "$metadata_exists" != "true" ]]; then |
| echo -e "${RED} ❌ Missing 'metadata' field${NC}" |
| return 1 |
| fi |
|
|
| echo " Data: {}" |
| echo " Metadata: {}" |
|
|
| |
| if [[ "$status" == "failure" ]]; then |
| echo -e "${GREEN} ✅ Error response format validation passed${NC}" |
| return 0 |
| else |
| echo -e "${RED} ❌ Status is not 'failure': $status${NC}" |
| return 1 |
| fi |
| } |
|
|
| |
| run_success_test() { |
| local test_name="$1" |
| local query_data="$2" |
| local expected_mode="$3" |
| local print_json="${4:-false}" |
|
|
| echo "" |
| echo "==================================" |
| echo -e "${BLUE}$test_name${NC}" |
| echo "==================================" |
|
|
| TOTAL_TESTS=$((TOTAL_TESTS + 1)) |
|
|
| |
| echo "Sending request..." |
| local response=$(curl -s -X POST "${BASE_URL}/query/data" \ |
| -H "Content-Type: application/json" \ |
| -H "X-API-Key: your-secure-api-key-here-123" \ |
| -d "$query_data") |
|
|
| |
| if [[ $? -ne 0 ]]; then |
| echo -e "${RED}❌ Request failed - cannot connect to server${NC}" |
| FAILED_TESTS=$((FAILED_TESTS + 1)) |
| return 1 |
| fi |
|
|
| |
| if [[ "$print_json" == "true" ]]; then |
| echo "" |
| echo "Response JSON:" |
| echo "$response" | jq '.' 2>/dev/null || echo "$response" |
| echo "" |
| fi |
|
|
| |
| if validate_success_response "$response" "$test_name" "$expected_mode"; then |
| PASSED_TESTS=$((PASSED_TESTS + 1)) |
| echo -e "${GREEN}✅ $test_name test passed${NC}" |
| else |
| FAILED_TESTS=$((FAILED_TESTS + 1)) |
| echo -e "${RED}❌ $test_name test failed${NC}" |
| echo "Raw response:" |
| echo "$response" | jq '.' 2>/dev/null || echo "$response" |
| fi |
| } |
|
|
| |
| run_error_test() { |
| local test_name="$1" |
| local query_data="$2" |
|
|
| echo "" |
| echo "==================================" |
| echo -e "${BLUE}$test_name${NC}" |
| echo "==================================" |
|
|
| TOTAL_TESTS=$((TOTAL_TESTS + 1)) |
|
|
| |
| echo "Sending request..." |
| local response=$(curl -s -X POST "${BASE_URL}/query/data" \ |
| -H "Content-Type: application/json" \ |
| -H "X-API-Key: your-secure-api-key-here-123" \ |
| -d "$query_data") |
|
|
| |
| if [[ $? -ne 0 ]]; then |
| echo -e "${RED}❌ Request failed - cannot connect to server${NC}" |
| FAILED_TESTS=$((FAILED_TESTS + 1)) |
| return 1 |
| fi |
|
|
| |
| if validate_error_response "$response" "$test_name"; then |
| PASSED_TESTS=$((PASSED_TESTS + 1)) |
| echo -e "${GREEN}✅ $test_name test passed${NC}" |
| else |
| FAILED_TESTS=$((FAILED_TESTS + 1)) |
| echo -e "${RED}❌ $test_name test failed${NC}" |
| echo "Raw response:" |
| echo "$response" | jq '.' 2>/dev/null || echo "$response" |
| fi |
| } |
|
|
| |
| echo "Starting tests for new /query/data endpoint data format..." |
| echo "" |
|
|
| |
| run_success_test "1. Basic Query Test (mix mode)" '{ |
| "query": "What is GraphRAG", |
| "mode": "mix", |
| "top_k": 5 |
| }' "mix" "true" |
|
|
| |
| run_success_test "2. Detailed Parameter Query Test (hybrid mode)" '{ |
| "query": "What is GraphRAG", |
| "mode": "hybrid", |
| "top_k": 5, |
| "chunk_top_k": 8, |
| "max_entity_tokens": 4000, |
| "max_relation_tokens": 4000, |
| "max_total_tokens": 16000, |
| "enable_rerank": true, |
| "response_type": "Multiple Paragraphs" |
| }' "hybrid" |
|
|
| |
| echo "" |
| echo "==================================================" |
| echo -e "${BLUE}Test Result Statistics${NC}" |
| echo "==================================================" |
| echo -e "Total tests: ${BLUE}$TOTAL_TESTS${NC}" |
| echo -e "Passed tests: ${GREEN}$PASSED_TESTS${NC}" |
| echo -e "Failed tests: ${RED}$FAILED_TESTS${NC}" |
|
|
| if [[ $FAILED_TESTS -eq 0 ]]; then |
| echo -e "${GREEN}🎉 All tests passed! New data format adaptation successful!${NC}" |
| exit 0 |
| else |
| echo -e "${RED}⚠️ $FAILED_TESTS test(s) failed, please check the issues${NC}" |
| exit 1 |
| fi |
|
|
| echo "" |
| echo "💡 Usage Instructions:" |
| echo "1. Ensure LightRAG API service is running (python -m lightrag.api.lightrag_server)" |
| echo "2. Adjust BASE_URL as needed" |
| echo "3. If authentication is required, add -H \"Authorization: Bearer your-token\"" |
| echo "4. Install jq for better JSON formatting output: brew install jq (macOS) or apt install jq (Ubuntu)" |
| echo "5. Script will automatically validate new data format structure: status, message, data, metadata" |
|
|