Repository navigation
feat(filter): add a glob filter clause (#585) - #599
Conversation
|
I'll fix CI failures and address comments from users with write access. I'll skip comments containing "(aside)".
|
Gitignore-style path globs (`**`, `*`, `?`, classes, alternation) as a filter clause, parsed as strictly as `prefix`. Columnar segments seek to the pattern's literal prefix in the string dictionary. Co-Authored-By: Ravi Decover AI <[email protected]> ---kosha-bench--- microbenchmark: segment_memory (cargo bench -p kosha-query --bench segment_memory) corpus: 8 segments × 4000 docs (32000 total), vocab ~20000 runner: Linux 6.6.141 x86_64 | rustc 1.100.0 (0ef1bc386 2026-11-09) | 2026-11-27T01:23:09Z latency (v2 = current lazy format, median of inner samples): cold broad ("the") 4.1 ms warm broad ("the") 0.11 ms warm 2-term AND 0.12 ms warm phrase 0.09 ms warm wildcard w1* 46.56 ms ---end kosha-bench---
a105e0d to
d060230
Compare
kNN microbench — main vs this PR (
|
| metric | before | after | Δ | limit | |
|---|---|---|---|---|---|
| warm kNN p50 | 0.32 ms | 0.27 ms | -14.1% | +25% | |
| p90 (not gated) | 0.38 ms | 0.34 ms | -12.0% | ||
| p99 (not gated) | 0.71 ms | 0.69 ms | -2.3% | ||
| warm hybrid p50 | 0.43 ms | 0.37 ms | -12.9% | +25% | |
| p90 (not gated) | 0.47 ms | 0.46 ms | -2.5% | ||
| p99 (not gated) | 0.52 ms | 0.55 ms | +6.5% | ||
| cold kNN p50 | 2.51 ms | 2.67 ms | +6.4% | +40% | |
| p90 (not gated) | 3.05 ms | 3.00 ms | -1.8% | ||
| p99 (not gated) | 3.56 ms | 3.43 ms | -3.6% | ||
| open all segments p50 | 1.16 ms | 1.17 ms | +1.5% | +40% | |
| p90 (not gated) | 1.27 ms | 1.25 ms | -2.1% | ||
| p99 (not gated) | 1.40 ms | 1.38 ms | -1.6% | ||
| postings probed / query | 100.0 | 100.0 | +0.0% | +10% |
corpus 8 segs × 4000 docs, dim 256, 64 clusters · latency fails only past both the % limit and an absolute floor · postings/query is deterministic · label perf-regression-accepted to accept an intended cost
Relevance & recall (
|
| metric | base | head | Δ | limit | |
|---|---|---|---|---|---|
lexical.ndcg@10 |
93.04 | 93.04 | 0.00 | −1 | |
lexical.recall@100 |
75.70 | 75.70 | 0.00 | −1 | |
vector.ndcg@10 |
73.79 | 73.79 | 0.00 | −1 | |
vector.recall@100 |
63.86 | 63.86 | 0.00 | −1 | |
hybrid.ndcg@10 |
88.01 | 88.01 | 0.00 | −1 | |
hybrid.recall@100 |
82.81 | 82.81 | 0.00 | −1 | |
filtered_knn.probe@100%.recall@10 |
67.92 | 67.92 | 0.00 | −1 | |
filtered_knn.probe@50%.recall@10 |
88.92 | 88.92 | 0.00 | −1 | |
filtered_knn.probe@10%.recall@10 |
96.00 | 96.00 | 0.00 | −1 | |
filtered_knn.probe@1%.recall@10 |
98.17 | 98.17 | 0.00 | −1 | |
[email protected]%.recall@10 |
100.00 | 100.00 | 0.00 | −2 | |
filtered_knn.planned@100%.recall@10 |
67.92 | 67.92 | 0.00 | −1 | |
filtered_knn.planned@50%.recall@10 |
100.00 | 100.00 | 0.00 | −1 | |
filtered_knn.planned@10%.recall@10 |
100.00 | 100.00 | 0.00 | −1 | |
filtered_knn.planned@1%.recall@10 |
100.00 | 100.00 | 0.00 | −1 | |
[email protected]%.recall@10 |
100.00 | 100.00 | 0.00 | −2 | |
ood.filtered_knn.probe@100%.recall@10 |
33.00 | 33.00 | 0.00 | −1 | |
ood.filtered_knn.probe@50%.recall@10 |
55.33 | 55.33 | 0.00 | −1 | |
ood.filtered_knn.probe@10%.recall@10 |
90.33 | 90.33 | 0.00 | −1 | |
ood.filtered_knn.probe@1%.recall@10 |
97.33 | 97.33 | 0.00 | −1 | |
[email protected]%.recall@10 |
100.00 | 100.00 | 0.00 | −2 | |
ood.filtered_knn.planned@100%.recall@10 |
33.00 | 33.00 | 0.00 | −1 | |
ood.filtered_knn.planned@50%.recall@10 |
100.00 | 100.00 | 0.00 | −1 | |
ood.filtered_knn.planned@10%.recall@10 |
100.00 | 100.00 | 0.00 | −1 | |
ood.filtered_knn.planned@1%.recall@10 |
100.00 | 100.00 | 0.00 | −1 | |
[email protected]%.recall@10 |
100.00 | 100.00 | 0.00 | −2 | |
vector_ann.mrr@10 |
100.00 | 100.00 | 0.00 | −1 | |
vector_ann.ndcg@10 |
73.37 | 73.37 | 0.00 | −1 |
Fixture synthetic: 3000 docs in 3 segments, 120 judged queries; kNN num_candidates 1.
ANN vs exact on the head (same embeddings and qrels; points ×100):
| metric | ANN | exact | ANN − exact | queries |
|---|---|---|---|---|
mrr@10 |
100.00 | 100.00 | 0.00 | 120 |
ndcg@10 |
73.37 | 77.30 | -3.93 | 120 |
Fails when a metric drops by more than its limit; thresholds are set in .github/workflows/relevance-compare.yml.
Relevance & recall (kosha-query bench relevance) — fixture neardup
✅ No metric regressed past its threshold.
Values and deltas in points (×100). Base 9d807303aabd15e6b6d6da62d44b2ce6b64b32b9 → head 70f6744a2628759909b7e2306c39c64fd4a86072. The harness is deterministic, so any non-zero delta is a real change.
| metric | base | head | Δ | limit | |
|---|---|---|---|---|---|
lexical.ndcg@10 |
99.03 | 99.03 | 0.00 | −1 | |
lexical.recall@100 |
85.76 | 85.76 | 0.00 | −1 | |
vector.ndcg@10 |
82.61 | 82.61 | 0.00 | −1 | |
vector.recall@100 |
71.78 | 71.78 | 0.00 | −1 | |
hybrid.ndcg@10 |
96.92 | 96.92 | 0.00 | −1 | |
hybrid.recall@100 |
86.59 | 86.59 | 0.00 | −1 | |
filtered_knn.probe@100%.recall@10 |
74.67 | 74.67 | 0.00 | −1 | |
filtered_knn.probe@50%.recall@10 |
91.92 | 91.92 | 0.00 | −1 | |
filtered_knn.probe@10%.recall@10 |
100.00 | 100.00 | 0.00 | −1 | |
filtered_knn.probe@1%.recall@10 |
99.08 | 99.08 | 0.00 | −1 | |
[email protected]%.recall@10 |
100.00 | 100.00 | 0.00 | −2 | |
filtered_knn.planned@100%.recall@10 |
74.67 | 74.67 | 0.00 | −1 | |
filtered_knn.planned@50%.recall@10 |
100.00 | 100.00 | 0.00 | −1 | |
filtered_knn.planned@10%.recall@10 |
100.00 | 100.00 | 0.00 | −1 | |
filtered_knn.planned@1%.recall@10 |
100.00 | 100.00 | 0.00 | −1 | |
[email protected]%.recall@10 |
100.00 | 100.00 | 0.00 | −2 | |
vector_ann.mrr@10 |
83.47 | 83.47 | 0.00 | −1 | |
vector_ann.ndcg@10 |
83.05 | 83.05 | 0.00 | −1 |
Fixture neardup: 1900 docs in 2 segments, 120 judged queries; kNN num_candidates 1.
ANN vs exact on the head (same embeddings and qrels; points ×100):
| metric | ANN | exact | ANN − exact | queries |
|---|---|---|---|---|
mrr@10 |
83.47 | 79.89 | +3.58 | 120 |
ndcg@10 |
83.05 | 80.88 | +2.17 | 120 |
Fails when a metric drops by more than its limit; thresholds are set in .github/workflows/relevance-compare.yml.
⏱ Microbench — main vs this PR (
|
| metric | pctl | before (main) | after (PR) | Δ |
|---|---|---|---|---|
| cold broad ("the") | p50 | 2.78 ms | 2.90 ms | +4.5% |
| p90 | 2.99 ms | 3.25 ms | +8.8% | |
| p99 | 3.48 ms | 5.11 ms | +46.9% |
|
| warm broad ("the") | p50 | 0.090 ms | 0.115 ms | +28.1% |
| p90 | 0.097 ms | 0.121 ms | +25.4% |
|
| p99 | 0.107 ms | 0.147 ms | +37.3% |
|
| warm 2-term AND | p50 | 0.106 ms | 0.140 ms | +31.9% |
| p90 | 0.110 ms | 0.145 ms | +32.5% |
|
| p99 | 0.140 ms | 0.159 ms | +13.5% |
|
| warm 3-term AND broad | p50 | 0.119 ms | 0.157 ms | +31.4% |
| p90 | 0.158 ms | 0.162 ms | +2.2% | |
| p99 | 0.184 ms | 0.189 ms | +3.1% | |
| warm phrase | p50 | 0.080 ms | 0.098 ms | +21.9% |
| p90 | 0.082 ms | 0.101 ms | +22.8% |
|
| p99 | 0.097 ms | 0.106 ms | +9.2% | |
| warm wildcard w1* | p50 | 44.7 ms | 46.0 ms | +2.8% |
| p90 | 47.1 ms | 48.9 ms | +3.8% | |
| p99 | 50.0 ms | 59.0 ms | +17.9% |
|
| resident while open | — | 13.1 MiB | 13.1 MiB | +0.0% |
corpus 8 segs × 4000 docs · cold n=25, warm n=200 · nearest-rank percentiles · deltas within ±10% are usually runner noise
…ross '/' Replace globset with an iterative glob-to-regex translation: negated and positive classes exclude '/', matching is by Unicode character with Unicode case folding, alternates cannot nest, and patterns are capped at 4096 bytes so a deeply nested glob cannot overflow the stack (Devin Review on #599). Co-Authored-By: Ravi Decover AI <[email protected]>
…ross '/' Replace globset with an iterative glob-to-regex translation: negated and positive classes exclude '/', matching is by Unicode character with Unicode case folding, alternates cannot nest, and patterns are capped at 4096 bytes so a deeply nested glob cannot overflow the stack (Devin Review on #599). Co-Authored-By: Ravi Decover AI <[email protected]> ---kosha-bench--- microbenchmark: segment_memory (cargo bench -p kosha-query --bench segment_memory) corpus: 8 segments × 4000 docs (32000 total), vocab ~20000 runner: Linux 6.6.141 x86_64 | rustc 1.100.0 (0ef1bc386 2026-11-09) | 2026-11-27T01:32:29Z latency (v2 = current lazy format, median of inner samples): cold broad ("the") 3.0 ms warm broad ("the") 0.11 ms warm 2-term AND 0.12 ms warm phrase 0.09 ms warm wildcard w1* 42.34 ms ---end kosha-bench---
b79fd98 to
4892399
Compare
…ep '**' recursive at alternative edges Devin Review on #599: '/a/b}' and '[z--a]' are now 400s instead of literal text and regex set subtraction, and '/c/{**/*.pdf,s.txt}' matches PDFs at any depth. Co-Authored-By: Ravi Decover AI <[email protected]>
…ep '**' recursive at alternative edges Devin Review on #599: '/a/b}' and '[z--a]' are now 400s instead of literal text and regex set subtraction, and '/c/{**/*.pdf,s.txt}' matches PDFs at any depth. Co-Authored-By: Ravi Decover AI <[email protected]> ---kosha-bench--- microbenchmark: segment_memory (cargo bench -p kosha-query --bench segment_memory) corpus: 8 segments × 4000 docs (32000 total), vocab ~20000 runner: Linux 6.6.141 x86_64 | rustc 1.100.0 (0ef1bc386 2026-11-09) | 2026-11-27T01:37:12Z latency (v2 = current lazy format, median of inner samples): cold broad ("the") 3.2 ms warm broad ("the") 0.12 ms warm 2-term AND 0.13 ms warm phrase 0.10 ms warm wildcard w1* 50.33 ms ---end kosha-bench---
acbb42d to
6f45615
Compare
…newlines Devin Review on #599: an escaped ',' or '{' no longer makes the next '**' recursive, and recursive '**' matches values containing newlines. Co-Authored-By: Ravi Decover AI <[email protected]>
…newlines Devin Review on #599: an escaped ',' or '{' no longer makes the next '**' recursive, and recursive '**' matches values containing newlines. Co-Authored-By: Ravi Decover AI <[email protected]> ---kosha-bench--- microbenchmark: segment_memory (cargo bench -p kosha-query --bench segment_memory) corpus: 8 segments × 4000 docs (32000 total), vocab ~20000 runner: Linux 6.6.141 x86_64 | rustc 1.100.0 (0ef1bc386 2026-11-09) | 2026-11-27T01:41:07Z latency (v2 = current lazy format, median of inner samples): cold broad ("the") 3.0 ms warm broad ("the") 0.11 ms warm 2-term AND 0.13 ms warm phrase 0.09 ms warm wildcard w1* 59.54 ms ---end kosha-bench---
0685657 to
5ea9b04
Compare
Co-Authored-By: Ravi Decover AI <[email protected]> ---kosha-bench--- microbenchmark: segment_memory (cargo bench -p kosha-query --bench segment_memory) corpus: 8 segments × 4000 docs (32000 total), vocab ~20000 runner: Linux 6.6.141 x86_64 | rustc 1.100.0 (0ef1bc386 2026-11-09) | 2026-11-27T01:44:10Z latency (v2 = current lazy format, median of inner samples): cold broad ("the") 4.4 ms warm broad ("the") 0.11 ms warm 2-term AND 0.13 ms warm phrase 0.09 ms warm wildcard w1* 48.85 ms ---end kosha-bench---
cbd2f2d to
70f6744
Compare
What and why
Closes #585 (Phase L, #589). Adds a
globfilter clause so agents can select documents by path the way they would with a shell glob:{"glob": {"path": "/contracts/**/*.pdf"}} {"glob": {"path": {"value": "/Contracts/*.PDF", "case_insensitive": true}}}globset(literal_separator,backslash_escape):*/?never cross/,**spans directories,[abc]/[!abc],{pdf,docx},\escapes. Matches the whole value.prefix(sharedparse_field_pattern): exactly one field, onlyvalue/case_insensitive, malformed patterns are a 400 (never a match-all). String fields only; numeric field is a 400.bool,knn.filter, delete-by-query.GlobFilter::literal_prefix, e.g./contracts/) in the sorted string dictionary and test only that ordinal range, each distinct value once; list terms are tested separately. Case-insensitive or leading-wildcard patterns test the whole dictionary. Legacy row-scan segments scan the column. Bloom pruning never skips a segment for a glob.The dedicated path field / path index and the p50 measurement from #585 are not in this PR; the literal-prefix dictionary seek is the "avoid full scans for selective patterns" piece.
How it was tested
kosha-core: glob semantics table, literal-prefix soundness (every match starts with the literal prefix), parse/round-trip/malformed cases, row-scan evaluation incl. lists and numeric rejection.kosha-segment: glob cases added tocolumnar_evaluation_matches_the_row_scan_for_every_clause(columnar vs row-scan equivalence).kosha-query:glob_filters_paths_across_segments(two segments; lexical, filter-only, bool must/must_not, knn.filter, numeric error).kosha-server:delete_by_prefix_parses_strictly_and_spans_segmentsextended with glob search and malformed glob deletes (400, nothing deleted).cargo fmt --all -- --check,cargo clippy --all-targets --all-features -- -D warnings,cargo test --lockedfor core/segment/query/server.Compatibility
/v1wire contract (proto/kosha/v1/kosha.proto, request/response JSON)Additive: a new filter clause key. An older server answers
globwith its existing 400 for unknown filter keys (#170), never a match-all. No proto/OpenAPI schema change (filters are free-form JSON there).Checklist
cargo fmt --all -- --checkcargo clippy --all-targets --all-features -- -D warningscargo test --all-features(core, segment, query, server)make client-python-test(ifclients/pythonchanged)docker build -t kosha:ci .(if the Dockerfile or build configuration changed)KOSHA_*variables have a row indocs/configuration.mdLink to Devin session: https://app.devin.ai/sessions/91ac22e94520430382b0941c2adf82e1
Open in Devin Desktop: https://app.devin.ai/desktop/session/91ac22e94520430382b0941c2adf82e1?variant=devin
Requested by: @ravi-decoverai
🟢 Devin Review found nothing to fix · View findings · Follow Devin's work