Skip to content

feat: KB/DB versioning and CocoIndex-based incremental workspace ingest - #28

Open
jjk9090 wants to merge 4 commits into
OpenDCAI:mainfrom
jjk9090:feat/incremental-update-versioning
Open

jjk9090 wants to merge 4 commits into
OpenDCAI:mainfrom
jjk9090:feat/incremental-update-versioning

Conversation

@jjk9090

@jjk9090 jjk9090 commented Oct 3, 2026

Copy link
Copy Markdown

Summary

This PR introduces version control and incremental update capabilities for the DataMind Knowledge Base (KB) and Database (DB), alongside related toolchain fixes and improvements.

  • KB: Implements version snapshots and history tracking using LanceDB.
  • DB: Implements database-level version control and rollback using Dolt.
  • Ingest: Introduces an optional CocoIndex-backed indexer with LanceDB to enable efficient incremental updates for the entire workspace.
  • Toolchain: Enhances the KB/DB query, CRUD, and rollback tools to support versioning, and fixes related ToolSpec descriptions and underlying logic bugs.

Key Changes

1. KB Version Control (LanceDB)

  • Added add_version to LanceDBVectorStore. It compares snapshots via _snapshot_files to automatically track Add, Update, Delete, and chunks_added / chunks_deleted.
  • Added rollback and list_versions to restore the KB to a historical version and sync version_list.
  • Introduced _record_file_version in IngestService to automatically trigger version commits after operations like kb_add_text, kb_add_file, and kb_delete_file.

2. DB Version Control (Dolt)

  • Enhanced the Dolt version control interface in DoltDialect:
    • commit_version: Automatically records a commit for write operations.
    • list_versions / list_tables_at_version / describe_at_version: Queries table schemas and metadata at historical versions.
    • query_sql_at_version / execute_readonly_at_version: Executes read-only queries at a specific historical version (automatically injects AS OF '<version>').
    • rollback: Implements data rollback via DOLT_REVERT while preserving full commit history.
  • Added corresponding DB tool specs (db_list_versions, db_list_tables_at_version, db_query_sql_at_version, db_query_nl_at_version, db_rollback, etc.).

3. Ingest Incremental Update (CocoIndex + LanceDB)

  • Added a CocoIndex-backed KB indexer (providers/cocoindex.py).
  • Leverages CocoIndex's memo=True and localfs.walk_dir to reprocess only files whose content or embedder identity has changed. State is persisted under storage_dir/<name>_state, significantly reducing redundant computation.
  • kb_update_workspace fully integrates CocoIndex and syncs parsed chunk caches (.jsonl) for non-text files via _sync_prechunked_files.

4. Toolchain Fixes & Bug Fixes

  • Fixed ToolSpec descriptions: Aligned descriptions for db_import_csv / db_update_* / db_delete_path. Clarified that replace clears rows and preserves the table schema (instead of drop & recreate), and that db_delete_path removes both the on-disk file and its records across all tables.
  • Tool CRUD expansion: Added db_delete_path to execute file deletion and DB record cleanup in a single transaction (supporting Dolt commit).

Testing

Added and updated the following test files to cover KB/DB versioning and ingest logic. All local tests pass:

  • datamind/tests/test_kb_versioning.py
  • datamind/tests/test_db_versioning.py
  • datamind/tests/test_kb_ingest.py
  • datamind/tests/test_db_ingest.py

Test command:

pytest datamind/tests/

jjk9090 added 4 commits October 2, 2026 15:05
…ch/rollback in KBService (list_versions, search_at_version, rollback)
…rsion (list_versions, *_at_version, rollback)
…ular (Dolt) files

Every file operation (add / update / delete) produces a new version on
both sides — a new LanceDB commit on the KB side and a new Dolt commit
on the DB side. Which pieces participate depends on the ingest mode:

Text files — two ingest modes:

  * `direct` + lancedb: per-file, low-latency. `kb_add_file()` chunks
    and writes straight into the vector store; re-adding the same path
    replaces its chunks (upsert). **No** workspace-level scan and
    **no** version history — the direct path bypasses the KB's
    version-tracking layer.

  * `cocoindex` + lancedb: workspace-level, versioned.
    - `kb_add_file()` copies the file into `uploads/` (unless already
      there), then triggers `app.update()`.
    - `kb_update_workspace()` runs a full scan; only changed / added /
      removed files are (re)indexed.
    - `kb_delete_file()` requires the file to be gone from disk, then
      syncs so its chunks disappear.
    - **Every** above operation commits a new LanceDB version, so
      `list_versions` / `search_at_version` / `rollback` all work.

Tabular files — Dolt (always versioned):

  * `db_import_path()` / `db_update_path()` / `db_delete_path()` use
    the `_source_file` column to scope mutations to the originating
    file. Re-importing a file replaces only its own rows; deleting the
    file drops only those rows.

  * Every mutation is committed as a new Dolt version, so per-file
    history (`list_versions`, `*_at_version`, `rollback`) is available
    for any file operation.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant