-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Hemant/rebuild updated #172
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
Open
hemant-endee
wants to merge
11
commits into
master
Choose a base branch
from
hemant/rebuild_updated
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 8 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
85aded6
Rebuild index with new config (#136)
hemant-endee bb2f3d6
using jthread with stop token
hemant-endee cbaa744
Shared parallel addPoint utility function — static chunk partition(sa…
hemant-endee cb9f73d
comments resolved
hemant-endee fd2c034
rebuild also handles execute_rebuild_job
hemant-endee 3b32a2e
correction on cleantempfiles and error code
hemant-endee 13fe6ce
rebuild status enum and logs code change
hemant-endee 6f4083e
rebuild.cpp
hemant-endee 2202923
Using Rebuild as friend class on Indexmanager helps to pass CacheEntr…
hemant-endee c2adbac
fix(rebuild): using new_alg directly, stop_request before phase3, an…
hemant-endee af444b6
test cases
hemant-endee File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,124 @@ | ||
| # Index Rebuild | ||
|
|
||
| Rebuild allows you to reconstruct an HNSW index graph with new configuration parameters (M, ef_construction) without re-uploading vector data. All vectors are re-indexed from MDBX storage — only the graph structure is rebuilt. | ||
|
|
||
| ## API Endpoints | ||
|
|
||
| | Method | Endpoint | Description | | ||
| |--------|----------|-------------| | ||
| | POST | `/api/v1/index/{name}/rebuild` | Start async rebuild | | ||
| | GET | `/api/v1/index/{name}/rebuild/status` | Check rebuild progress | | ||
|
|
||
| --- | ||
|
|
||
| ## Start Rebuild | ||
|
|
||
| **POST** `/api/v1/index/{name}/rebuild` | ||
|
|
||
| All parameters are optional. Omitted parameters retain their current values. | ||
|
|
||
| ```json | ||
| { | ||
| "M": 32, | ||
| "ef_con": 256 | ||
| } | ||
| ``` | ||
|
|
||
| **Parameters:** | ||
|
|
||
| | Parameter | Type | Description | | ||
| |-----------|------|-------------| | ||
| | `M` | int | HNSW graph connectivity (4–512) | | ||
| | `ef_con` | int | Construction-time search quality (8–4096) | | ||
|
|
||
| **Response 202:** | ||
| ```json | ||
| { | ||
| "status": "rebuilding", | ||
| "previous_config": { "M": 16, "ef_con": 128 }, | ||
| "new_config": { "M": 32, "ef_con": 256 }, | ||
| "total_vectors": 50000 | ||
| } | ||
| ``` | ||
|
|
||
| **Errors:** | ||
|
|
||
| | Code | Condition | | ||
| |------|-----------| | ||
| | 400 | No changes specified, invalid parameters, or attempted to change `precision`/`space_type` | | ||
| | 404 | Index not found | | ||
| | 409 | Rebuild or backup already in progress for this user | | ||
|
|
||
| --- | ||
|
|
||
| ## Check Progress | ||
|
|
||
| **GET** `/api/v1/index/{name}/rebuild/status` | ||
|
|
||
| **Status values:** | ||
|
|
||
| | Status | Meaning | | ||
| |--------|---------| | ||
| | `idle` | No rebuild has run for this index (or querying a different index) | | ||
| | `in_progress` | Rebuild is currently running | | ||
| | `completed` | Rebuild finished successfully | | ||
| | `failed` | Rebuild failed (see `error` field) | | ||
|
|
||
| **In progress:** | ||
| ```json | ||
| { | ||
| "status": "in_progress", | ||
| "vectors_processed": 45000, | ||
| "total_vectors": 100000, | ||
| "percent_complete": 45.0, | ||
| "started_at": "2026-03-25T10:30:00Z" | ||
| } | ||
| ``` | ||
|
|
||
| **Completed:** | ||
| ```json | ||
| { | ||
| "status": "completed", | ||
| "vectors_processed": 100000, | ||
| "total_vectors": 100000, | ||
| "percent_complete": 100.0, | ||
| "started_at": "2026-03-25T10:30:00Z", | ||
| "completed_at": "2026-03-25T10:32:15Z" | ||
| } | ||
| ``` | ||
|
|
||
| **Failed:** | ||
| ```json | ||
| { | ||
| "status": "failed", | ||
| "vectors_processed": 45000, | ||
| "total_vectors": 100000, | ||
| "percent_complete": 45.0, | ||
| "started_at": "2026-03-25T10:30:00Z", | ||
| "completed_at": "2026-03-25T10:31:05Z", | ||
| "error": "Out of memory" | ||
| } | ||
| ``` | ||
|
|
||
| Status is per-index. The `completed`/`failed` state persists until the next rebuild is started for that user. | ||
|
|
||
| --- | ||
|
|
||
| ## Restrictions | ||
|
|
||
| The following parameters **cannot** be changed via rebuild (returns 400): | ||
| - `precision` (quantization level) | ||
| - `space_type` | ||
|
|
||
|
|
||
| --- | ||
|
|
||
| ## Behavior | ||
|
|
||
| - **All vectors are re-indexed** from MDBX storage into a new HNSW graph with the updated configuration. | ||
| - **Search continues** during rebuild — queries use the old index until the rebuild completes. | ||
| - **Write operations** (insert, delete, update) will block and timeout while the rebuild is running, same as during backup. | ||
| - **One rebuild at a time per user** — cannot start a rebuild on any index while another rebuild is in progress for the same user. Also cannot run concurrently with a backup. | ||
| - **Periodic checkpoints** — the in-progress graph is saved to a temp file at regular intervals. | ||
| - **On completion**, the new graph replaces `default.idx`. All temporary and intermediate files are cleaned up. | ||
| - **On server restart** during an incomplete rebuild, the old index loads normally. Temp files are cleaned up automatically. The rebuild must be restarted manually. | ||
Oops, something went wrong.
Oops, something went wrong.
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.
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.
Things that are missing in the doc. make it more comprehensive
Disk space: rebuild needs 2× the index size on disk (timestamped + canonical co-exist briefly).
Memory: 2× the graph in RAM during Phase 2 (old + new).
Expected duration: rough order of magnitude per million vectors helps capacity planning.
What "manually restart" means after a crash — operationally how does an operator know a rebuild was incomplete? (There's no persisted state.)
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.
Fixed. Added Capacity and Timing section covering disk space (2×), memory (2×), and expected duration.