Skip to content

docs(cookbook): Add AST-aware code ingestion with incremental updates - #7485

Open
AreteDriver wants to merge 1 commit into
chroma-core:mainfrom
AreteDriver:docs/code-ingestion-cookbook
Open

docs(cookbook): Add AST-aware code ingestion with incremental updates#7485
AreteDriver wants to merge 1 commit into
chroma-core:mainfrom
AreteDriver:docs/code-ingestion-cookbook

Conversation

@AreteDriver

Copy link
Copy Markdown

Summary

Adds a new cookbook demonstrating production-grade code ingestion into Chroma with three techniques that are hard to get right:

  1. AST-aware chunking for Python — semantic boundaries (functions/classes/methods) instead of naive window splitting.
  2. Hash-based deduplication — deterministic IDs mean unchanged files are free to re-ingest.
  3. File-watching incremental updates — debounced auto-reindex with stale-entry cleanup.

Motivation

Naive code ingestion (sliding-window over raw text) splits in the middle of functions, produces duplicate embeddings across re-runs, and requires full-collection rebuilds on every change. This cookbook shows how to use Chroma's upsert + where capabilities to maintain a live, incrementally-updated code knowledge base.

Scope

  • examples/code_ingestion/ingest.py — standalone ingestion script
  • examples/code_ingestion/chunker.py — AST-based chunker with redaction
  • examples/code_ingestion/README.md — step-by-step guide

Verification

Tested on a 30K LOC Python monorepo. Ingestion time: ~45s first run, ~2s incremental re-index. Collection size stable across re-runs; only modified files trigger new embeddings.


Author's note: Extracted from production tooling at github.com/AreteDriver/animus (memboot → Animus pipeline). Happy to adjust idioms or API usage to match Chroma conventions.

Adds a new cookbook example demonstrating production-grade code ingestion
into Chroma with three techniques:

1. AST-aware chunking for Python (semantic boundaries: functions, classes,
   methods) instead of naive window splitting. Falls back to sliding window
   for unsupported file types.

2. Hash-based deduplication via deterministic chunk IDs — stable across
   re-runs, making upsert idempotent and incremental updates cheap.

3. File-watching incremental updates with debounced auto-reindex and stale-
   entry cleanup.

Also includes credential redaction (API keys, private keys, database URLs)
to prevent secrets from being embedded into the vector store.

@claude claude Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Claude Code Review

This pull request is from a fork — automated review is disabled. A repository maintainer can comment @claude review to run a one-time review.

@github-actions

Copy link
Copy Markdown

Reviewer Checklist

Please leverage this checklist to ensure your code review is thorough before approving

Testing, Bugs, Errors, Logs, Documentation

  • Can you think of any use case in which the code does not behave as intended? Have they been tested?
  • Can you think of any inputs or external events that could break the code? Is user input validated and safe? Have they been tested?
  • If appropriate, are there adequate property based tests?
  • If appropriate, are there adequate unit tests?
  • Should any logging, debugging, tracing information be added or removed?
  • Are error messages user-friendly?
  • Have all documentation changes needed been made?
  • Have all non-obvious changes been commented?

System Compatibility

  • Are there any potential impacts on other parts of the system or backward compatibility?
  • Does this change intersect with any items on our roadmap, and if so, is there a plan for fitting them together?

Quality

  • Is this code of a unexpectedly high quality (Readability, Modularity, Intuitiveness)

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