Repository navigation
feat(clients): add kosha-ingest for PDF/DOCX/HTML with page boundaries (#587) - #602
Conversation
|
I'll fix CI failures and address comments from users with write access. I'll skip comments containing "(aside)".
|
#587) 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:57:39Z latency (v2 = current lazy format, median of inner samples): cold broad ("the") 3.2 ms warm broad ("the") 0.11 ms warm 2-term AND 0.12 ms warm phrase 0.09 ms warm wildcard w1* 45.28 ms ---end kosha-bench---
d2937a2 to
46ae404
Compare
kNN microbench — main vs this PR (
|
| metric | before | after | Δ | limit | |
|---|---|---|---|---|---|
| warm kNN p50 | 0.26 ms | 0.24 ms | -7.4% | +25% | |
| p90 (not gated) | 0.32 ms | 0.29 ms | -11.0% | ||
| p99 (not gated) | 0.66 ms | 0.56 ms | -15.7% | ||
| warm hybrid p50 | 0.33 ms | 0.34 ms | +5.6% | +25% | |
| p90 (not gated) | 0.37 ms | 0.50 ms | +35.1% | ||
| p99 (not gated) | 0.43 ms | 0.57 ms | +33.4% | ||
| cold kNN p50 | 1.99 ms | 2.23 ms | +12.0% | +40% | |
| p90 (not gated) | 2.52 ms | 2.48 ms | -1.5% | ||
| p99 (not gated) | 3.11 ms | 2.75 ms | -11.6% | ||
| open all segments p50 | 1.09 ms | 1.10 ms | +0.5% | +40% | |
| p90 (not gated) | 1.17 ms | 1.31 ms | +12.8% | ||
| p99 (not gated) | 1.28 ms | 1.38 ms | +7.2% | ||
| 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
⏱ Microbench — main vs this PR (
|
| metric | pctl | before (main) | after (PR) | Δ |
|---|---|---|---|---|
| cold broad ("the") | p50 | 2.76 ms | 2.69 ms | -2.5% |
| p90 | 3.73 ms | 2.96 ms | -20.5% 🟢 | |
| p99 | 3.99 ms | 3.14 ms | -21.2% 🟢 | |
| warm broad ("the") | p50 | 0.092 ms | 0.087 ms | -4.6% |
| p90 | 0.140 ms | 0.093 ms | -33.8% 🟢 | |
| p99 | 0.275 ms | 0.113 ms | -58.8% 🟢 | |
| warm 2-term AND | p50 | 0.103 ms | 0.103 ms | -0.4% |
| p90 | 0.109 ms | 0.106 ms | -3.0% | |
| p99 | 0.141 ms | 0.135 ms | -4.8% | |
| warm 3-term AND broad | p50 | 0.115 ms | 0.116 ms | +0.4% |
| p90 | 0.146 ms | 0.151 ms | +3.1% | |
| p99 | 0.156 ms | 0.160 ms | +2.1% | |
| warm phrase | p50 | 0.079 ms | 0.078 ms | -0.7% |
| p90 | 0.084 ms | 0.081 ms | -3.5% | |
| p99 | 0.095 ms | 0.108 ms | +12.6% |
|
| warm wildcard w1* | p50 | 42.4 ms | 42.1 ms | -0.5% |
| p90 | 43.4 ms | 43.0 ms | -0.9% | |
| p99 | 45.2 ms | 44.3 ms | -2.1% | |
| 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
Co-Authored-By: Ravi Decover AI <[email protected]>
…only its own Co-Authored-By: Ravi Decover AI <[email protected]>
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-27T02:04:36Z latency (v2 = current lazy format, median of inner samples): cold broad ("the") 2.8 ms warm broad ("the") 0.11 ms warm 2-term AND 0.12 ms warm phrase 0.08 ms warm wildcard w1* 43.17 ms ---end kosha-bench---
fd252af to
d7e3e52
Compare
|
Found 1 test failure on Blacksmith runners: Failure
|
Co-Authored-By: Ravi Decover AI <[email protected]>
Co-Authored-By: Ravi Decover AI <[email protected]>
Co-Authored-By: Ravi Decover AI <[email protected]>
…-source 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-27T02:10:06Z latency (v2 = current lazy format, median of inner samples): cold broad ("the") 2.8 ms warm broad ("the") 0.10 ms warm 2-term AND 0.12 ms warm phrase 0.09 ms warm wildcard w1* 42.07 ms ---end kosha-bench---
0c0cb41 to
628dcbb
Compare
![Fix with [code]smith](https://pr-comments-assets.blacksmith.sh/codesmith/fix-with-codesmith-light-v2-3x.png)
What and why
Part of #587 (Phase L, #589). Until now Kosha has only indexed JSON documents. This PR adds
kosha-ingest(clients/python/kosha_client/ingest.py, under the newingestextra), which turns a folder of.pdf,.docx,.html/.htm,.txtand.mdfiles into Kosha documents.Build vs. integrate: extraction runs client-side and integrates OSS extractors, pypdf and python-docx, both pure Python. HTML uses the stdlib
html.parser. It needs no new server dependency or worker, and a hosted parser or pdfium could replaceextract()later.Pages:
\f). That is the page separatorread(page=n)cuts on in feat(api): addreadfor line, page and byte ranges inside a document (#586) #600, soreadreturns the right PDF page.pageBreakBefore. Word's rendered layout pages are not available without rendering..txtfile (pdftotextoutput) are page breaks too.--per-pagewrites one document per page instead, with apageInteger field, so asearchhit carries its page number.Fields:
path--prefix+ the relative path (#585)bodytitlemime_typesize_bytesmodified_atcontent_sha256page_countscannedsourceIdempotent re-ingest:
f_+ sha256(path)[:32], so a changed file upserts over its old document.content_sha256for each batch of 64 paths and skips unchanged files.--forceoverrides this.--per-page, pages past a shortened file's new length are deleted.Scanned PDFs: pages with no text layer are flagged with
scanned: true, have an empty body and are listed in the report. OCR stays out of scope for v1.Failure handling: a file that fails to extract is reported under
failedand the rest of the folder still ingests. The exit code is 1 when any file fails. Hidden files are skipped.Docs are in
clients/python/README.md("Ingesting PDF, DOCX and HTML files").How it was tested
tests/test_ingest.pycovers:script/style, block structure and entities.--forcere-indexes, and per-page deletes run when a file shrinks.make client-python-test(now installs.[ingest]): 343 passed, 35 skipped.kosha-server, on a mixed folder (a 3-page PDF, a scanned PDF, a 3-page DOCX and an HTML file):indexed: 4, with the scanned PDF flagged. Second run:unchanged: 4.--per-page, searching formonthlyreturned/contracts/2024/msa.pdfpage 3 and/contracts/lease.docxpage 2. Both are correct.\f-separated pages, andprefixonpathandtermonscannedwork.Compatibility
/v1wire contract (proto/kosha/v1/kosha.proto, request/response JSON)This change is client-only.
ingestis an optional extra, so a plainpip install kosha-clientstill has no dependencies. #601 edits the samepip installlines inci.ymlandMakefile, so whichever PR merges second needs.[mcp,ingest]on those lines.Checklist
cargo fmt --all -- --check(no Rust changes)cargo clippy --all-targets --all-features -- -D warnings(no Rust changes)cargo test --all-features(no Rust changes)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.md(none)Link 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