-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrank.sh
More file actions
executable file
·62 lines (50 loc) · 1.69 KB
/
rank.sh
File metadata and controls
executable file
·62 lines (50 loc) · 1.69 KB
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
#!/bin/bash
# Test Schema Ranker with full schema support
# Usage:
# ./test_schema_ranker.sh "query" "table1,table2,table3"
# ./test_schema_ranker.sh "query" "table1|table2|table3" (use | for full schemas)
set -e
cd "$(dirname "${BASH_SOURCE[0]}")"
if [ -z "$1" ]; then
echo "Usage: ./test_schema_ranker.sh \"query\" \"table1,table2,table3\""
echo ""
echo "Examples:"
echo " # Simple table names:"
echo " ./test_schema_ranker.sh \"Find customer orders\" \"customers,orders,products,logs\""
echo ""
echo " # Full schemas (use | separator):"
echo " ./test_schema_ranker.sh \"Find customer orders\" \"customers (id, name, email)|orders (id, customer_id, total)|products (id, name, price)\""
exit 1
fi
source venv/bin/activate
QUERY="$1"
TABLES="$2"
# Detect separator
if [[ "$TABLES" == *"|"* ]]; then
SEPARATOR="|"
else
SEPARATOR=","
fi
python3 << EOF
from sentence_transformers import SentenceTransformer
from sentence_transformers.util import cos_sim
# Load model
model = SentenceTransformer('models/schema_ranker/schema_ranker_model')
query = """$QUERY"""
tables_str = """$TABLES"""
separator = """$SEPARATOR"""
tables = [t.strip() for t in tables_str.split(separator) if t.strip()]
# Rank
query_emb = model.encode(query)
table_embs = model.encode(tables)
scores = cos_sim(query_emb, table_embs)[0].tolist()
ranked = sorted(zip(tables, scores), key=lambda x: -x[1])
print(f'Query: "{query}"')
print()
print('Ranked schema elements:')
for name, score in ranked:
# Truncate long names for display
display_name = name[:40] + "..." if len(name) > 40 else name
bar = '█' * max(0, int(score * 20))
print(f' {display_name:45s} {score:.3f} {bar}')
EOF