fix(ck-engine): apply path scope before top_k in semantic search#111
Merged
Conversation
semantic_search_v3 was computing the top_k from all chunks in the index BEFORE applying the requested path filter. With a whole-codebase index plus a narrow \`path=\` query, the global top_k could be entirely consumed by chunks outside the requested scope, leaving the path filter with nothing to keep and returning an empty result set even though the in-scope file contained excellent matches. Two changes: - Build the scope once up-front (PathScope enum) and filter at the sidecar-collection stage. Earliest possible filter, also avoids loading and ranking embeddings we'd discard anyway. - Hoist the canonicalize() of \`options.path\` out of the per-result loop where it was running N times. Tests: - 3 PathScope unit tests (All / Dir / File) — run under all features including --no-default-features. - 1 regression test guarding the original symptom: index 8 noisy files about TOPIC_A in a sibling, plus 1 in-scope file, search the scoped dir with top_k=3, assert the result is non-empty and stays in scope. Gated on fastembed since it needs a real embedder. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
4 tasks
runonthespot
added a commit
that referenced
this pull request
May 23, 2026
Ships the bug fixes and security work merged today: - #111 fix: scoped semantic search returned [] when global top_k was consumed by chunks outside the requested path scope - #112 security: MCP tool handlers were sandbox-escapable via any readable host path; added allowed_roots + canonicalize check - #106 fix: MCP tool schemas now Gemini-API compatible (no more union types in JSON Schema) - #100 fix: oneshot 0.1.13 patches a use-after-free race - #99 chore: docs-site + ck-vscode dev-dep bumps See CHANGELOG.md. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
`semantic_search_v3` computed cosine similarity for every chunk in the index, sorted them, took the global top_k, and only THEN applied the path filter. With a whole-codebase index plus a narrow `path=` query, the global top_k could be entirely consumed by chunks outside the requested scope — leaving the path filter with nothing to keep and returning an empty result set even though the in-scope file had great matches.
Found via code review (task #10 in the session task list).
Fix
Tests
Test plan
🤖 Generated with Claude Code