Repository navigation
feat(brain): parallel corpus write + sort-by-date - #63
Merged
Merged
Conversation
Replace the sequential per-leaf embed+upsert loop in WriteCorpus with a
cgo-free worker-pool core (corpus_pool.go):
- parallelEmbed: order-preserving worker pool over N goroutines; embed
errors collected per-result; ctx cancellation returns context.Canceled.
- chunkBounds: split leafs into [start,end) transaction batches.
- ProgressReporter: live rate + ETA to stderr (control/monitoring).
- WriteCorpus now takes WriteOptions{Workers,Batch,Skip,Limit,Progress},
embeds in parallel then writes in batched AddLeafs transactions.
- --skip resume: existingLeafIDSet skips leafs already in the db.
TDD: corpus_pool_test.go covers order preservation, worker cap, ctx
cancel, error propagation, progress counts, chunk bounds.
index.go gains --workers --batch --progress --skip control flags.
- rank: add SortByDate / RankAndFilterSort and --sort date[:asc|:desc] - read.go: get() returns valid_from/valid_to; ValidFrom wired from CorpusLeaf.Date in the corpus loader - search/httpapi: surface valid dates in MCP + spec
This was referenced Aug 21, 2026
The previous skip filtered leafs after parallelEmbed, so a resume still re-embedded every leaf. Move the skip check to before embedding so a re-run only embeds leafs not already in the db. Extract filterExistingLeafs + LeafID into the cgo-free pool file so the resume path is unit-testable; add TestFilterExistingLeafs.
--rebuild deletes the db, making --skip useless for resuming a crashed index build. Let --skip run without --rebuild so it preserves the existing db, skips already-embedded leafs, and only builds missing indexes. Verified: rebuilt 242k leafs, resume completed EXIT=0, indexes built (db 1.49GB->4.24GB), semantic search + --sort date:desc work, daemons up.
eSlider
added a commit
that referenced
this pull request
Aug 24, 2026
feat(brain): parallel corpus write + sort-by-date
eSlider
added a commit
that referenced
this pull request
Sep 15, 2026
feat(brain): parallel corpus write + sort-by-date
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
Optimizes the 2dph brain corpus (re)index and adds control/monitoring, TDD-first.
Feat(brain): parallel corpus write
parallelEmbedorder-preserving worker pool,chunkBoundstransaction batching,ProgressReporter(live rate + ETA).WriteCorpustakesWriteOptions{Workers,Batch,Skip,Limit,Progress}; embeds inparallel then writes in batched
AddLeafstransactions.--skipresume viaexistingLeafIDSet(skips leafs already in the DB).index.gocontrol flags:--workers --batch --progress --skip.corpus_pool_test.go(order, worker cap, ctx cancel, error propagation,progress counts, chunk bounds).
Feat(brain): sort by date
rank:SortByDate/RankAndFilterSort,--sort date[:asc|:desc].read.go: returnvalid_from/valid_to; wired fromCorpusLeaf.Date.Rebuild result
Ran on 20-core box: 242,275 leafs at ~100/s with 12 workers (vs sequential),
live ETA; embedding completed before monitor abort (resume via
--skip).Test
go test ./internal/brain/(cgo-free pool tests) pass; tagged build via zig ok.