AI Engineer Portal
Your personal operating system for career transition.
Exercise
Build an incremental document indexer
Build an Incremental Document Indexer
Re-indexing your entire corpus every time a document changes is wasteful and creates operational risk. Incremental indexing tracks which documents have changed by hashing their content, then only re-embeds and re-indexes what is new or updated.
What you are building
Create an IncrementalIndexer that:
- Tracks document state in a persistent JSON file:
{doc_id: {"hash": str, "chunk_ids": list[str], "indexed_at": str}}. - Detects changes by comparing content hash to stored hash. A document is dirty if its hash changed or is absent from state.
- Handles upserts: for a changed document, delete old chunk vectors, re-chunk, embed, and add new chunks.
- Handles deletes: when a document is removed, delete its chunk vectors and remove from state.
- Reports indexing results via an
IndexSyncResultdataclass. - Is idempotent: calling
synctwice with the same input makes no API calls on the second run.
Why this matters
Without incremental indexing, every CI deploy triggers a full re-index that may take hours and cost thousands of API calls. With it, a corpus of 100K documents where 50 changed today only costs indexing those 50.
Constraints
- State file is JSON (human-readable for debugging).
- Chunker and embed+add functions are injected (testable in isolation).
- Timestamps in ISO 8601 format.
Rag Systems / medium / Step 5 of 6
General drill
Keep the solution explicit and reviewable.
Make the solution explicit, debuggable, and easy to explain.
Review where the boundary is, what gets validated, and what would be hard to debug later.
Practice
Generate a variation
Generate a new exercise variation to deepen understanding or practice a related concept.
Attempt history
Recent submissions
Before you submit, decide what a strong answer should make obvious to the reviewer.
No attempts yet.