Repository navigation
feat: hierarchical documents with depth-10 tree engine + doc_search (#438 #440) - #439
Merged
Merged
Conversation
- Add parent_id, path (materialized UUID), depth, sort_order, has_children columns to documents table - Schema migration v11→v12 with column_exists guards for idempotency - Add column_exists_in() helper for table-scoped column checks - Add Error::validation() convenience constructor - Store methods: list_root_documents, list_document_children, list_descendants, get_breadcrumbs, move_document, count_descendants, cascade_delete_safe - lib.rs API: doc_upsert_with_parent (max depth 10), doc_list_roots, doc_list_children, doc_list_descendants, doc_breadcrumbs, doc_move - doc_delete now returns (bool, usize) for cascade reporting - CLI: create --parent, list --tree, children, move, breadcrumbs, descendants subcommands - Tree display with indent-based hierarchy in CLI output
stmt was being dropped inside if/else branches while MappedRows iterator still held a reference. Collect results inside each branch.
🔍 Cora AI Code Review❌ Blocked — critical issues found. 🔴 Error (9)
Review powered by cora-cli · BYOK · MIT |
| let grandchild = make_child_doc("gc", "grandchild", "GC", "child", "/root/child/"); | ||
| store.upsert_document(&grandchild).unwrap(); | ||
|
|
||
| // Delete root → cascades to child + grandchild. |
- list_descendants, count_descendants, move_document: path already ends
with '/', so format!('/{}/') created '//' which broke LIKE queries
- Updated 3 migration test assertions from schema v11 to v12
(edges.rs, timeline.rs, crud.rs)
SQL LIKE without % is exact match — children paths like /root/eng/ never matched LIKE '/root/'. Added % suffix to all path prefix queries in list_descendants, count_descendants, move_document. Also exclude self via 'AND id != ?' since % matches empty string.
REPLACE(path, '/root/%', ...) treated '%' as literal — fixed by using old_path_exact for REPLACE target and old_prefix (with %) for WHERE.
…xing - FTS5 virtual table for documents (title/slug keyword search) - Sync triggers keep FTS5 in sync with documents table - doc_search() supports 3 modes: semantic, fts, hybrid (RRF fusion) - Chunk embeddings now indexed in usearch with 'chunk:' prefix - Old chunks cleaned from usearch on document update/delete - CLI: uteke doc search <query> --mode <semantic|fts|hybrid> - delete_chunks_for_documents() for batch chunk cleanup - get_chunks_by_ids() for search result enrichment - DocumentSearchResult struct with score, chunk heading/snippet
- Prefix unused variables with underscore (_pid, _ns, _chunk_key, _chunk_id) - Replace &[doc_id.clone()] with std::slice::from_ref(&doc_id) - Reformat long lines per rustfmt (sort_by, map closures, method chains)
- Remove unnecessary & on format! in Error::validation (line 943) - Collapse DocCommands::Search match pattern to single line per rustfmt
Bug fixes:
- move_document: use old_prefix (full path) for descendant LIKE instead of cur_id
- delete_document: fetch doc path for cascade delete instead of hardcoded /{id}/%
- doc_delete: accept namespace param instead of hardcoding DEFAULT_NAMESPACE
- move_document: recompute has_children on old parent after moving child
- get_chunks_by_ids_ordered: preserve input order for usearch score alignment
False positives documented:
- sec-sql-concat: table names are internal constants, never user input
- LIKE without %: format! explicitly adds % (lines 441, 545, 597)
- max_depth absolute: design choice, consistent with stored depth values
| // Update all descendants: replace old prefix with new prefix, adjust depth. | ||
| let n = tx | ||
| .execute( | ||
| "UPDATE documents SET path = REPLACE(path, ?1, ?2), depth = depth + ?3 \ |
| limit: usize, | ||
| ) -> Result<Vec<DocumentSummary>, Error> { | ||
| self.store.list_root_documents(namespace, limit) | ||
| } |
| ) -> Result<Vec<DocumentSummary>, Error> { | ||
| let ns = namespace.unwrap_or(DEFAULT_NAMESPACE); | ||
| self.store | ||
| .list_descendants(id_or_slug, ns, max_depth, limit) |
| id_or_slug: &str, | ||
| new_parent_slug: Option<&str>, | ||
| namespace: Option<&str>, | ||
| ) -> Result<usize, Error> { |
| parent_id, depth, has_children, sort_order \ | ||
| FROM documents WHERE path LIKE ?1 AND id != ?4 AND depth <= ?2 \ | ||
| ORDER BY path, sort_order LIMIT ?3", | ||
| ) |
| Ok(( | ||
| row.get::<_, String>(0)?, | ||
| row.get::<_, String>(1)?, | ||
| row.get::<_, i64>(2)?, |
| "UPDATE documents SET path = REPLACE(path, ?1, ?2), depth = depth + ?3 \ | ||
| WHERE path LIKE ?4 AND id != ?5", | ||
| params![old_path_exact, new_path, depth_diff, old_prefix, doc_id,], | ||
| ) |
This was referenced Jun 22, 2026
ajianaz
added a commit
that referenced
this pull request
Aug 13, 2026
…438 #440) (#439) * feat: hierarchical documents with depth-10 tree engine (#438) - Add parent_id, path (materialized UUID), depth, sort_order, has_children columns to documents table - Schema migration v11→v12 with column_exists guards for idempotency - Add column_exists_in() helper for table-scoped column checks - Add Error::validation() convenience constructor - Store methods: list_root_documents, list_document_children, list_descendants, get_breadcrumbs, move_document, count_descendants, cascade_delete_safe - lib.rs API: doc_upsert_with_parent (max depth 10), doc_list_roots, doc_list_children, doc_list_descendants, doc_breadcrumbs, doc_move - doc_delete now returns (bool, usize) for cascade reporting - CLI: create --parent, list --tree, children, move, breadcrumbs, descendants subcommands - Tree display with indent-based hierarchy in CLI output * fix: resolve borrow checker error in list_descendants stmt was being dropped inside if/else branches while MappedRows iterator still held a reference. Collect results inside each branch. * style: apply rustfmt formatting * fix: path prefix double-slash bug + bump version assertions to 12 - list_descendants, count_descendants, move_document: path already ends with '/', so format!('/{}/') created '//' which broke LIKE queries - Updated 3 migration test assertions from schema v11 to v12 (edges.rs, timeline.rs, crud.rs) * fix: LIKE queries need '%' wildcard for prefix scan SQL LIKE without % is exact match — children paths like /root/eng/ never matched LIKE '/root/'. Added % suffix to all path prefix queries in list_descendants, count_descendants, move_document. Also exclude self via 'AND id != ?' since % matches empty string. * fix: split old_prefix into exact + LIKE for REPLACE vs WHERE REPLACE(path, '/root/%', ...) treated '%' as literal — fixed by using old_path_exact for REPLACE target and old_prefix (with %) for WHERE. * feat: add doc_search with hybrid semantic+FTS5 and usearch chunk indexing - FTS5 virtual table for documents (title/slug keyword search) - Sync triggers keep FTS5 in sync with documents table - doc_search() supports 3 modes: semantic, fts, hybrid (RRF fusion) - Chunk embeddings now indexed in usearch with 'chunk:' prefix - Old chunks cleaned from usearch on document update/delete - CLI: uteke doc search <query> --mode <semantic|fts|hybrid> - delete_chunks_for_documents() for batch chunk cleanup - get_chunks_by_ids() for search result enrichment - DocumentSearchResult struct with score, chunk heading/snippet * style: fix clippy and rustfmt issues in doc_search implementation - Prefix unused variables with underscore (_pid, _ns, _chunk_key, _chunk_id) - Replace &[doc_id.clone()] with std::slice::from_ref(&doc_id) - Reformat long lines per rustfmt (sort_by, map closures, method chains) * fix: resolve clippy borrowed expression and rustfmt match pattern - Remove unnecessary & on format! in Error::validation (line 943) - Collapse DocCommands::Search match pattern to single line per rustfmt * fix: address CodeCora findings — path predicates, namespace, ordering Bug fixes: - move_document: use old_prefix (full path) for descendant LIKE instead of cur_id - delete_document: fetch doc path for cascade delete instead of hardcoded /{id}/% - doc_delete: accept namespace param instead of hardcoding DEFAULT_NAMESPACE - move_document: recompute has_children on old parent after moving child - get_chunks_by_ids_ordered: preserve input order for usearch score alignment False positives documented: - sec-sql-concat: table names are internal constants, never user input - LIKE without %: format! explicitly adds % (lines 441, 545, 597) - max_depth absolute: design choice, consistent with stored depth values * fix: use correct type comparison for old_parent in move_document * fix: use stable as_ref/as_deref for parent comparison * fix: remove redundant as_deref on Option<&str> * fix: remove unnecessary usize cast in move_document --------- Co-authored-by: ajianaz <[email protected]>
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.
Summary
Implements hierarchical documents engine (depth-10 tree) and hybrid document search for Uteke.
Closes: #438, #440
Features
Hierarchical Documents (schema v12)
parent_id,path(materialized),depth,sort_order,has_childrencolumnsMAX_DEPTH = 10enforced inmove_document()doc_search — 3 search modes:
semantic: usearch chunk embeddings withchunk:prefixfts: FTS5 keyword search on title/slughybrid(default): RRF fusion of semantic + FTS (k=60)Chunk lifecycle management
get_chunks_by_ids_ordered()preserves usearch score orderingCLI:
uteke doc search <query> --mode <semantic|fts|hybrid> --limit NSchema Changes (v11 → v12)
ALTER TABLE documents ADD COLUMN parent_id TEXTALTER TABLE documents ADD COLUMN path TEXT DEFAULT ''ALTER TABLE documents ADD COLUMN depth INTEGER DEFAULT 0ALTER TABLE documents ADD COLUMN sort_order INTEGER DEFAULT 0ALTER TABLE documents ADD COLUMN has_children INTEGER DEFAULT 0documents_fts(title, slug, content)with sync triggersBug Fixes (from CodeCora review)
old_prefix(full materialized path) instead ofcur_id(UUID only)/{uuid}/%namespaceparameter instead of hardcodingDEFAULT_NAMESPACEhas_childrenon old parent after moving last child awayCodeCora Status
CodeCora shows findings from earlier commits before bug fixes were applied. All actionable findings have been resolved:
Test plan