-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathsample_v2.qql
More file actions
124 lines (109 loc) · 3.53 KB
/
sample_v2.qql
File metadata and controls
124 lines (109 loc) · 3.53 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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
-- QQL sample v2
-- Compact end-to-end showcase for deterministic inserts, search, query-time
-- params, recommendation, and hybrid retrieval.
SHOW COLLECTIONS
-- Dense collection
CREATE COLLECTION qql_sample_v2
INSERT BULK INTO COLLECTION qql_sample_v2 VALUES [
{
'id': 1001,
'text': 'STEMI requires emergent revascularization with primary PCI and dual antiplatelet therapy.',
'department': 'cardiology',
'topic': 'acute_coronary_syndrome',
'year': 2024
},
{
'id': 1002,
'text': 'Heart failure with reduced ejection fraction is treated with ARNI, beta-blocker, MRA, and SGLT2 inhibitor therapy.',
'department': 'cardiology',
'topic': 'heart_failure',
'year': 2024
},
{
'id': 2001,
'text': 'Acute ischemic stroke management includes rapid imaging, alteplase within the treatment window, and thrombectomy in selected patients.',
'department': 'neurology',
'topic': 'stroke',
'year': 2024
},
{
'id': 2002,
'text': 'Transient ischemic attack requires urgent secondary prevention and vascular risk stratification.',
'department': 'neurology',
'topic': 'stroke',
'year': 2023
},
{
'id': 2003,
'text': 'Secondary stroke prevention includes antiplatelet therapy, statins, blood pressure control, and carotid evaluation when indicated.',
'department': 'neurology',
'topic': 'stroke_prevention',
'year': 2024
},
{
'id': 3001,
'text': 'COPD exacerbations are managed with bronchodilators, corticosteroids, and antibiotics when indicated.',
'department': 'pulmonology',
'topic': 'copd',
'year': 2024
}
]
-- Basic dense search
SEARCH qql_sample_v2 SIMILAR TO 'stroke thrombolysis and thrombectomy' LIMIT 3
-- Dense search with filter
SEARCH qql_sample_v2 SIMILAR TO 'secondary stroke prevention' LIMIT 3 WHERE department = 'neurology'
-- Query-time search params
SEARCH qql_sample_v2 SIMILAR TO 'acute coronary syndrome' LIMIT 3 EXACT
SEARCH qql_sample_v2 SIMILAR TO 'stroke prevention' LIMIT 3 WITH { hnsw_ef: 128 }
-- Recommendation from known example IDs
RECOMMEND FROM qql_sample_v2
POSITIVE IDS (2001)
LIMIT 3
RECOMMEND FROM qql_sample_v2
POSITIVE IDS (2001, 2002)
NEGATIVE IDS (1001)
STRATEGY 'best_score'
LIMIT 3
WHERE department = 'neurology'
-- Recommend with pagination and score threshold
RECOMMEND FROM qql_sample_v2
POSITIVE IDS (2001)
LIMIT 5
OFFSET 2
SCORE THRESHOLD 0.3
-- Recommend with exact KNN baseline
RECOMMEND FROM qql_sample_v2
POSITIVE IDS (2001)
LIMIT 3
WITH { exact: true }
-- Recommend using sparse vector instead of dense
RECOMMEND FROM qql_sample_v2_hybrid
POSITIVE IDS (4001)
LIMIT 3
USING 'sparse'
-- Hybrid collection
CREATE COLLECTION qql_sample_v2_hybrid HYBRID
INSERT BULK INTO COLLECTION qql_sample_v2_hybrid VALUES [
{
'id': 4001,
'text': 'Transformer attention mechanisms improve long-context sequence modeling and retrieval quality.',
'domain': 'ml',
'year': 2024
},
{
'id': 4002,
'text': 'Sparse retrieval with BM25 remains strong for exact terminology and keyword-heavy document search.',
'domain': 'ir',
'year': 2023
},
{
'id': 4003,
'text': 'Hybrid retrieval combines dense semantic matching with sparse keyword search using reciprocal rank fusion.',
'domain': 'ir',
'year': 2024
}
] USING HYBRID
-- Hybrid and sparse-only search
SEARCH qql_sample_v2_hybrid SIMILAR TO 'keyword retrieval and bm25' LIMIT 3 USING HYBRID
SEARCH qql_sample_v2_hybrid SIMILAR TO 'keyword retrieval and bm25' LIMIT 3 USING SPARSE
SHOW COLLECTIONS