|
|
@@ -6,7 +6,7 @@ A CLI tool for searching markdown knowledge bases using hybrid retrieval: combin
|
|
|
|
|
|
```
|
|
|
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
|
|
-โ QMD Search Pipeline โ
|
|
|
+โ QMD Hybrid Search Pipeline โ
|
|
|
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
|
|
|
|
|
โโโโโโโโโโโโโโโโโโโ
|
|
|
@@ -16,31 +16,35 @@ A CLI tool for searching markdown knowledge bases using hybrid retrieval: combin
|
|
|
โโโโโโโโโโโโโโโโดโโโโโโโโโโโโโโโ
|
|
|
โผ โผ
|
|
|
โโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโ
|
|
|
- โ Query Expansionโ โ Direct Query โ
|
|
|
- โ (qwen3:0.6b) โ โ (ร2 weight) โ
|
|
|
+ โ Query Expansionโ โ Original Queryโ
|
|
|
+ โ (qwen3:0.6b) โ โ (ร2 weight) โ
|
|
|
โโโโโโโโโฌโโโโโโโโโ โโโโโโโโโฌโโโโโโโโโ
|
|
|
โ โ
|
|
|
- โ 1 alternative query โ
|
|
|
+ โ 2 alternative queries โ
|
|
|
โโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโ
|
|
|
โ
|
|
|
- โโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโ
|
|
|
- โผ โผ โผ
|
|
|
- โโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโ
|
|
|
- โ FTS Search โ โ FTS Search โ โ FTS Search โ
|
|
|
- โ (BM25) โ โ (BM25) โ โ (BM25) โ
|
|
|
- โโโโโโโโโฌโโโโโโโโโ โโโโโโโโโฌโโโโโโโโโ โโโโโโโโโฌโโโโโโโโโ
|
|
|
- โ โ โ
|
|
|
- โโโโโโโโโดโโโโโโโโโ โโโโโโโโโดโโโโโโโโโ โโโโโโโโโดโโโโโโโโโ
|
|
|
- โ Vector Search โ โ Vector Search โ โ Vector Search โ
|
|
|
- โ(embeddinggemma)โ โ(embeddinggemma)โ โ(embeddinggemma)โ
|
|
|
- โโโโโโโโโฌโโโโโโโโโ โโโโโโโโโฌโโโโโโโโโ โโโโโโโโโฌโโโโโโโโโ
|
|
|
- โ โ โ
|
|
|
- โโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโ
|
|
|
- โ
|
|
|
- โผ
|
|
|
+ โโโโโโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโ
|
|
|
+ โผ โผ โผ
|
|
|
+ โโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโ
|
|
|
+ โ Original Query โ โ Expanded Query 1โ โ Expanded Query 2โ
|
|
|
+ โโโโโโโโโโฌโโโโโโโโโ โโโโโโโโโโฌโโโโโโโโโ โโโโโโโโโโฌโโโโโโโโโ
|
|
|
+ โ โ โ
|
|
|
+ โโโโโโโโโดโโโโโโโโ โโโโโโโโโดโโโโโโโโ โโโโโโโโโดโโโโโโโโ
|
|
|
+ โผ โผ โผ โผ โผ โผ
|
|
|
+ โโโโโโโโโ โโโโโโโโโ โโโโโโโโโ โโโโโโโโโ โโโโโโโโโ โโโโโโโโโ
|
|
|
+ โ BM25 โ โVector โ โ BM25 โ โVector โ โ BM25 โ โVector โ
|
|
|
+ โ(FTS5) โ โSearch โ โ(FTS5) โ โSearch โ โ(FTS5) โ โSearch โ
|
|
|
+ โโโโโฌโโโโ โโโโโฌโโโโ โโโโโฌโโโโ โโโโโฌโโโโ โโโโโฌโโโโ โโโโโฌโโโโ
|
|
|
+ โ โ โ โ โ โ
|
|
|
+ โโโโโโโโโฌโโโโโโโโ โโโโโโโโฌโโโโโโโ โโโโโโโโฌโโโโโโโ
|
|
|
+ โ โ โ
|
|
|
+ โโโโโโโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโ
|
|
|
+ โ
|
|
|
+ โผ
|
|
|
โโโโโโโโโโโโโโโโโโโโโโโโโ
|
|
|
โ RRF Fusion + Bonus โ
|
|
|
- โ (Top-rank preserved) โ
|
|
|
+ โ Original query: ร2 โ
|
|
|
+ โ Top-rank bonus: +0.05โ
|
|
|
โ Top 30 Kept โ
|
|
|
โโโโโโโโโโโโโฌโโโโโโโโโโโโ
|
|
|
โ
|
|
|
@@ -54,7 +58,9 @@ A CLI tool for searching markdown knowledge bases using hybrid retrieval: combin
|
|
|
โผ
|
|
|
โโโโโโโโโโโโโโโโโโโโโโโโโ
|
|
|
โ Position-Aware Blend โ
|
|
|
- โ (RRF + Reranker) โ
|
|
|
+ โ Top 1-3: 75% RRF โ
|
|
|
+ โ Top 4-10: 60% RRF โ
|
|
|
+ โ Top 11+: 40% RRF โ
|
|
|
โโโโโโโโโโโโโโโโโโโโโโโโโ
|
|
|
```
|
|
|
|
|
|
@@ -134,20 +140,31 @@ bun install
|
|
|
|
|
|
```sh
|
|
|
# Index all .md files in current directory
|
|
|
-qmd index
|
|
|
+qmd add .
|
|
|
|
|
|
# Index with custom glob pattern
|
|
|
-qmd index "**/*.md"
|
|
|
+qmd add "docs/**/*.md"
|
|
|
|
|
|
-# Index specific directory
|
|
|
-qmd index "docs/**/*.md"
|
|
|
+# Drop and re-add a collection
|
|
|
+qmd add --drop .
|
|
|
```
|
|
|
|
|
|
### Generate Vector Embeddings
|
|
|
|
|
|
```sh
|
|
|
-# Embed all indexed documents
|
|
|
+# Embed all indexed documents (chunked into ~6KB pieces)
|
|
|
qmd embed
|
|
|
+
|
|
|
+# Force re-embed everything
|
|
|
+qmd embed -f
|
|
|
+```
|
|
|
+
|
|
|
+### Add Context
|
|
|
+
|
|
|
+```sh
|
|
|
+# Add context description for files in a path
|
|
|
+qmd add-context . "Project documentation and guides"
|
|
|
+qmd add-context ./meetings "Internal meeting transcripts"
|
|
|
```
|
|
|
|
|
|
### Search Commands
|
|
|
@@ -176,12 +193,14 @@ qmd query "user authentication"
|
|
|
### Options
|
|
|
|
|
|
```sh
|
|
|
--n <num> # Number of results (default: 5)
|
|
|
+-n <num> # Number of results (default: 5, or 20 for --files/--json)
|
|
|
--min-score <num> # Minimum score threshold (default: 0)
|
|
|
--full # Show full document content
|
|
|
--csv # CSV output (for piping/scripting)
|
|
|
--md # Output as markdown
|
|
|
--xml # Output as XML
|
|
|
+--files # Output: score,filepath,context
|
|
|
+--json # JSON output with snippets
|
|
|
+--csv # CSV output with snippets
|
|
|
+--md # Markdown output
|
|
|
+--xml # XML output
|
|
|
--index <name> # Use named index
|
|
|
```
|
|
|
|
|
|
@@ -190,19 +209,19 @@ qmd query "user authentication"
|
|
|
Default output is colorized CLI format (respects `NO_COLOR` env):
|
|
|
|
|
|
```
|
|
|
- 93% docs/guide.md:42
|
|
|
+ 93% ~/docs/guide.md:42
|
|
|
โ This section covers the **craftsmanship** of building
|
|
|
โ quality software with attention to detail.
|
|
|
โ See also: engineering principles
|
|
|
|
|
|
- 67% notes/meeting.md:15
|
|
|
+ 67% ~/notes/meeting.md:15
|
|
|
โ Discussion about code quality and craftsmanship
|
|
|
โ in the development process.
|
|
|
```
|
|
|
|
|
|
- **Score**: Color-coded (green >70%, yellow >40%, dim otherwise)
|
|
|
-- **Path**: Shortened relative to current directory
|
|
|
-- **Line**: Line number where match was found (omitted for vector-only results)
|
|
|
+- **Path**: Relative to $HOME (`~/...`)
|
|
|
+- **Line**: Line number where match was found
|
|
|
- **Snippet**: Context around match with query terms highlighted
|
|
|
|
|
|
### Examples
|
|
|
@@ -212,7 +231,10 @@ Default output is colorized CLI format (respects `NO_COLOR` env):
|
|
|
qmd query -n 10 --min-score 0.3 "API design patterns"
|
|
|
|
|
|
# Output as markdown for LLM context
|
|
|
-qmd search -md --full "error handling"
|
|
|
+qmd search --md --full "error handling"
|
|
|
+
|
|
|
+# JSON output for scripting
|
|
|
+qmd query --json "quarterly reports"
|
|
|
|
|
|
# Use separate index for different knowledge base
|
|
|
qmd --index work search "quarterly reports"
|
|
|
@@ -221,14 +243,17 @@ qmd --index work search "quarterly reports"
|
|
|
### Manage Collections
|
|
|
|
|
|
```sh
|
|
|
-# List all indexed collections
|
|
|
-qmd list
|
|
|
+# Show index status and collections with contexts
|
|
|
+qmd status
|
|
|
|
|
|
-# Show database statistics
|
|
|
-qmd stats
|
|
|
+# Re-index all collections
|
|
|
+qmd update-all
|
|
|
|
|
|
-# Forget a collection
|
|
|
-qmd forget
|
|
|
+# Get document body by filepath
|
|
|
+qmd get ~/notes/meeting.md
|
|
|
+
|
|
|
+# Clean up cache and orphaned data
|
|
|
+qmd cleanup
|
|
|
```
|
|
|
|
|
|
## Data Storage
|
|
|
@@ -239,10 +264,12 @@ Index stored in: `~/.cache/qmd/index.sqlite`
|
|
|
|
|
|
```sql
|
|
|
collections -- Indexed directories and glob patterns
|
|
|
+path_contexts -- Context descriptions by path prefix
|
|
|
documents -- Markdown content with metadata
|
|
|
documents_fts -- FTS5 full-text index
|
|
|
-content_vectors -- Embedding cache (by content hash)
|
|
|
-vectors_vec -- sqlite-vec vector index
|
|
|
+content_vectors -- Embedding chunks (hash, seq, pos)
|
|
|
+vectors_vec -- sqlite-vec vector index (hash_seq key)
|
|
|
+ollama_cache -- Cached API responses
|
|
|
```
|
|
|
|
|
|
## Environment Variables
|
|
|
@@ -259,32 +286,59 @@ vectors_vec -- sqlite-vec vector index
|
|
|
```
|
|
|
Markdown Files โโโบ Parse Title โโโบ Hash Content โโโบ Store in SQLite
|
|
|
โ โ
|
|
|
- โโโบ FTS5 Index โโโโโโโโโโโโโโโโโโโโโโโ
|
|
|
+ โโโโโโโโโโโโบ FTS5 Index โโโโโโโโโโโโโโ
|
|
|
```
|
|
|
|
|
|
### Embedding Flow
|
|
|
|
|
|
+Documents are chunked into ~6KB pieces to fit the embedding model's token window:
|
|
|
+
|
|
|
```
|
|
|
-Document โโโบ Format for EmbeddingGemma โโโบ Ollama API โโโบ Store Vector
|
|
|
- "title: X | text: Y" /api/embed
|
|
|
+Document โโโบ Chunk (~6KB each) โโโบ Format each chunk โโโบ Ollama API โโโบ Store Vectors
|
|
|
+ โ "title | text" /api/embed
|
|
|
+ โ
|
|
|
+ โโโบ Chunks stored with:
|
|
|
+ - hash: document hash
|
|
|
+ - seq: chunk sequence (0, 1, 2...)
|
|
|
+ - pos: character position in original
|
|
|
```
|
|
|
|
|
|
### Query Flow (Hybrid)
|
|
|
|
|
|
```
|
|
|
-Query โโโบ Expand (3 variations) โโโบ FTS + Vector (per variation)
|
|
|
- โ
|
|
|
- โผ
|
|
|
- Merge (max score)
|
|
|
- โ
|
|
|
- โผ
|
|
|
- Top 25 candidates
|
|
|
- โ
|
|
|
- โผ
|
|
|
- LLM Re-rank (0-10)
|
|
|
- โ
|
|
|
- โผ
|
|
|
- Final ranked results
|
|
|
+Query โโโบ LLM Expansion โโโบ [Original, Variant 1, Variant 2]
|
|
|
+ โ
|
|
|
+ โโโโโโโโโโโดโโโโโโโโโโ
|
|
|
+ โผ โผ
|
|
|
+ For each query: FTS (BM25)
|
|
|
+ โ โ
|
|
|
+ โผ โผ
|
|
|
+ Vector Search Ranked List
|
|
|
+ โ
|
|
|
+ โผ
|
|
|
+ Ranked List
|
|
|
+ โ
|
|
|
+ โโโโโโโโโโโฌโโโโโโโโโโ
|
|
|
+ โผ
|
|
|
+ RRF Fusion (k=60)
|
|
|
+ Original query ร2 weight
|
|
|
+ Top-rank bonus: +0.05/#1, +0.02/#2-3
|
|
|
+ โ
|
|
|
+ โผ
|
|
|
+ Top 30 candidates
|
|
|
+ โ
|
|
|
+ โผ
|
|
|
+ LLM Re-ranking
|
|
|
+ (yes/no + logprob confidence)
|
|
|
+ โ
|
|
|
+ โผ
|
|
|
+ Position-Aware Blend
|
|
|
+ Rank 1-3: 75% RRF / 25% reranker
|
|
|
+ Rank 4-10: 60% RRF / 40% reranker
|
|
|
+ Rank 11+: 40% RRF / 60% reranker
|
|
|
+ โ
|
|
|
+ โผ
|
|
|
+ Final Results
|
|
|
```
|
|
|
|
|
|
## Model Configuration
|