Repository navigation
[Feat]: tighten KB Indexed badge + folder cascade delete + pmid attribution #47
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
9e39a9c
feb73bb
a73a179
9616f02
2e614f6
65a7b65
29fa16e
d70418b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -21,7 +21,18 @@ export const ocrPageSchema = z.object({ | |
| export async function pageToMarkdownNode( | ||
| state: KbAgentStateShape, | ||
| ): Promise<Partial<KbAgentStateShape>> { | ||
| if (state.mode === "chunksOnly") { | ||
| if (state.mode === "chunksOnly" || state.mode === "retryFailedChunks") { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👀 Quick clarification on the comment-vs-code matchup on line 24: if (state.mode === "chunksOnly" || state.mode === "retryFailedChunks") {
// ... `retryFailed` is intentionally NOT in this list — its whole point is
// to re-OCR the failed pages, so this node has to run.
But the OCR branch's per-page skip — if ((p.markdown ?? "").trim().length > 0 && !p.errorMessage) {
return p;
}— only skips successful pages. Pages in Lower priority: |
||
| // ponytail: `chunksOnly` reuses the cached pages[].markdown verbatim. | ||
| // `retryFailedChunks` keeps doc.status='success' so all pages have | ||
| // markdown; only failed chunks (per-chunk UPDATE pre-applied by the | ||
| // route) need re-extraction. `retryFailed` is intentionally NOT in | ||
| // this list — its whole point is to re-OCR the failed pages, so this | ||
| // node has to run. The per-page OCR skip below (markdown.trim() > 0 | ||
| // AND no errorMessage) preserves successful pages while re-running | ||
| // OCR on any page with empty markdown OR a prior errorMessage, | ||
| // regardless of `status` — so `retryFailed`'s mixed-status | ||
| // pagesByDocId (some success, some failed) lands in the right lane | ||
| // per page. | ||
| return { | ||
| pagesByDocId: state.pagesByDocId, | ||
| processedFiles: state.processedFiles, | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
✅ Good fix on the cartesian-inflation issue. The two independent subqueries +
coalesce(...,0)correctly giveentityCountandrelationshipCountas their true values, including when one side has zero rows. Confirmed viatests/api/kb/documents/[id].test.tscases 1–3.Two adjacent points worth flagging while this file is open, even if out of scope for the PR:
status === "success"guard onfindKbChunksContentByDocumentIdis the only status filter — if a doc is inparsing/failed,chunksreturns[], butentityCount/relationshipCountstill query. Forparsing/faileddocs that's fine (the badge shows "Pending"/"Not Indexed" anyway), but the badge condition incomponents/tool-ui/kb/status-badge.tsxusesentityCount === 0 && relationshipCount === 0 → hasGraph=falseto flip the badge to "Embedding". For a fresh doc with 0 chunks yet,entityCount/relationshipCountwill both be 0, but the badge will render based on the doc-status branch (pending/parsing) above this and show "Pending" — which is correct by accident, not by design. A status-conditional gating on the count query would make the intent explicit.The
Promise.all([...]).then((rows) => rows[0]?.n ?? 0)micro-promise pattern works butcount(*)always returns a row in PG, sorows[0]?.n ?? 0is paranoid — the?? 0is unreachable. Dropping it (or usingNumber(rows[0]!.n)) removes dead fallback code.