Sfoglia il codice sorgente

Update README to reflect current implementation

- Fix architecture diagram: show BM25+Vector for all query variations
- Add position-aware blending percentages to diagram
- Update CLI commands: add โ†’ index, add-context, cleanup, status
- Document chunked embeddings (~6KB pieces with hash/seq/pos)
- Update schema section with new tables (path_contexts, ollama_cache)
- Rewrite How It Works flows with accurate pipeline details
- Fix output format examples to show ~/... paths
- Add --files and --json output options

๐Ÿค– Generated with [Claude Code](https://claude.com/claude-code)
Tobi Lutke 5 mesi fa
parent
commit
42ab3f6c10
1 ha cambiato i file con 113 aggiunte e 59 eliminazioni
  1. 113 59
      README.md

+ 113 - 59
README.md

@@ -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