|
| 1 | +### Concept: Create Collection |
| 2 | +```commandline |
| 3 | +-- Dense-only (default model, 384 dims) |
| 4 | +CREATE COLLECTION research_papers |
| 5 | +
|
| 6 | +-- Pinned to a specific model (768 dims) |
| 7 | +CREATE COLLECTION research_papers USING MODEL 'BAAI/bge-base-en-v1.5' |
| 8 | +
|
| 9 | +-- Hybrid (dense + sparse BM25) |
| 10 | +CREATE COLLECTION research_papers HYBRID |
| 11 | +
|
| 12 | +-- Hybrid with custom dense model |
| 13 | +CREATE COLLECTION research_papers USING HYBRID DENSE MODEL 'BAAI/bge-base-en-v1.5' |
| 14 | +``` |
| 15 | + |
| 16 | +### Concept: SHOW COLLECTIONS + DROP COLLECTION |
| 17 | +```commandline |
| 18 | +SHOW COLLECTIONS |
| 19 | +
|
| 20 | +DROP COLLECTION old_experiments |
| 21 | +``` |
| 22 | + |
| 23 | +### Concept: INSERT INTO COLLECTION |
| 24 | +```commandline |
| 25 | +-- Minimal (text only) |
| 26 | +INSERT INTO COLLECTION articles VALUES {'text': 'Qdrant supports cosine similarity search'} |
| 27 | +
|
| 28 | +-- With rich metadata |
| 29 | +INSERT INTO COLLECTION articles VALUES { |
| 30 | + 'text': 'Neural networks learn representations from data', |
| 31 | + 'author': 'alice', |
| 32 | + 'category': 'ml', |
| 33 | + 'year': 2024, |
| 34 | + 'published': true |
| 35 | +} |
| 36 | +
|
| 37 | +-- With a specific embedding model |
| 38 | +INSERT INTO COLLECTION articles VALUES {'text': 'hello world'} USING MODEL 'BAAI/bge-small-en-v1.5' |
| 39 | +``` |
| 40 | +#### Bulk Insert |
| 41 | +```commandline |
| 42 | +-- Minimal bulk |
| 43 | +INSERT BULK INTO COLLECTION articles VALUES [ |
| 44 | + {'text': 'Qdrant supports cosine similarity search'}, |
| 45 | + {'text': 'Sparse BM25 vectors enable keyword retrieval'}, |
| 46 | + {'text': 'Hybrid search combines dense and sparse results via RRF'} |
| 47 | +] |
| 48 | +
|
| 49 | +-- With metadata |
| 50 | +INSERT BULK INTO COLLECTION articles VALUES [ |
| 51 | + {'text': 'Attention is all you need', 'author': 'vaswani', 'year': 2017}, |
| 52 | + {'text': 'BERT: Pre-training of deep bidirectional transformers', 'author': 'devlin', 'year': 2018}, |
| 53 | + {'text': 'Language models are few-shot learners', 'author': 'brown', 'year': 2020} |
| 54 | +] |
| 55 | +``` |
| 56 | + |
| 57 | +### Concept: DELETE FROM |
| 58 | +```commandline |
| 59 | +-- By UUID (from INSERT output) |
| 60 | +DELETE FROM articles WHERE id = '3f2e1a4b-8c91-4d0e-b123-abc123def456' |
| 61 | +
|
| 62 | +-- By integer ID |
| 63 | +DELETE FROM articles WHERE id = 42 |
| 64 | +``` |
| 65 | + |
| 66 | +### Concept: Basic Semantic Search |
| 67 | +```commandline |
| 68 | +-- Top 5 results |
| 69 | +SEARCH articles SIMILAR TO 'machine learning algorithms' LIMIT 5 |
| 70 | +
|
| 71 | +-- With a specific model (must match INSERT model) |
| 72 | +SEARCH articles SIMILAR TO 'deep learning' LIMIT 10 USING MODEL 'BAAI/bge-small-en-v1.5' |
| 73 | +
|
| 74 | +-- Equality / inequality |
| 75 | +SEARCH articles SIMILAR TO 'ml' LIMIT 10 WHERE category = 'paper' |
| 76 | +SEARCH articles SIMILAR TO 'ml' LIMIT 10 WHERE status != 'draft' |
| 77 | +
|
| 78 | +-- Range |
| 79 | +SEARCH articles SIMILAR TO 'ai' LIMIT 5 WHERE year > 2020 |
| 80 | +SEARCH articles SIMILAR TO 'history of ai' LIMIT 10 WHERE year BETWEEN 2018 AND 2023 |
| 81 | +
|
| 82 | +-- IN / NOT IN |
| 83 | +SEARCH articles SIMILAR TO 'retrieval' LIMIT 10 WHERE status IN ('published', 'reviewed') |
| 84 | +
|
| 85 | +-- Null checks |
| 86 | +SEARCH articles SIMILAR TO 'ml' LIMIT 5 WHERE reviewer IS NOT NULL |
| 87 | +
|
| 88 | +-- Full-text MATCH |
| 89 | +SEARCH articles SIMILAR TO 'search' LIMIT 10 WHERE title MATCH PHRASE 'semantic search' |
| 90 | +
|
| 91 | +-- Logical AND / OR / NOT |
| 92 | +SEARCH articles SIMILAR TO 'nlp' LIMIT 10 WHERE category = 'paper' AND year >= 2020 |
| 93 | +SEARCH articles SIMILAR TO 'conference' LIMIT 10 WHERE (source = 'arxiv' OR source = 'ieee') AND year >= 2022 |
| 94 | +
|
| 95 | +-- Single level nesting |
| 96 | +SEARCH articles SIMILAR TO 'wikipedia' LIMIT 5 WHERE meta.source = 'web' |
| 97 | +
|
| 98 | +-- Array of nested objects |
| 99 | +SEARCH cities SIMILAR TO 'large city' LIMIT 5 WHERE country.cities[].population > 1000000 |
| 100 | +
|
| 101 | +-- Simple Hybrid search |
| 102 | +SEARCH articles SIMILAR TO 'transformer architecture' LIMIT 10 USING HYBRID |
| 103 | +
|
| 104 | +-- Hybrid search with WHERE |
| 105 | +SEARCH articles SIMILAR TO 'transformers' LIMIT 10 USING HYBRID WHERE year >= 2020 |
| 106 | +
|
| 107 | +-- Custom dense + sparse models |
| 108 | +SEARCH articles SIMILAR TO 'sparse retrieval' LIMIT 5 |
| 109 | + USING HYBRID DENSE MODEL 'BAAI/bge-base-en-v1.5' SPARSE MODEL 'prithivida/Splade_PP_en_v1' |
| 110 | + |
| 111 | +-- Default SPLADE/BM25 |
| 112 | +SEARCH medical_knowledge SIMILAR TO 'beta blocker contraindications' LIMIT 5 USING SPARSE |
| 113 | +
|
| 114 | +-- Custom sparse model |
| 115 | +SEARCH medical_knowledge SIMILAR TO 'beta blocker contraindications' LIMIT 5 |
| 116 | + USING SPARSE MODEL 'prithivida/Splade_PP_en_v1' |
| 117 | +``` |
| 118 | + |
| 119 | +### Concept: RERANK — second-pass precision scoring |
| 120 | +```commandline |
| 121 | +-- Dense search + rerank |
| 122 | +SEARCH articles SIMILAR TO 'machine learning for healthcare' LIMIT 5 RERANK |
| 123 | +
|
| 124 | +-- Hybrid + rerank (maximum precision) |
| 125 | +SEARCH articles SIMILAR TO 'attention mechanism in transformers' LIMIT 10 USING HYBRID RERANK |
| 126 | +
|
| 127 | +-- With WHERE + rerank |
| 128 | +SEARCH articles SIMILAR TO 'deep learning' LIMIT 10 WHERE year > 2020 RERANK |
| 129 | +
|
| 130 | +-- Custom cross-encoder |
| 131 | +SEARCH articles SIMILAR TO 'semantic search' LIMIT 5 |
| 132 | + RERANK MODEL 'BAAI/bge-reranker-large' |
| 133 | +
|
| 134 | +-- Everything combined |
| 135 | +SEARCH articles SIMILAR TO 'neural IR' LIMIT 10 |
| 136 | + USING HYBRID DENSE MODEL 'BAAI/bge-base-en-v1.5' |
| 137 | + WHERE year >= 2020 |
| 138 | + RERANK MODEL 'cross-encoder/ms-marco-MiniLM-L-6-v2' |
| 139 | +``` |
| 140 | + |
| 141 | +### Concept: Query-time search parameter overrides |
| 142 | +```commandline |
| 143 | +-- Exact KNN (brute force, useful for recall debugging) |
| 144 | +SEARCH articles SIMILAR TO 'attention mechanism' LIMIT 10 EXACT |
| 145 | +
|
| 146 | +-- Boost HNSW exploration at query time (higher ef = better recall, slower) |
| 147 | +SEARCH articles SIMILAR TO 'transformers' LIMIT 10 WITH { hnsw_ef: 256 } |
| 148 | +
|
| 149 | +-- ACORN for filtered queries |
| 150 | +SEARCH articles SIMILAR TO 'RAG' LIMIT 10 WHERE tag = 'li' WITH { acorn: true } |
| 151 | +
|
| 152 | +-- Hybrid + exact mode |
| 153 | +SEARCH articles SIMILAR TO 'attention' LIMIT 10 USING HYBRID EXACT |
| 154 | +``` |
| 155 | + |
| 156 | +### Concept: playing with .qql script files |
| 157 | +```commandline |
| 158 | +# From terminal |
| 159 | +qql> execute seed.qql |
| 160 | +
|
| 161 | +# Stop on first error |
| 162 | +qql> execute seed.qql --stop-on-error |
| 163 | +
|
| 164 | +# Export all points to a .qql file |
| 165 | +qql> dump medical_records backup.qql |
| 166 | +
|
| 167 | +# Inside the shell |
| 168 | +qql> DUMP COLLECTION medical_records backup.qql |
| 169 | +
|
| 170 | +# Round-trip: backup → drop → restore |
| 171 | +qql> dump medical_records backup.qql |
| 172 | +qql> DROP COLLECTION medical_records |
| 173 | +qql> execute backup.qql |
| 174 | +``` |
0 commit comments