feat(search): heading_path FTS5 text column filter #165
Reference in New Issue
Block a user
Delete Branch "feat/heading-text-column-filter"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
요약
v0.17.0 trigram tokenizer (PR #159) 가 미수정으로 남겨둔
heading_path_jsonJSON 노이즈 closure. trigram 이chunks_fts.heading_path컬럼 (V002/V007 트리거가chunks.heading_path_json을 그대로 INSERT) 의 JSON 표기 ([,",,) + 안의 path 세그먼트 (app,src) 까지 3-gram 색인 → query 가 우연히 false positive hit 하는 문제. 사용자 결정: column filter —heading_path색인은 V007 verbatim 그대로 유지, 매칭 대상만text컬럼으로 한정. V008 migration / design §5.5 verbatim 블록 변경 불필요.변경
crates/kebab-search/src/lexical.rs::build_match_string가 non-raw 분기에서 combined expression 을text : (<expr>)로 wrap. FTS5 column filter syntax (column:expr) 가 OR/AND sub-expression 허용 — 한국어 trigram 빌더의(whole) OR (token_and)형태가 그대로 들어감.'...') 는 변경 없음 — 사용자가 명시 의도로'heading_path : agent'같은 explicit column filter opt-in 가능 (escape hatch).heading_path_json노이즈 항목 closure 표기 + 새 2026-05-25 post-v0.17.1 dogfood entry 추가.Surface 영향
search_response.v1의 shape 동일.'foo OR bar*') 가 이미 documented escape hatch — heading 검색이 필요한 사용자는'heading_path : <token>'형태로 진입 가능. 별도 SKILL.md 갱신 불필요.검증
cargo test -p kebab-search -p kebab-store-sqlite -p kebab-app -j 1— 전부 녹색 (RAM 16 GB 제약으로 직렬 빌드).cargo clippy -p kebab-search -p kebab-store-sqlite -p kebab-app --all-targets -j 1 -- -D warnings— clean.lexical_snapshot_run_1+hybrid_snapshot_run_1둘 다 column filter 적용 후에도 점수 동일 (text 본문 매칭 query 라 BM25 분포 무변화) — fixture regenerate 불필요.시험 항목 (Test Plan)
build_match_string_*8 unit test (column filter prefix 추가된 expected string 으로 갱신)build_match_string_raw_mode_preserves_heading_filter신규 — raw mode 가 explicitheading_path : ...보존 확인lexical_heading_only_token_does_not_hit_default_mode신규 회귀 핀 — heading-only unique token (kubernetes-agent-controller) 가 default mode 에서 0 hitlexical_raw_mode_can_opt_into_heading_path_filter신규 — 같은 fixture 가 raw mode 로 1 hit (escape hatch 동작 핀)lexical_multi_token_korean_query_hits등) — text 본문 매칭이라 column filter 영향 없음비범위
chunks_fts.heading_path컬럼 제거 / 평문 heading 변환 — column filter 만으로 false positive 차단 충분, schema 변경은 over-engineering.project_ranking_deferred정책 그대로 유지.Assisted-by: Claude Code
회차 1 — column filter approach 깔끔, raw mode escape hatch 보존 + 신규 회귀 핀 2 가 dual invariant (default 0 hit / raw 1 hit) 핀. actionable 2 + 칭찬 2:
9 신규 / 갱신 unit test카운트 표기 ambiguity — 실제 11 (8 갱신 + 1 신규 unit + 2 신규 integration). 명시 권장'foo OR bar*'만 예제 — heading 검색 의도 사용자가 새 escape hatch'heading_path : <token>'발견 어려움. 별 PR 또는 본 PR 추가 결정 사용자 위임칭찬:
format!의 paren wrap 이 OR/AND precedence 위험 차단 + dual-invariant 회귀 핀 설계.@@ -228,0 +241,4 @@(Some(w), None) => w,(None, Some(a)) => a,(Some(w), Some(a)) if w == a => w,(Some(w), Some(a)) => format!("({w}) OR ({a})"),칭찬 —
format!("text : ({expression})")의 paren wrap 이 중요. FTS5 의 column filtertext : foo OR bar가 parser 에 따라(text:foo) OR bar로 잘못 binding 될 위험 있는데 outer paren 으로 OR/AND sub-expression 을 column filter scope 안에 명확히 묶음. 회귀 핀lexical_heading_only_token_does_not_hit_default_mode가 OR 케이스 (text : (("foo bar") OR ("foo" "bar"))) 도 실제 SQLite 가 받아들임 실증.@@ -1063,0 +1063,4 @@// ── post-v0.17.1 dogfood — `text` column filter ──────────────────────────/// Heading-only token (unique to `chunks.heading_path_json`, absent칭찬 —
lexical_heading_only_token_does_not_hit_default_mode+lexical_raw_mode_can_opt_into_heading_path_filter가 같은 fixture (heading-only unique token + 무관 text body) 로 default 0 hit / raw-mode 1 hit 의 dual invariant 를 핀. closure 의 의도 (false positive 차단 + escape hatch 보존) 가 한 fixture 의 두 시각으로 검증되어 후속 회귀 detection 가 자연.@@ -52,0 +53,4 @@v0.17.0 의 한국어 trigram tokenizer 채택 entry (2026-05-24 위) 가 미수정으로 남겨둔 `heading_path_json` JSON 노이즈 closure. trigram 이 `chunks_fts.heading_path` 컬럼 (V002/V007 트리거가 `chunks.heading_path_json` 을 그대로 INSERT) 의 JSON 표기 (`[`, `"`, `,`) + 안의 path 세그먼트 (`app`, `src`) 까지 3-gram 색인해서 query 가 우연히 false positive hit 하는 문제. 사용자 결정 (column filter vs 평문 heading 변환): **column filter** — `heading_path` 색인은 V007 verbatim 그대로 유지, 매칭 대상만 `text` 컬럼으로 한정. V008 migration / design §5.5 verbatim 블록 변경 불필요.**변경**:test 카운트 표기 ambiguity.
9 신규 / 갱신 unit test:다음 4 bullet 의 실제 산수:build_match_string_*expected string)build_match_string_raw_mode_preserves_heading_filter)lexical_heading_only_token_does_not_hit_default_mode+lexical_raw_mode_can_opt_into_heading_path_filter,crates/kebab-search/tests/lexical.rs)= 11 total (9 unit + 2 integration). doc 의
9 신규 / 갱신 unit test는 unit 만 세고 integration 을 별도라 두어 의도된 듯하나 산수가 그대로 안 보임. 명시 권장:후속 archeology 가 count 그대로 따라가도록.
@@ -52,0 +63,4 @@- `lexical_raw_mode_can_opt_into_heading_path_filter` 신규 — 같은 fixture 가 raw mode 로 hit 확인**사용자 영향**:- 기본 lexical / hybrid 검색에서 heading 만 매칭되던 false positive 차단. 한국어 / 영어 substring 매칭의 recall 은 그대로 (text 본문에 있는 token 은 변함없이 hit). 본문 검색의 precision 가 올라감.Follow-up suggestion (본 PR 비범위): SKILL.md 의 raw mode 안내가 v0.17.0 에서
'foo OR bar*'한 예제만 가지고 있어, heading 검색을 일부러 하던 agent / 사용자 (있다면) 가'heading_path : <token>'라는 새 escape hatch 를 발견하기 어려움.integrations/claude-code/kebab/SKILL.md의 raw mode 절에 한 줄 example 추가가 발견성 ↑ — 별 PR 또는 follow-up commit.현재 PR 의 "별도 SKILL.md 갱신 불필요" 판단은 raw mode 자체가 documented 임을 근거로 했는데, 신규 column-name (
heading_path) 이 documented surface 가 아닌 점은 분리해 봐야 함. 사용자 결정 위임 — 본 PR 에 포함할지 별 PR 로 분리할지.회차 2 — 회차 1 의 2 actionable 모두 잘 반영 (count 정정 + SKILL.md 추가). 그러나 SKILL.md 추가가 HOTFIXES entry 본문의
별도 SKILL.md 갱신 불필요단락과 contradiction. 한 줄 정정 후 APPROVE 가능.actionable 1 + 칭찬 1.
@@ -61,6 +61,7 @@ Input:- When `truncated: true`, the budget loop modified the page (snippet shortening or k reduction). `next_cursor` is **independent** — non-null whenever more hits may be reachable. Caller may widen `max_tokens` (re-issue same query for fuller snippets / more hits per page) or follow `next_cursor` (advance through more hits) or both. Mismatched cursor (corpus_revision changed) returns `error.v1.code = stale_cursor` — re-issue the search to obtain a fresh one.- **`trace: true` (p9-fb-37)** — debug aid. Response carries an extra `trace` block: `lexical[]` + `vector[]` (pre-fusion candidates), `rrf_inputs[]` (RRF union before final cut), and `timing` (`lexical_ms`, `vector_ms`, `fusion_ms`, `total_ms`). Trace bypasses the search cache (always cold). Use sparingly — it bloats the wire response and is for diagnosing "why did this hit / not hit", not normal retrieval.- **`hint` (v0.17.0)** — optional advisory string on `search_response.v1`. Present only when the result is empty AND the trimmed query is shorter than the FTS5 trigram tokenizer's 3-char minimum. Surface it to the user instead of retrying the same short query. Korean lexical search benefits most from ≥3-char keywords (`충돌` zero-hit, `충돌은` substring-hit). Raw FTS5 mode (`'...'`) opts out — the user opted into FTS5 syntax. Vector / hybrid modes carry the field too but it's rarely triggered (semantic embeddings handle short queries).- **Column scoping (post-v0.17.1 dogfood)** — default lexical / hybrid matching is scoped to the `text` column only. The `heading_path` column is indexed (path segments like `app`, `src` plus JSON punctuation are 3-gram'd) but excluded from the default MATCH — past JSON noise produced false positives where a query coincidentally shared a 3-gram with a file's heading path. To deliberately search heading paths, escape into raw FTS5 mode with an explicit column filter: `'heading_path : <token>'` (e.g. `kebab search "'heading_path : agent'"`). Same applies to MCP `search` — quote the inner expression. Raw mode bypasses both column scoping and the 3-char `hint` short-circuit.칭찬 — column scoping bullet 이 (1) 기본 동작 (text 한정) + (2) JSON 노이즈 원인 + (3) escape hatch (
'heading_path : agent') + (4) CLI / MCP 양쪽 적용 + (5) raw mode 가hintshort-circuit 도 우회 한다는 cross-feature 영향까지 한 단락에 압축. agent 가 doc 읽고 한 번에 사용 가능 — examplekebab search "'heading_path : agent'"의 shell-quote escaping (outer"+ inner') 도 실제 호출 가능한 형태로 정확.@@ -52,0 +71,4 @@**MCP / agent 가시성**: `search_response.v1` 의 wire shape 변경 없음. 사용자가 heading 검색을 명시 의도하던 케이스는 raw mode 안내 — `integrations/claude-code/kebab/SKILL.md` 의 search 절은 v0.17.0 의 raw mode 안내 (`'foo OR bar*'`) 가 그대로 적용. 별도 SKILL.md 갱신 불필요 (raw mode 가 이미 documented escape hatch).Cross-link: `crates/kebab-search/src/lexical.rs::build_match_string`, `migrations/V007__fts_trigram.sql` (verbatim 유지), design §5.5 (verbatim 유지, query-time 동작만 변경).회차 1 의 follow-up suggestion 을 본 PR 에 포함하기로 결정 후 SKILL.md 가 실제로 갱신됐는데, HOTFIXES entry 의 마지막 단락이 여전히
별도 SKILL.md 갱신 불필요 (raw mode 가 이미 documented escape hatch)라고 적혀 있음 — contradiction. 변경 list 의 마지막 bullet (integrations/claude-code/kebab/SKILL.md ... 한 bullet 추가) 과도 맞지 않음.정정:
entry 가 후속 archeology 의 single source 라 변경 사실과 doc 본문이 일치해야 함.
회차 3 — 회차 2 의 doc contradiction 한 줄로 정정. 잔여 actionable 0건. APPROVE.
본 PR 의 회차 cadence (4 → 1 → 0) 자연스러운 수렴. 회차 1 의 follow-up suggestion 을 본 PR 에 포함하기로 한 결정이 HOTFIXES
별도 SKILL.md 갱신 불필요단락까지 영향을 cascade 한 게 회차 2 의 단일 actionable 원천 — 분리 PR 이었으면 안 났을 contradiction 인데 review loop 가 한 회차 안에 잡아 머지 후 follow-up 회피.PR-A (#164) + PR-B (#165) 모두 closure entry 정리 완료. v0.17.1 post-dogfood polish 완료.